This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Replace -1U{LL} expressions with appropriate *_MAX macros in Support library.
ClosedPublic

Authored by pavelkopyl on Feb 13 2023, 12:40 PM.

Details

Summary

This makes a code a bit more clear and also gets rid of C4146 warning
on MSVC compiler:
'unary minus operator applied to unsigned type, result still unsigned'.

In case uint64_t variable is initialized or compared against -1U expression,
which corresponds to 32-bit constant, UINT_MAX macro is used to preserve
NFC semantics; -1ULL is replaced with UINT64_MAX.

Diff Detail

Event Timeline

pavelkopyl created this revision.Feb 13 2023, 12:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 13 2023, 12:40 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
pavelkopyl requested review of this revision.Feb 13 2023, 12:40 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 13 2023, 12:40 PM
dblaikie accepted this revision.Feb 13 2023, 1:25 PM

Mixed feelings - if the code is valid/does what the developer intended, and the MSVC warning is just giving false positives/being too chatty, then we should probably disable the MSVC warning.

Equally, this does seem more readable, at the cost of including another header - but I guess there aren't too many TUs that don't include climits somewhere along the way.

I'm OK with this, but also open to hearing other people's perspectives.

This revision is now accepted and ready to land.Feb 13 2023, 1:25 PM
craig.topper added inline comments.Feb 13 2023, 1:33 PM
llvm/include/llvm/Support/BlockFrequency.h
30

Why not UINT64_MAX?

Mixed feelings - if the code is valid/does what the developer intended, and the MSVC warning is just giving false positives/being too chatty, then we should probably disable the MSVC warning.

Equally, this does seem more readable, at the cost of including another header - but I guess there aren't too many TUs that don't include climits somewhere along the way.

I'm OK with this, but also open to hearing other people's perspectives.

Actually, this warning is already suppressed in mainline, but we have a bit customized build where it would more desirable to "fix" it.

pavelkopyl added inline comments.Feb 13 2023, 2:07 PM
llvm/include/llvm/Support/BlockFrequency.h
30

Sure, that's possible (and <climits> is not required in this case), but I just wanted to preserve ULL type of the constant. Yep, probably UINT64_MAX looks more natural taking into account the destination type.

Replace ULLONG_MAX with UINT64_MAX.

pavelkopyl edited the summary of this revision. (Show Details)Feb 13 2023, 3:08 PM