From: Chad Rosier Date: Thu, 21 Feb 2013 18:56:55 +0000 (+0000) Subject: [driver] Handle the processing of the QA_OVERRIDE_GCC3_OPTIONS and CCC_ADD_ARGS X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=79165b82ddc881c705275fe9eb5a745f717a1eda;p=clang [driver] Handle the processing of the QA_OVERRIDE_GCC3_OPTIONS and CCC_ADD_ARGS before the DiagnosticsEngine is instantiated. Otherwise, warning options are not handled correctly. rdar://13254743 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175779 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Driver/qa_override.c b/test/Driver/qa_override.c index 5f96976ee9..341736fe4f 100644 --- a/test/Driver/qa_override.c +++ b/test/Driver/qa_override.c @@ -1,6 +1,13 @@ // RUN: env QA_OVERRIDE_GCC3_OPTIONS="#+-Os +-Oz +-O +-O3 +-Oignore +a +b +c xb Xa Omagic ^-ccc-print-options " %clang x -O2 b -O3 2>&1 | FileCheck %s +// RUN: env QA_OVERRIDE_GCC3_OPTIONS="x-Werror +-mfoo" %clang -Werror %s -c 2>&1 | FileCheck %s -check-prefix=RM-WERROR + // CHECK-NOT: ### // CHECK: Option 0 - Name: "-ccc-print-options", Values: {} // CHECK-NEXT: Option 1 - Name: "", Values: {"x"} // CHECK-NEXT: Option 2 - Name: "-O", Values: {"ignore"} // CHECK-NEXT: Option 3 - Name: "-O", Values: {"magic"} + +// RM-WERROR: ### QA_OVERRIDE_GCC3_OPTIONS: x-Werror +-mfoo +// RM-WERROR-NEXT: ### Deleting argument -Werror +// RM-WERROR-NEXT: ### Adding argument -mfoo at end +// RM-WERROR-NEXT: clang: warning: argument unused during compilation: '-mfoo' diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp index ee2d5f5963..de627fb58b 100644 --- a/tools/driver/driver.cpp +++ b/tools/driver/driver.cpp @@ -373,6 +373,32 @@ int main(int argc_, const char **argv_) { } } + // Handle QA_OVERRIDE_GCC3_OPTIONS and CCC_ADD_ARGS, used for editing a + // command line behind the scenes. + if (const char *OverrideStr = ::getenv("QA_OVERRIDE_GCC3_OPTIONS")) { + // FIXME: Driver shouldn't take extra initial argument. + ApplyQAOverride(argv, OverrideStr, SavedStrings); + } else if (const char *Cur = ::getenv("CCC_ADD_ARGS")) { + // FIXME: Driver shouldn't take extra initial argument. + std::vector ExtraArgs; + + for (;;) { + const char *Next = strchr(Cur, ','); + + if (Next) { + ExtraArgs.push_back(SaveStringInSet(SavedStrings, + std::string(Cur, Next))); + Cur = Next + 1; + } else { + if (*Cur != '\0') + ExtraArgs.push_back(SaveStringInSet(SavedStrings, Cur)); + break; + } + } + + argv.insert(&argv[1], ExtraArgs.begin(), ExtraArgs.end()); + } + llvm::sys::Path Path = GetExecutablePath(argv[0], CanonicalPrefixes); IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions; @@ -438,32 +464,6 @@ int main(int argc_, const char **argv_) { if (TheDriver.CCLogDiagnostics) TheDriver.CCLogDiagnosticsFilename = ::getenv("CC_LOG_DIAGNOSTICS_FILE"); - // Handle QA_OVERRIDE_GCC3_OPTIONS and CCC_ADD_ARGS, used for editing a - // command line behind the scenes. - if (const char *OverrideStr = ::getenv("QA_OVERRIDE_GCC3_OPTIONS")) { - // FIXME: Driver shouldn't take extra initial argument. - ApplyQAOverride(argv, OverrideStr, SavedStrings); - } else if (const char *Cur = ::getenv("CCC_ADD_ARGS")) { - // FIXME: Driver shouldn't take extra initial argument. - std::vector ExtraArgs; - - for (;;) { - const char *Next = strchr(Cur, ','); - - if (Next) { - ExtraArgs.push_back(SaveStringInSet(SavedStrings, - std::string(Cur, Next))); - Cur = Next + 1; - } else { - if (*Cur != '\0') - ExtraArgs.push_back(SaveStringInSet(SavedStrings, Cur)); - break; - } - } - - argv.insert(&argv[1], ExtraArgs.begin(), ExtraArgs.end()); - } - OwningPtr C(TheDriver.BuildCompilation(argv)); int Res = 0; SmallVector, 4> FailingCommands;