Skip to content

Commit f2661be

Browse files
committed
[clang][cli] Prevent double denormalization
If both flags created through BoolOption are CC1Option and the keypath has a non-default or non-implied value, the denormalizer gets called twice. If the denormalizer has the ability to generate both flags, we can end up generating the same flag twice. Reviewed By: dexonsmith, Bigcheese Differential Revision: https://reviews.llvm.org/D93094
1 parent 95114f2 commit f2661be

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class BoolOptionFlag<FlagDefExpanded flag, FlagDefExpanded other,
338338
: Flag<["-"], flag.Spelling>, Flags<flag.OptionFlags>, HelpText<flag.Help>,
339339
MarshallingInfoBooleanFlag<keypath, default.Value, flag.ValueAsCode,
340340
flag.RecordName, other.ValueAsCode,
341-
other.RecordName, other.Spelling>,
341+
other.RecordName>,
342342
ImpliedByAnyOf<implied.ImpliedBy, implied.ValueAsCode> {}
343343

344344
// Generates TableGen records for two command line flags that control the same

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,11 @@ static auto makeBooleanOptionNormalizer(bool Value, bool OtherValue,
197197
};
198198
}
199199

200-
static auto makeBooleanOptionDenormalizer(bool Value,
201-
const char *OtherSpelling) {
202-
return [Value, OtherSpelling](
203-
SmallVectorImpl<const char *> &Args, const char *Spelling,
204-
CompilerInvocation::StringAllocator, unsigned, bool KeyPath) {
205-
Args.push_back(KeyPath == Value ? Spelling : OtherSpelling);
200+
static auto makeBooleanOptionDenormalizer(bool Value) {
201+
return [Value](SmallVectorImpl<const char *> &Args, const char *Spelling,
202+
CompilerInvocation::StringAllocator, unsigned, bool KeyPath) {
203+
if (KeyPath == Value)
204+
Args.push_back(Spelling);
206205
};
207206
}
208207

clang/unittests/Frontend/CompilerInvocationTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ TEST_F(CommandLineTest, BoolOptionCC1ViaLetPresentPos) {
269269

270270
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
271271

272-
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fdebug-pass-manager")));
272+
ASSERT_EQ(count(GeneratedArgs, StringRef("-fdebug-pass-manager")), 1);
273273
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-debug-pass-manager"))));
274274
}
275275

llvm/include/llvm/Option/OptParser.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ class MarshallingInfoBitfieldFlag<code keypath, code value>
176176

177177
// Marshalling info for booleans. Applied to the flag setting keypath to false.
178178
class MarshallingInfoBooleanFlag<code keypath, code defaultvalue, code value, code name,
179-
code other_value, code other_name, string other_spelling>
179+
code other_value, code other_name>
180180
: MarshallingInfoFlag<keypath, defaultvalue> {
181181
code Normalizer = "makeBooleanOptionNormalizer("#value#", "#other_value#", OPT_"#other_name#")";
182-
code Denormalizer = "makeBooleanOptionDenormalizer("#value#", \""#other_spelling#"\")";
182+
code Denormalizer = "makeBooleanOptionDenormalizer("#value#")";
183183
}
184184

185185
// Mixins for additional marshalling attributes.

0 commit comments

Comments
 (0)