diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 68fc062d4b09c..77d6302a24086 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1049,6 +1049,69 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { } } + [&]() { + if (ContainsError) + return; + + llvm::SmallVector WarningsToDisable = { + "-Wno-elaborated-enum-base", + }; + + llvm::SmallVector ExtraArgs = { + // Add other command-line arguments here. + }; + + // Append WarningsToDisable to ExtraArgs, although do not disable warnings + // the command-line has explicitly turned on. + // + // TODO: Consider handling warning groups specially. + if (!WarningsToDisable.empty()) { + // Map the warnings explicitly turned on by the command-line. + llvm::StringSet<> WarningsToKeep; + for (auto *Arg : Args) { + if (!Arg->getOption().matches(options::OPT_W_Joined)) + continue; + StringRef Value = Arg->getValue(); + if (Value.empty()) + continue; // Skip past "-W" + + // Handle "-Wflag", "-Werror=flag", and "-Wno-flag". Ignore + // "-Wno-error=flag" since it doesn't turn the warning on or off. + if (Value.consume_front("no-")) { + WarningsToKeep.erase(Value); + continue; + } + (void)Value.consume_front("error="); + WarningsToKeep.insert(Value); + } + + // Disable any warnings not explicitly turned on. + for (const char *Warning : WarningsToDisable) { + StringRef S(Warning); + bool Consumed = S.consume_front("-Wno-"); + (void)Consumed; + assert(Consumed && "Warning flag should be in '-Wno-' form"); + if (!WarningsToKeep.count(S)) + ExtraArgs.push_back(Warning); + } + } + + if (ExtraArgs.empty()) + return; // Nothing to do... + + // Process the extra arguments, adding them to the main Args list. + InputArgList ExtraOptions = + ParseArgStrings(ExtraArgs, /*IsClCompatMode=*/false, ContainsError); + if (ContainsError) + return; + for (auto *Opt : ExtraOptions) { + // Always claim these implicit arguments to avoid strange warnings + // in -v output. + Opt->claim(); + appendOneArg(Opt, nullptr); + } + }(); + // Check for working directory option before accessing any files if (Arg *WD = Args.getLastArg(options::OPT_working_directory)) if (VFS->setCurrentWorkingDirectory(WD->getValue())) diff --git a/clang/test/Driver/myriad-toolchain.c b/clang/test/Driver/myriad-toolchain.c index 215a02fd0dec1..c83f7e8cbc807 100644 --- a/clang/test/Driver/myriad-toolchain.c +++ b/clang/test/Driver/myriad-toolchain.c @@ -62,7 +62,7 @@ // RUN: %clang -target shave-myriad -c %s -o foo.o -### -MD -MF dep.d 2>&1 \ // RUN: | FileCheck %s -check-prefix=MDMF -// MDMF: "-S" "-fno-exceptions" "-DMYRIAD2" "-MD" "-MF" "dep.d" "-MT" "foo.o" +// MDMF: "-S" "-fno-exceptions" "-DMYRIAD2" "-MD" "-MF" "dep.d" "-Wno-elaborated-enum-base" "-MT" "foo.o" // RUN: %clang -target shave-myriad -std=gnu++11 -mcpu=anothercpu -S %s -o foo.o -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=STDEQ diff --git a/clang/test/Driver/workarounds.c b/clang/test/Driver/workarounds.c new file mode 100644 index 0000000000000..b2dfc3e9dd684 --- /dev/null +++ b/clang/test/Driver/workarounds.c @@ -0,0 +1,10 @@ +// Check that Driver workarounds are enabled. +// +// RUN: %clang %s -### 2>&1 | FileCheck %s +// RUN: %clang -target x86_64-apple-darwin %s -### 2>&1 | FileCheck %s +// RUN: %clang -target x86_64-linux-unknown %s -### 2>&1 | FileCheck %s +// RUN: %clang -target x86_64-apple-darwin %s -W -### 2>&1 | FileCheck %s +// CHECK: "-cc1" +// Note: Add CHECK-SAME checks after this note for each workaround. +// CHECK-SAME: "-Wno-elaborated-enum-base" +