ICG fails to compile on Mac when using clang/llvm 3.8.1. #271

Modified the makefile to define LIBCLANG_MAJOR, LIBCLANG_MINOR, and
LIBCLANG_PATCHLEVEL based on the llvm-config executable in the llvm
directory pointed to by the configuration.  These new variable names
are independent of the __clang_major__, etc. variables we were defining
only in Linux.  Using these names, we can reduce the clang version
checks to a single consistent set of version numbers.  We don't have
to deal with the different version numbers assigned by Apple.
This commit is contained in:
Alex Lin
2016-07-25 14:57:07 -05:00
parent df94af17df
commit f7d1ff6376
4 changed files with 16 additions and 39 deletions

View File

@ -64,12 +64,10 @@ Most of the main program is pieced together from examples on the web. We are doi
*/
int main( int argc , char * argv[] ) {
#if (__clang_major__ >= 6) || ((__clang_major__ == 3) && (__clang_minor__ >= 5))
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
clang::TargetOptions to;
#elif (__clang_major__ == 3) && (__clang_minor__ >= 3)
clang::TargetOptions * to = new clang::TargetOptions() ;
#else
clang::TargetOptions to;
clang::TargetOptions * to = new clang::TargetOptions() ;
#endif
clang::CompilerInstance ci;
@ -82,13 +80,6 @@ int main( int argc , char * argv[] ) {
return -1 ;
}
/*
if ( show_units ) {
list_units() ;
return 0 ;
}
*/
if ( input_file_names.empty() ) {
std::cerr << "No header file specified" << std::endl ;
return 1 ;
@ -98,9 +89,6 @@ int main( int argc , char * argv[] ) {
clang::DiagnosticOptions & diago = ci.getDiagnosticOpts() ;
diago.ShowColors = 1 ;
ci.getDiagnostics().setIgnoreAllWarnings(true) ;
#if ( GCC_MAJOR == 4 ) && ( GCC_MINOR <= 2 )
ci.getDiagnostics().setSuppressAllDiagnostics() ;
#endif
// Set all of the defaults to c++
clang::CompilerInvocation::setLangDefaults(ci.getLangOpts() , clang::IK_CXX) ;
@ -110,15 +98,13 @@ int main( int argc , char * argv[] ) {
ci.getLangOpts().CPlusPlus11 = true ;
// Set the default target architecture
#if (__clang_major__ >= 6) || (__clang_major__ == 3) && (__clang_minor__ >= 5)
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
to.Triple = llvm::sys::getDefaultTargetTriple();
#elif (__clang_major__ == 3) && (__clang_minor__ >= 3)
to->Triple = llvm::sys::getDefaultTargetTriple();
#else
to.Triple = llvm::sys::getDefaultTargetTriple();
to->Triple = llvm::sys::getDefaultTargetTriple();
#endif
#if (__clang_major__ >= 6) || (__clang_major__ == 3) && (__clang_minor__ >= 5)
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
std::shared_ptr<clang::TargetOptions> shared_to = std::make_shared<clang::TargetOptions>(to) ;
clang::TargetInfo *pti = clang::TargetInfo::CreateTargetInfo(ci.getDiagnostics(), shared_to);
#else
@ -129,7 +115,7 @@ int main( int argc , char * argv[] ) {
// Create all of the necessary managers.
ci.createFileManager();
ci.createSourceManager(ci.getFileManager());
#if (__clang_major__ >= 6) || (__clang_major__ == 3) && (__clang_minor__ >= 5)
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
ci.createPreprocessor(clang::TU_Complete);
#else
ci.createPreprocessor();
@ -146,7 +132,7 @@ int main( int argc , char * argv[] ) {
// Tell the preprocessor to use its default predefines
clang::PreprocessorOptions & ppo = ci.getPreprocessorOpts() ;
ppo.UsePredefines = true;
#if (__clang_major__ == 3) && (__clang_minor__ >= 8)
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 8))
pp.getBuiltinInfo().initializeBuiltins(pp.getIdentifierTable(), pp.getLangOpts());
#else
pp.getBuiltinInfo().InitializeBuiltins(pp.getIdentifierTable(), pp.getLangOpts());
@ -167,7 +153,7 @@ int main( int argc , char * argv[] ) {
// Tell the compiler to use our ICGASTconsumer
ICGASTConsumer *astConsumer = new ICGASTConsumer(ci, hsd, cs, pa);
#if (__clang_major__ >= 6) || ((__clang_major__ == 3) && (__clang_minor__ >= 6))
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 6))
std::unique_ptr<clang::ASTConsumer> unique_ast(astConsumer) ;
ci.setASTConsumer(std::move(unique_ast));
#else
@ -193,7 +179,7 @@ int main( int argc , char * argv[] ) {
}
// Open up the input file and parse it.
const clang::FileEntry *pFile = ci.getFileManager().getFile(input_file_full_path);
#if (__clang_major__ >= 6) || ((__clang_major__ == 3) && (__clang_minor__ >= 5))
#if (LIBCLANG_MAJOR > 3) || ((LIBCLANG_MAJOR == 3) && (LIBCLANG_MINOR >= 5))
ci.getSourceManager().setMainFileID(ci.getSourceManager().createFileID(pFile, clang::SourceLocation(), clang::SrcMgr::C_User));
#else
ci.getSourceManager().createMainFileID(pFile);