https://github.com/TPPPP72 updated 
https://github.com/llvm/llvm-project/pull/234259

>From df5afb69add0d1b9e16eb15bcef7221d297eb97b Mon Sep 17 00:00:00 2001
From: Shengxin Pei <[email protected]>
Date: Fri, 13 Nov 2026 17:20:14 +0800
Subject: [PATCH] [Clang][CodeGen] Fix an assertion with complex argument to
 __builtin_constant_p

---
 clang/lib/CodeGen/CGBuiltin.cpp             |  5 +++--
 clang/test/CodeGen/builtin-constant-p-opt.c | 25 +++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/builtin-constant-p-opt.c

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2ea329869284e..f8d48a839d732 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4098,8 +4098,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
     QualType ArgType = Arg->getType();
     // FIXME: The allowance for Obj-C pointers and block pointers is historical
     // and likely a mistake.
-    if (!ArgType->isIntegralOrEnumerationType() && !ArgType->isFloatingType() 
&&
-        !ArgType->isObjCObjectPointerType() && !ArgType->isBlockPointerType())
+    if (!ArgType->isIntegralOrEnumerationType() &&
+        !ArgType->isRealFloatingType() && !ArgType->isObjCObjectPointerType() 
&&
+        !ArgType->isBlockPointerType())
       // Per the GCC documentation, only numeric constants are recognized after
       // inlining.
       return RValue::get(ConstantInt::get(ResultType, 0));
diff --git a/clang/test/CodeGen/builtin-constant-p-opt.c 
b/clang/test/CodeGen/builtin-constant-p-opt.c
new file mode 100644
index 0000000000000..1ca94902c5cda
--- /dev/null
+++ b/clang/test/CodeGen/builtin-constant-p-opt.c
@@ -0,0 +1,25 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -O2 -emit-llvm -o - %s | 
FileCheck %s
+
+// GH204760
+
+// CHECK-LABEL: define dso_local noundef { double, double } @test_nonconstant(
+// CHECK-SAME: ) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    ret { double, double } zeroinitializer
+//
+__complex__ double test_nonconstant(void) {
+  __complex__ double b = __builtin_constant_p(b);
+  return b;
+}
+
+// CHECK-LABEL: define dso_local noundef { double, double } @test_constant(
+// CHECK-SAME: ) local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:    ret { double, double } { double 1.000000e+00, double 
0.000000e+00 }
+//
+__complex__ double test_constant(void) {
+  int c = __builtin_constant_p(1.0 + 2.0i);
+  __complex__ double r = c;
+  return r;
+}

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

Reply via email to