Skip to content

Disable the -Welaborated-enum-base to build the Foundation on Linux #2625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
63 changes: 63 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,69 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
}
}

[&]() {
if (ContainsError)
return;

llvm::SmallVector<const char *, 16> WarningsToDisable = {
"-Wno-elaborated-enum-base",
};

llvm::SmallVector<const char *, 32> 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()))
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/myriad-toolchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Driver/workarounds.c
Original file line number Diff line number Diff line change
@@ -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"