diff options
| author | Timm Baeder <tbaeder@redhat.com> | 2025-03-22 18:03:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-22 18:03:50 +0100 |
| commit | db7475a770c360a42560aa01859d5dcbb808ade8 (patch) | |
| tree | 52928a7ecc6dd0bba1c65867c92ec6689ed6bff0 /clang/test/AST/ByteCode/literals.cpp | |
| parent | ccc18ca1479dee73b0fdafa75d9403c50c17ee28 (diff) | |
[clang][bytecode] Ignore overflow in unary operators if requested (#132557)
Add PreInc and PreDec ops for this purpose and ignore the overflow if
UnaryOperator::canOverflow() returns false.
Diffstat (limited to 'clang/test/AST/ByteCode/literals.cpp')
| -rw-r--r-- | clang/test/AST/ByteCode/literals.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/literals.cpp b/clang/test/AST/ByteCode/literals.cpp index 73fcb0f1f2dc..68d400bc31dd 100644 --- a/clang/test/AST/ByteCode/literals.cpp +++ b/clang/test/AST/ByteCode/literals.cpp @@ -598,6 +598,32 @@ namespace IncDec { static_assert(UnderFlow() == -1, ""); // both-error {{not an integral constant expression}} \ // both-note {{in call to 'UnderFlow()'}} + /// This UnaryOperator can't overflow, so we shouldn't diagnose any overflow. + constexpr int CanOverflow() { + char c = 127; + char p; + ++c; + c++; + p = ++c; + p = c++; + + c = -128; + --c; + c--; + p = --c; + p = ++c; + + return 0; + } + static_assert(CanOverflow() == 0, ""); + + constexpr char OverflownChar() { + char c = 127; + c++; + return c; + } + static_assert(OverflownChar() == -128, ""); + constexpr int getTwo() { int i = 1; return (i += 1); |
