diff --git a/interpreter/cling/lib/Interpreter/CIFactory.cpp b/interpreter/cling/lib/Interpreter/CIFactory.cpp index 179b34dfd6d15..f4c4ce8ef7693 100644 --- a/interpreter/cling/lib/Interpreter/CIFactory.cpp +++ b/interpreter/cling/lib/Interpreter/CIFactory.cpp @@ -49,7 +49,6 @@ #define NOGDI #define NOMINMAX #include - #include #include #define popen _popen #define pclose _pclose @@ -426,6 +425,13 @@ namespace { } } #else // _MSC_VER + // Skip LLVM_CXX execution if -nostdinc++ was provided. + for (const auto arg : args) { + if (!strcmp(arg, "-nostdinc++")) { + return; + } + } + static const char *CppInclQuery = "echo | LC_ALL=C " LLVM_CXX " -xc++ -E -v - 2>&1 >/dev/null " "| awk '/^#include needs ClingJIT IncrementalExecutor::~IncrementalExecutor() {} std::unique_ptr - IncrementalExecutor::CreateHostTargetMachine() const { + IncrementalExecutor::CreateHostTargetMachine(const int& argc, const char* const *argv) const { // TODO: make this configurable. Triple TheTriple(sys::getProcessTriple()); #ifdef _WIN32 @@ -91,6 +91,28 @@ std::unique_ptr CodeModel::Model CMModel = CodeModel::JITDefault; CodeGenOpt::Level OptLevel = CodeGenOpt::Less; + for (int i = 0; i < argc; ++i) { + const std::string arg(argv[i]); + if (arg.length() != 3 || arg.rfind("-O", 0) != 0) { + continue; + } + + switch (argv[i][2]) { + case '0': + OptLevel = CodeGenOpt::None; + break; + case '1': + OptLevel = CodeGenOpt::Less; + break; + case '2': + OptLevel = CodeGenOpt::Default; + break; + case '3': + OptLevel = CodeGenOpt::Aggressive; + break; + } + } + std::unique_ptr TM; TM.reset(TheTarget->createTargetMachine(TheTriple.getTriple(), MCPU, FeaturesStr, diff --git a/interpreter/cling/lib/Interpreter/IncrementalExecutor.h b/interpreter/cling/lib/Interpreter/IncrementalExecutor.h index d594b05e965c9..a9ca106f95ec6 100644 --- a/interpreter/cling/lib/Interpreter/IncrementalExecutor.h +++ b/interpreter/cling/lib/Interpreter/IncrementalExecutor.h @@ -127,7 +127,7 @@ namespace cling { clang::DiagnosticsEngine& m_Diags; #endif - std::unique_ptr CreateHostTargetMachine() const; + std::unique_ptr CreateHostTargetMachine(const int& argc, const char* const *argv) const; public: enum ExecutionResult { @@ -137,7 +137,7 @@ namespace cling { kNumExeResults }; - IncrementalExecutor(clang::DiagnosticsEngine& diags); + IncrementalExecutor(clang::DiagnosticsEngine& diags, const int& argc, const char* const *argv); ~IncrementalExecutor(); diff --git a/interpreter/cling/lib/Interpreter/Interpreter.cpp b/interpreter/cling/lib/Interpreter/Interpreter.cpp index c7a518fe4a12d..b16a153754091 100644 --- a/interpreter/cling/lib/Interpreter/Interpreter.cpp +++ b/interpreter/cling/lib/Interpreter/Interpreter.cpp @@ -193,7 +193,7 @@ namespace cling { /*isTemp*/true), this)); if (!isInSyntaxOnlyMode()) - m_Executor.reset(new IncrementalExecutor(SemaRef.Diags)); + m_Executor.reset(new IncrementalExecutor(SemaRef.Diags, argc, argv)); // Tell the diagnostic client that we are entering file parsing mode. DiagnosticConsumer& DClient = getCI()->getDiagnosticClient();