https://github.com/flovent updated 
https://github.com/llvm/llvm-project/pull/177815

>From 5e6827b75c6a99626519740fd0f2abf59cb7715e Mon Sep 17 00:00:00 2001
From: flovent <[email protected]>
Date: Sun, 25 Jan 2026 10:38:22 +0800
Subject: [PATCH 1/2] [clang][bytecode] Fix crash caused by overflow of Casting
 float number to integer

---
 clang/lib/AST/ByteCode/Interp.h    | 10 ++++++----
 clang/test/AST/ByteCode/floats.cpp | 13 +++++++++++++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index cc8844e0fe90c..d856cd7c0a2d9 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2628,8 +2628,9 @@ static inline bool CastFloatingIntegralAP(InterpState &S, 
CodePtr OpPC,
   auto Status = F.convertToInteger(Result);
 
   // Float-to-Integral overflow check.
-  if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite())
-    return handleOverflow(S, OpPC, F.getAPFloat());
+  if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite() &&
+      !handleOverflow(S, OpPC, F.getAPFloat()))
+    return false;
 
   FPOptions FPO = FPOptions::getFromOpaqueInt(FPOI);
 
@@ -2649,8 +2650,9 @@ static inline bool CastFloatingIntegralAPS(InterpState 
&S, CodePtr OpPC,
   auto Status = F.convertToInteger(Result);
 
   // Float-to-Integral overflow check.
-  if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite())
-    return handleOverflow(S, OpPC, F.getAPFloat());
+  if ((Status & APFloat::opStatus::opInvalidOp) && F.isFinite() &&
+      !handleOverflow(S, OpPC, F.getAPFloat()))
+    return false;
 
   FPOptions FPO = FPOptions::getFromOpaqueInt(FPOI);
 
diff --git a/clang/test/AST/ByteCode/floats.cpp 
b/clang/test/AST/ByteCode/floats.cpp
index 930921d0eee1f..29e806cb542f7 100644
--- a/clang/test/AST/ByteCode/floats.cpp
+++ b/clang/test/AST/ByteCode/floats.cpp
@@ -224,3 +224,16 @@ namespace nan {
                                                            // expected-error 
{{must be initialized by a constant expression}} \
                                                            // expected-note 
{{produces a NaN}}
 }
+
+namespace ConvertToIntOverflow {
+  // should not crash
+  enum { E = (__uint128_t)-1. }; // ref-error {{expression is not an integral 
constant expression}} \
+                                 // ref-note {{outside the range of 
representable values of type}} \
+                                 // expected-error {{expression is not an 
integral constant expression}} \
+                                 // expected-note {{outside the range of 
representable values of type}}
+
+  enum { F = (__int128)(3.0e38) }; // ref-error {{expression is not an 
integral constant expression}} \
+                                   // ref-note {{outside the range of 
representable values of type}} \
+                                   // expected-error {{expression is not an 
integral constant expression}} \
+                                   // expected-note {{outside the range of 
representable values of type}}
+}

>From b7dbd99381024c2adab6f336d313d77aab4e48b0 Mon Sep 17 00:00:00 2001
From: flovent <[email protected]>
Date: Sun, 25 Jan 2026 21:56:09 +0800
Subject: [PATCH 2/2] [NFC] test when __SIZEOF_INT128__ is defined

---
 clang/test/AST/ByteCode/floats.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/AST/ByteCode/floats.cpp 
b/clang/test/AST/ByteCode/floats.cpp
index 29e806cb542f7..7da4bf884e3e3 100644
--- a/clang/test/AST/ByteCode/floats.cpp
+++ b/clang/test/AST/ByteCode/floats.cpp
@@ -225,6 +225,7 @@ namespace nan {
                                                            // expected-note 
{{produces a NaN}}
 }
 
+#ifdef __SIZEOF_INT128__
 namespace ConvertToIntOverflow {
   // should not crash
   enum { E = (__uint128_t)-1. }; // ref-error {{expression is not an integral 
constant expression}} \
@@ -237,3 +238,4 @@ namespace ConvertToIntOverflow {
                                    // expected-error {{expression is not an 
integral constant expression}} \
                                    // expected-note {{outside the range of 
representable values of type}}
 }
+#endif

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to