[clang] 607f19c - [clang][Interp] Fix float->int casts overflowing (#72658)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 11 08:25:07 PST 2023
Author: Timm Baeder
Date: 2023-12-11T17:25:03+01:00
New Revision: 607f19cb947a25fe7ed131d983a90961f3c2541a
URL: https://github.com/llvm/llvm-project/commit/607f19cb947a25fe7ed131d983a90961f3c2541a
DIFF: https://github.com/llvm/llvm-project/commit/607f19cb947a25fe7ed131d983a90961f3c2541a.diff
LOG: [clang][Interp] Fix float->int casts overflowing (#72658)
If S.noteUndefinedBehavior() returns true, we will continue evaluation
and need a value on the stack.
Added:
Modified:
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/floats.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 4f7778bdd2ff3..6cf122f2ba55e 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1619,7 +1619,11 @@ bool CastFloatingIntegral(InterpState &S, CodePtr OpPC) {
QualType Type = E->getType();
S.CCEDiag(E, diag::note_constexpr_overflow) << F.getAPFloat() << Type;
- return S.noteUndefinedBehavior();
+ if (S.noteUndefinedBehavior()) {
+ S.Stk.push<T>(T(Result));
+ return true;
+ }
+ return false;
}
S.Stk.push<T>(T(Result));
diff --git a/clang/test/AST/Interp/floats.cpp b/clang/test/AST/Interp/floats.cpp
index e17167f5bf6db..45c31c759e47f 100644
--- a/clang/test/AST/Interp/floats.cpp
+++ b/clang/test/AST/Interp/floats.cpp
@@ -39,6 +39,10 @@ constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constan
static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
// expected-error {{invalid argument type 'float' to unary expression}}
+
+typedef int tdb[(long long)4e20]; //expected-error {{variable length}} \
+ //ref-error {{variable length}}
+
/// Initialized by a double.
constexpr float df = 0.0;
/// The other way around.
More information about the cfe-commits
mailing list