Skip to content

Commit

Permalink
interface: pass correct 4th argument to CompilerInvocation::setLangDe…
Browse files Browse the repository at this point in the history
…faults

Since llvmorg-12-init-16745-gc495dfe0268b ([clang][cli] NFC: Decrease
the scope of ParseLangArgs parameters, Thu Jan 14 08:26:12 2021 +0100),
the fourth argument of CompilerInvocation::setLangDefaults is
a std::vector<std::string> rather than a clang::PreprocessorOptions.
Introduce a setLangDefaultsArg4 to pass in the right argument
depending on what is expected by the specific version of clang.

Signed-off-by: Sven Verdoolaege <[email protected]>
  • Loading branch information
Sven Verdoolaege committed Apr 10, 2021
1 parent 647edd6 commit aba9b46
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions interface/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extract_interface_SOURCES = \
cpp.cc \
cpp_conversion.h \
cpp_conversion.cc \
set_lang_defaults_arg4.h \
extract_interface.h \
extract_interface.cc
extract_interface_LDFLAGS = $(CLANG_LDFLAGS) $(CLANG_RFLAG)
Expand Down
5 changes: 4 additions & 1 deletion interface/extract_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,15 @@ static void create_main_file_id(SourceManager &SM, const FileEntry *file)

#ifdef SETLANGDEFAULTS_TAKES_5_ARGUMENTS

#include "set_lang_defaults_arg4.h"

static void set_lang_defaults(CompilerInstance *Clang)
{
PreprocessorOptions &PO = Clang->getPreprocessorOpts();
TargetOptions &TO = Clang->getTargetOpts();
llvm::Triple T(TO.Triple);
CompilerInvocation::setLangDefaults(Clang->getLangOpts(), IK_C, T, PO,
CompilerInvocation::setLangDefaults(Clang->getLangOpts(), IK_C, T,
setLangDefaultsArg4(PO),
LangStandard::lang_unspecified);
}

Expand Down
16 changes: 16 additions & 0 deletions interface/set_lang_defaults_arg4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <string>
#include <vector>

#include <clang/Lex/PreprocessorOptions.h>

/* Convert a clang::PreprocessorOptions to the fourth argument
* of CompilerInvocation::setLangDefaults, which may be either
* a clang::PreprocessorOptions itself or its Includes.
*/
struct setLangDefaultsArg4 {
setLangDefaultsArg4(clang::PreprocessorOptions &PO) : PO(PO) {}
operator clang::PreprocessorOptions &() { return PO; }
operator std::vector<std::string> &() { return PO.Includes; }

clang::PreprocessorOptions &PO;
};
7 changes: 5 additions & 2 deletions m4/ax_detect_clang.m4
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CC="$SAVE_CC"
AC_LANG_PUSH(C++)
SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CLANG_CXXFLAGS $CPPFLAGS"
CPPFLAGS="$CLANG_CXXFLAGS -I$srcdir $CPPFLAGS"
AC_CHECK_HEADER([clang/Basic/SourceLocation.h], [],
[AC_ERROR([clang header file not found])])
AC_EGREP_HEADER([getDefaultTargetTriple], [llvm/Support/Host.h], [],
Expand Down Expand Up @@ -194,14 +194,17 @@ AC_TRY_COMPILE([
#include <clang/Basic/TargetOptions.h>
#include <clang/Lex/PreprocessorOptions.h>
#include <clang/Frontend/CompilerInstance.h>
#include "set_lang_defaults_arg4.h"
], [
using namespace clang;
CompilerInstance *Clang;
TargetOptions TO;
llvm::Triple T(TO.Triple);
PreprocessorOptions PO;
CompilerInvocation::setLangDefaults(Clang->getLangOpts(), IK_C,
T, PO, LangStandard::lang_unspecified);
T, setLangDefaultsArg4(PO),
LangStandard::lang_unspecified);
], [AC_DEFINE([SETLANGDEFAULTS_TAKES_5_ARGUMENTS], [],
[Define if CompilerInvocation::setLangDefaults takes 5 arguments])])
AC_TRY_COMPILE([
Expand Down

0 comments on commit aba9b46

Please sign in to comment.