This is an archive of the discontinued LLVM Phabricator instance.

[llvm] Remove std::clamp equivalent in `Transforms/Utils/MisExpect.cpp`
ClosedPublic

Authored by jloser on Aug 14 2022, 8:15 PM.

Details

Summary

Use std::clamp directly from the standard library now that LLVM is built with
C++17 standards mode.

Diff Detail

Event Timeline

jloser created this revision.Aug 14 2022, 8:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2022, 8:15 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
jloser requested review of this revision.Aug 14 2022, 8:15 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 14 2022, 8:15 PM
jloser updated this revision to Diff 452659.Aug 15 2022, 7:14 AM

Fix deduction of std::clamp by casting Tolerance.

paulkirth accepted this revision.Aug 15 2022, 8:00 AM

LGTM.

If you’re up for it, cleaning up how we parse tolerance in clang and how we store it in the context would be nice.

If not, I’ll probably do it later today so no worries.

Thanks for the clean up!

llvm/lib/Transforms/Utils/MisExpect.cpp
171

I don’t know what I was thinking when I implemented the tolerance option. There’s no reason they need to be 64-bit.

Really, we should fix how we parse and store the tolerance values.

That would allow us to ditch all these casts here and also choose more reasonable types.

Especially since they can’t exceed 100 …

This revision is now accepted and ready to land.Aug 15 2022, 8:00 AM
paulkirth added inline comments.Aug 17 2022, 7:50 AM
llvm/lib/Transforms/Utils/MisExpect.cpp
75

Ugh. in D131935 I think I forgot to update the return type here, despite changing everything else to uint32_t.

When you rebase, could you update this?

jloser updated this revision to Diff 453295.Aug 17 2022, 8:40 AM

Rebase since D131869 landed. Remove use of static_cast for the tolerance.

jloser marked 2 inline comments as done.Aug 17 2022, 8:40 AM
jloser added inline comments.
llvm/lib/Transforms/Utils/MisExpect.cpp
75

Yeah, I noticed this. Not a biggie - just fixed and rebased.

Perfect! Thanks so much!

jloser updated this revision to Diff 453500.Aug 17 2022, 6:21 PM
jloser marked an inline comment as done.

Reintroduce cast for MisExpectTolerance to go from cl::opt<uint32_t> to uint32_t.

jloser updated this revision to Diff 453680.Aug 18 2022, 9:09 AM

Rebase to see if CI is happy