https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/72658
If S.noteUndefinedBehavior() returns true, we will continue evaluation and need a value on the stack. >From 070102561f8af1916b860225c79f07009cf368b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Fri, 17 Nov 2023 14:59:14 +0100 Subject: [PATCH] [clang][Interp] Fix float->int casts overflowing If S.noteUndefinedBehavior() returns true, we will continue evaluation and need a value on the stack. --- clang/lib/AST/Interp/Interp.h | 6 +++++- clang/test/AST/Interp/floats.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 026a95d65488da9..ef09b957057cdcb 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 e17167f5bf6dbbf..45c31c759e47fc6 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. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits