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 1/2] [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 2ea329869284e7..f8d48a839d7326 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 00000000000000..1ca94902c5cda0 --- /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; +} >From 21ac3d9277b594ce00c92267114ed4ff269c4741 Mon Sep 17 00:00:00 2001 From: Shengxin Pei <[email protected]> Date: Thu, 19 Nov 2026 10:48:06 +0800 Subject: [PATCH 2/2] move tests --- clang/test/CodeGen/builtin-constant-p-opt.c | 25 --------------------- clang/test/CodeGen/builtin-constant-p.c | 25 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 26 deletions(-) delete mode 100644 clang/test/CodeGen/builtin-constant-p-opt.c diff --git a/clang/test/CodeGen/builtin-constant-p-opt.c b/clang/test/CodeGen/builtin-constant-p-opt.c deleted file mode 100644 index 1ca94902c5cda0..00000000000000 --- a/clang/test/CodeGen/builtin-constant-p-opt.c +++ /dev/null @@ -1,25 +0,0 @@ -// 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; -} diff --git a/clang/test/CodeGen/builtin-constant-p.c b/clang/test/CodeGen/builtin-constant-p.c index 07288069a5e3ad..7687bafffb16e1 100644 --- a/clang/test/CodeGen/builtin-constant-p.c +++ b/clang/test/CodeGen/builtin-constant-p.c @@ -2,7 +2,7 @@ // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O0 | FileCheck %s // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O2 -fexperimental-new-constant-interpreter | FileCheck %s // RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -disable-llvm-optzns -o - %s -O0 -fexperimental-new-constant-interpreter | FileCheck %s - +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O2 | FileCheck %s --check-prefix=CHECK-O2 int a = 42; @@ -153,3 +153,26 @@ void test15(void) { int a, b; (void)__builtin_constant_p((a = b, test15_f())); } + +// GH204760 + +// CHECK-O2-LABEL: define dso_local noundef { double, double } @test_nonconstant( +// CHECK-O2-SAME: ) local_unnamed_addr #[[ATTR0:[0-9]+]] { +// CHECK-O2-NEXT: [[ENTRY:.*:]] +// CHECK-O2-NEXT: ret { double, double } zeroinitializer +// +__complex__ double test_nonconstant(void) { + __complex__ double b = __builtin_constant_p(b); + return b; +} + +// CHECK-O2-LABEL: define dso_local noundef { double, double } @test_constant( +// CHECK-O2-SAME: ) local_unnamed_addr #[[ATTR0]] { +// CHECK-O2-NEXT: [[ENTRY:.*:]] +// CHECK-O2-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
