Skip to content

Commit a942aa5

Browse files
authored
Merge pull request #2625 from apple/eng/elaborated-enum-base-2021
Disable the -Welaborated-enum-base to build the Foundation on Linux
2 parents c029864 + 1e8aec7 commit a942aa5

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,69 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
10491049
}
10501050
}
10511051

1052+
[&]() {
1053+
if (ContainsError)
1054+
return;
1055+
1056+
llvm::SmallVector<const char *, 16> WarningsToDisable = {
1057+
"-Wno-elaborated-enum-base",
1058+
};
1059+
1060+
llvm::SmallVector<const char *, 32> ExtraArgs = {
1061+
// Add other command-line arguments here.
1062+
};
1063+
1064+
// Append WarningsToDisable to ExtraArgs, although do not disable warnings
1065+
// the command-line has explicitly turned on.
1066+
//
1067+
// TODO: Consider handling warning groups specially.
1068+
if (!WarningsToDisable.empty()) {
1069+
// Map the warnings explicitly turned on by the command-line.
1070+
llvm::StringSet<> WarningsToKeep;
1071+
for (auto *Arg : Args) {
1072+
if (!Arg->getOption().matches(options::OPT_W_Joined))
1073+
continue;
1074+
StringRef Value = Arg->getValue();
1075+
if (Value.empty())
1076+
continue; // Skip past "-W"
1077+
1078+
// Handle "-Wflag", "-Werror=flag", and "-Wno-flag". Ignore
1079+
// "-Wno-error=flag" since it doesn't turn the warning on or off.
1080+
if (Value.consume_front("no-")) {
1081+
WarningsToKeep.erase(Value);
1082+
continue;
1083+
}
1084+
(void)Value.consume_front("error=");
1085+
WarningsToKeep.insert(Value);
1086+
}
1087+
1088+
// Disable any warnings not explicitly turned on.
1089+
for (const char *Warning : WarningsToDisable) {
1090+
StringRef S(Warning);
1091+
bool Consumed = S.consume_front("-Wno-");
1092+
(void)Consumed;
1093+
assert(Consumed && "Warning flag should be in '-Wno-' form");
1094+
if (!WarningsToKeep.count(S))
1095+
ExtraArgs.push_back(Warning);
1096+
}
1097+
}
1098+
1099+
if (ExtraArgs.empty())
1100+
return; // Nothing to do...
1101+
1102+
// Process the extra arguments, adding them to the main Args list.
1103+
InputArgList ExtraOptions =
1104+
ParseArgStrings(ExtraArgs, /*IsClCompatMode=*/false, ContainsError);
1105+
if (ContainsError)
1106+
return;
1107+
for (auto *Opt : ExtraOptions) {
1108+
// Always claim these implicit arguments to avoid strange warnings
1109+
// in -v output.
1110+
Opt->claim();
1111+
appendOneArg(Opt, nullptr);
1112+
}
1113+
}();
1114+
10521115
// Check for working directory option before accessing any files
10531116
if (Arg *WD = Args.getLastArg(options::OPT_working_directory))
10541117
if (VFS->setCurrentWorkingDirectory(WD->getValue()))

clang/test/Driver/myriad-toolchain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
// RUN: %clang -target shave-myriad -c %s -o foo.o -### -MD -MF dep.d 2>&1 \
6464
// RUN: | FileCheck %s -check-prefix=MDMF
65-
// MDMF: "-S" "-fno-exceptions" "-DMYRIAD2" "-MD" "-MF" "dep.d" "-MT" "foo.o"
65+
// MDMF: "-S" "-fno-exceptions" "-DMYRIAD2" "-MD" "-MF" "dep.d" "-Wno-elaborated-enum-base" "-MT" "foo.o"
6666

6767
// RUN: %clang -target shave-myriad -std=gnu++11 -mcpu=anothercpu -S %s -o foo.o -### 2>&1 \
6868
// RUN: | FileCheck %s -check-prefix=STDEQ

clang/test/Driver/workarounds.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Check that Driver workarounds are enabled.
2+
//
3+
// RUN: %clang %s -### 2>&1 | FileCheck %s
4+
// RUN: %clang -target x86_64-apple-darwin %s -### 2>&1 | FileCheck %s
5+
// RUN: %clang -target x86_64-linux-unknown %s -### 2>&1 | FileCheck %s
6+
// RUN: %clang -target x86_64-apple-darwin %s -W -### 2>&1 | FileCheck %s
7+
// CHECK: "-cc1"
8+
// Note: Add CHECK-SAME checks after this note for each workaround.
9+
// CHECK-SAME: "-Wno-elaborated-enum-base"
10+

0 commit comments

Comments
 (0)