Skip to content

Commit 607f19c

Browse files
authored
[clang][Interp] Fix float->int casts overflowing (#72658)
If S.noteUndefinedBehavior() returns true, we will continue evaluation and need a value on the stack.
1 parent 33819f3 commit 607f19c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,11 @@ bool CastFloatingIntegral(InterpState &S, CodePtr OpPC) {
16191619
QualType Type = E->getType();
16201620

16211621
S.CCEDiag(E, diag::note_constexpr_overflow) << F.getAPFloat() << Type;
1622-
return S.noteUndefinedBehavior();
1622+
if (S.noteUndefinedBehavior()) {
1623+
S.Stk.push<T>(T(Result));
1624+
return true;
1625+
}
1626+
return false;
16231627
}
16241628

16251629
S.Stk.push<T>(T(Result));

clang/test/AST/Interp/floats.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ constexpr float m = 5.0f / 0.0f; // ref-error {{must be initialized by a constan
3939
static_assert(~2.0f == 3, ""); // ref-error {{invalid argument type 'float' to unary expression}} \
4040
// expected-error {{invalid argument type 'float' to unary expression}}
4141

42+
43+
typedef int tdb[(long long)4e20]; //expected-error {{variable length}} \
44+
//ref-error {{variable length}}
45+
4246
/// Initialized by a double.
4347
constexpr float df = 0.0;
4448
/// The other way around.

0 commit comments

Comments
 (0)