This is an archive of the discontinued LLVM Phabricator instance.

[clang][cli] Prevent double denormalization
ClosedPublic

Authored by jansvoboda11 on Dec 11 2020, 1:41 AM.

Details

Summary

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.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Dec 11 2020, 1:41 AM
jansvoboda11 requested review of this revision.Dec 11 2020, 1:41 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 11 2020, 1:41 AM
jansvoboda11 edited the summary of this revision. (Show Details)Dec 11 2020, 1:43 AM
jansvoboda11 added inline comments.
clang/unittests/Frontend/CompilerInvocationTest.cpp
272

Is it wise to rely on pointer comparison here? The call to count returns 2 before changing the denormalizer and 1 after, but I'm not sure if it will work on all platforms.

dexonsmith added inline comments.Dec 11 2020, 2:11 PM
clang/unittests/Frontend/CompilerInvocationTest.cpp
272

Does this compile / avoid the pointer comparison?

ASSERT_EQ(count(GeneratedArgs, StringRef("-fdebug-pass-manager")), 1);
jansvoboda11 added inline comments.Dec 15 2020, 2:14 AM
clang/unittests/Frontend/CompilerInvocationTest.cpp
272

Yes, this forces the const char * from GeneratedArgs to be converted into StringRef, which does comparison via ::memcmp.

If we decide comparing StringRefs is a better solution, I'd be inclined to create a helper function or custom matcher that does the conversion to StringRef. That way, we don't have to worry about doing the right thing in test cases.

Bigcheese accepted this revision.Dec 15 2020, 8:52 AM

lgtm with the test fix.

clang/unittests/Frontend/CompilerInvocationTest.cpp
272

I believe that if you have shared libraries enabled this is guaranteed to be different. We should do a string comparison here, and I think a helper makes sense if we expect to do this more often.

This revision is now accepted and ready to land.Dec 15 2020, 8:52 AM
dexonsmith accepted this revision.Dec 15 2020, 2:37 PM

LGTM too, once the test is fixed.

clang/unittests/Frontend/CompilerInvocationTest.cpp
272

Agreed, should be string comparison. IMO passing StringRef("...") into count is clear / easy enough, but a custom matcher would be fine too.

This revision was landed with ongoing or failed builds.Dec 16 2020, 12:51 AM
This revision was automatically updated to reflect the committed changes.