[clang] 77d2283 - [clang][Interp] Diagnose shift overflows
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 13 22:51:02 PDT 2024
Author: Timm Bäder
Date: 2024-07-14T07:28:02+02:00
New Revision: 77d2283e5824fb5bf375df65559a88a68159594b
URL: https://github.com/llvm/llvm-project/commit/77d2283e5824fb5bf375df65559a88a68159594b
DIFF: https://github.com/llvm/llvm-project/commit/77d2283e5824fb5bf375df65559a88a68159594b.diff
LOG: [clang][Interp] Diagnose shift overflows
Added:
Modified:
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/shifts.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 60e1d78f7405..c7d8604c7dc2 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -147,7 +147,7 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
const APSInt Val = RHS.toAPSInt();
QualType Ty = E->getType();
S.CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
- return true; // We will do the shift anyway but fix up the shift amount.
+ return !(S.getEvalStatus().Diag && !S.getEvalStatus().Diag->empty() && S.getLangOpts().CPlusPlus11);
}
if (LHS.isSigned() && !S.getLangOpts().CPlusPlus20) {
diff --git a/clang/test/AST/Interp/shifts.cpp b/clang/test/AST/Interp/shifts.cpp
index c5abdb7dd8a1..360b87b7ee04 100644
--- a/clang/test/AST/Interp/shifts.cpp
+++ b/clang/test/AST/Interp/shifts.cpp
@@ -200,13 +200,14 @@ namespace LongInt {
};
enum shiftof {
- X = (1<<-29) // all-error {{expression is not an integral constant expression}} \
- // all-note {{negative shift count -29}}
-};
+ X = (1<<-29), // all-error {{expression is not an integral constant expression}} \
+ // all-note {{negative shift count -29}}
+
+ X2 = (-1<<29), // cxx17-error {{expression is not an integral constant expression}} \
+ // cxx17-note {{left shift of negative value -1}} \
+ // ref-cxx17-error {{expression is not an integral constant expression}} \
+ // ref-cxx17-note {{left shift of negative value -1}}
-enum shiftof2 {
- X2 = (-1<<29) // cxx17-error {{expression is not an integral constant expression}} \
- // cxx17-note {{left shift of negative value -1}} \
- // ref-cxx17-error {{expression is not an integral constant expression}} \
- // ref-cxx17-note {{left shift of negative value -1}}
+ X3 = (1<<32) // all-error {{expression is not an integral constant expression}} \
+ // all-note {{shift count 32 >= width of type 'int'}}
};
More information about the cfe-commits
mailing list