Skip to content

Commit 7104363

Browse files
marsupialsftnight
authored andcommitted
Allow CompilerOptions:: DefaultLanguage to be queried earlier in initialization.
1 parent b4e11b5 commit 7104363

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

include/cling/Interpreter/InvocationOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace cling {
4646
/// or './cling -x c') that this shouldn't be done. This will return false
4747
/// in those cases.
4848
///
49-
bool DefaultLanguage(const clang::LangOptions&) const;
49+
bool DefaultLanguage(const clang::LangOptions* = nullptr) const;
5050

5151
unsigned Language : 1;
5252
unsigned ResourceDir : 1;

lib/Interpreter/CIFactory.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ namespace {
405405
Opts.FastMath = 1;
406406
#endif
407407

408-
if (CompilerOpts.DefaultLanguage(Opts)) {
408+
if (CompilerOpts.DefaultLanguage(&Opts)) {
409409
#ifdef __STRICT_ANSI__
410410
Opts.GNUMode = 0;
411411
#else
@@ -429,7 +429,7 @@ namespace {
429429
Opts.MicrosoftExt = 0;
430430
}
431431

432-
if (CompilerOpts.DefaultLanguage(Opts)) {
432+
if (CompilerOpts.DefaultLanguage(&Opts)) {
433433
#if _GLIBCXX_USE_FLOAT128
434434
// We are compiling with libstdc++ with __float128 enabled.
435435
if (!Target.hasFloat128Type()) {
@@ -634,7 +634,7 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts,
634634
SetPreprocessorFromBinary(PPOpts);
635635

636636
// Sanity check that clang delivered the language standard requested
637-
if (CompilerOpts.DefaultLanguage(LangOpts)) {
637+
if (CompilerOpts.DefaultLanguage(&LangOpts)) {
638638
switch (CxxStdCompiledWith()) {
639639
case 17: assert(LangOpts.CPlusPlus1z && "Language version mismatch");
640640
case 14: assert(LangOpts.CPlusPlus14 && "Language version mismatch");
@@ -732,18 +732,17 @@ static void stringifyPreprocSetting(PreprocessorOptions& PPOpts,
732732
// We do C++ by default; append right after argv[0] if no "-x" given
733733
argvCompile.push_back("-x");
734734
argvCompile.push_back( "c++");
735-
736-
if (!COpts.StdVersion) {
737-
// By default, set the standard to what cling was compiled with.
738-
// clang::driver::Compilation will do various things while initializing
739-
// and by enforcing the std version now cling is telling clang what to
740-
// do, rather than after clang has dedcuded a default.
741-
switch (CxxStdCompiledWith()) {
742-
case 17: argvCompile.emplace_back("-std=c++1z"); break;
743-
case 14: argvCompile.emplace_back("-std=c++14"); break;
744-
case 11: argvCompile.emplace_back("-std=c++11"); break;
745-
default: llvm_unreachable("Unrecognized C++ version");
746-
}
735+
}
736+
if (COpts.DefaultLanguage()) {
737+
// By default, set the standard to what cling was compiled with.
738+
// clang::driver::Compilation will do various things while initializing
739+
// and by enforcing the std version now cling is telling clang what to
740+
// do, rather than after clang has dedcuded a default.
741+
switch (CxxStdCompiledWith()) {
742+
case 17: argvCompile.emplace_back("-std=c++1z"); break;
743+
case 14: argvCompile.emplace_back("-std=c++14"); break;
744+
case 11: argvCompile.emplace_back("-std=c++11"); break;
745+
default: llvm_unreachable("Unrecognized C++ version");
747746
}
748747
}
749748
// argv[0] already inserted, get the rest

lib/Interpreter/InvocationOptions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void CompilerOptions::Parse(int argc, const char* const argv[],
145145
}
146146
}
147147

148-
bool CompilerOptions::DefaultLanguage(const LangOptions& LangOpts) const {
148+
bool CompilerOptions::DefaultLanguage(const LangOptions* LangOpts) const {
149149
// When StdVersion is set (-std=c++11, -std=gnu++11, etc.) then definitely
150150
// don't setup the defaults, as they may interfere with what the user is doing
151151
if (StdVersion)
@@ -154,7 +154,7 @@ bool CompilerOptions::DefaultLanguage(const LangOptions& LangOpts) const {
154154
// Also don't set up the defaults when language is explicitly set; unless
155155
// the language was set to generate a PCH, in which case definitely do.
156156
if (Language)
157-
return LangOpts.CompilingPCH || HasOutput;
157+
return HasOutput || (LangOpts && LangOpts->CompilingPCH);
158158

159159
return true;
160160
}

0 commit comments

Comments
 (0)