This is an archive of the discontinued LLVM Phabricator instance.

[clang] NFC: Refactor custom class into a lambda in CompilerInvocation
ClosedPublic

Authored by jansvoboda11 on Dec 21 2020, 4:54 AM.

Details

Summary

Change makeFlagToValueNormalizer so that one specialization converts all integral/enum arguments into uint64_t and forwards them to the more generic version.

This makes it easy to replace the custom FlagToValueNormalizer struct with a lambda, which is the common approach in other (de)normalizers.

Finally, drop custom is_int_convertbile in favor of llvm::is_integral_or_enum.

Diff Detail

Event Timeline

jansvoboda11 requested review of this revision.Dec 21 2020, 4:54 AM
jansvoboda11 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 21 2020, 4:54 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
dexonsmith accepted this revision.Dec 21 2020, 1:07 PM

This looks like an improvement, so LGTM, but I have a couple of comments.

clang/lib/Frontend/CompilerInvocation.cpp
165–170

I missed the double negation here for a while; might be simpler as:

<std::is_same<T, uint64_t>::value ||
 !llvm::is_integral_or_neum<T>::value>
176–180

Ah, I guess you want this to match the above. I guess that's the benefit of the old is_int_convertible -- it didn't need double-negation to make it clear that the two functions were alternatives. I might prefer the previous option of having a stand-alone function (possibly renamed if you think the old name isn't correct anymore). (Regardless, you can drop the unnecessary parentheses.)

180

(not a behaviour change but) I wonder if this correct for signed types, where the conversion back to T could change sign if it's a negative value. Should there be an assertion that the value is >= 0? (Probably to do separately / outside this patch)

This revision is now accepted and ready to land.Dec 21 2020, 1:07 PM

Extract SFINAE check into function again

jansvoboda11 added inline comments.Dec 22 2020, 5:45 AM
clang/lib/Frontend/CompilerInvocation.cpp
180

It might be good to be defensive here. I'll put that into a follow-up.

This revision was landed with ongoing or failed builds.Dec 22 2020, 5:45 AM
This revision was automatically updated to reflect the committed changes.