Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don’t change the C++ version from underneath clang, tell it what is d…
…esired.
  • Loading branch information
marsupial authored and Axel-Naumann committed Jul 5, 2017
commit 7378fc8ca40346a33b0a0dc937ee024cc573f230
38 changes: 25 additions & 13 deletions interpreter/cling/lib/Interpreter/CIFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,18 +398,6 @@ namespace {
Opts.MathErrno = 0;
#endif

// C++11 is turned on if cling is built with C++11: it's an interpreter;
// cross-language compilation doesn't make sense.

if (Opts.CPlusPlus) {
switch (CxxStdCompiledWith()) {
case 17: Opts.CPlusPlus1z = 1; // intentional fall-through
case 14: Opts.CPlusPlus14 = 1; // intentional fall-through
case 11: Opts.CPlusPlus11 = 1; break;
default: break;
}
}

#ifdef _REENTRANT
Opts.POSIXThreads = 1;
#endif
Expand All @@ -418,7 +406,7 @@ namespace {
#endif

if (CompilerOpts.DefaultLanguage(Opts)) {
#ifdef __STRICT_ANSI__ || defined(LLVM_ON_WIN32)
#ifdef __STRICT_ANSI__
Opts.GNUMode = 0;
#else
Opts.GNUMode = 1;
Expand Down Expand Up @@ -644,6 +632,17 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts,
PreprocessorOptions& PPOpts = CI->getInvocation().getPreprocessorOpts();
SetPreprocessorFromBinary(PPOpts);

// Sanity check that clang delivered the language standard requested
const auto& LangOpts = CI->getLangOpts();
if (CompilerOpts.DefaultLanguage(LangOpts)) {
switch (CxxStdCompiledWith()) {
case 17: assert(LangOpts.CPlusPlus1z && "Language version mismatch");
case 14: assert(LangOpts.CPlusPlus14 && "Language version mismatch");
case 11: assert(LangOpts.CPlusPlus11 && "Language version mismatch");
default: break;
}
}

PPOpts.addMacroDef("__CLING__");
if (CI->getLangOpts().CPlusPlus11 == 1)
PPOpts.addMacroDef("__CLING__CXX11");
Expand Down Expand Up @@ -733,6 +732,19 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts,
// We do C++ by default; append right after argv[0] if no "-x" given
argvCompile.push_back("-x");
argvCompile.push_back( "c++");

if (!COpts.StdVersion) {
// By default, set the standard to what cling was compiled with.
// clang::driver::Compilation will do various things while initializing
// and by enforcing the std version now cling is telling clang what to
// do, rather than after clang has dedcuded a default.
switch (CxxStdCompiledWith()) {
case 17: argvCompile.emplace_back("-std=c++1z"); break;
case 14: argvCompile.emplace_back("-std=c++14"); break;
case 11: argvCompile.emplace_back("-std=c++11"); break;
default: llvm_unreachable("Unrecognized C++ version");
}
}
}
// argv[0] already inserted, get the rest
argvCompile.insert(argvCompile.end(), argv+1, argv + argc);
Expand Down