This is an archive of the discontinued LLVM Phabricator instance.

[clang][Interp] Add more shift error checking
ClosedPublic

Authored by tbaeder on May 9 2023, 10:39 AM.

Diff Detail

Event Timeline

tbaeder created this revision.May 9 2023, 10:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 10:39 AM
tbaeder requested review of this revision.May 9 2023, 10:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 10:39 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
shafik added inline comments.May 9 2023, 4:35 PM
clang/lib/AST/Interp/Interp.h
129

Maybe this quote for C++20 should be moved below the else block with a comment noting that C++20 forward the above is no longer UB? My first reading I thought the second quote applied to the else if below and was super confused.

132

Do we test this diagnostic?

tbaeder added inline comments.May 9 2023, 11:14 PM
clang/lib/AST/Interp/Interp.h
132

OH! No, and the 12 was just a debug value I forgot to replace with the real thing.

tbaeder updated this revision to Diff 520954.May 10 2023, 4:05 AM
tbaeder updated this revision to Diff 521078.May 10 2023, 1:08 PM
tbaeder marked an inline comment as done.
tbaeder updated this revision to Diff 521082.May 10 2023, 1:14 PM
shafik accepted this revision.May 10 2023, 1:35 PM

LGTM

clang/lib/AST/Interp/Interp.h
137–138

Just adding a reference to https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0907r4.html since that is the paper that changed this behavior

This revision is now accepted and ready to land.May 10 2023, 1:35 PM
tbaeder updated this revision to Diff 521237.May 11 2023, 2:41 AM
tbaeder marked an inline comment as done.
aaron.ballman added inline comments.May 11 2023, 11:00 AM
clang/test/AST/Interp/shifts.cpp
165–171

I'd like a test along the lines of:

constexpr int foo(int a) {
  return -a << 2;
}
static_assert(foo(10)); // Should fail
constexpr int a = -2;
static_assert(foo(a)); // Should be fine
static_assert(foo(-a)); // Should fail
tbaeder updated this revision to Diff 526965.May 31 2023, 2:22 AM
tbaeder marked an inline comment as done.
This revision was automatically updated to reflect the committed changes.