https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/236332
>From c5e681d691e6e730f0db48a1a1821651a6f3f938 Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy <[email protected]> Date: Wed, 28 Oct 2026 08:21:16 +0100 Subject: [PATCH 1/2] [CIR] Return undef for unimplemented target builtin results A null RValue from an NYI target builtin crashed later uses of the result Return undef instead, like the other NYI paths in emitBuiltinExpr --- clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 5 ++--- .../CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 clang/test/CIR/CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 21a86114420e1..8f23e0f39bcac 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -3383,10 +3383,9 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID, if (std::optional<mlir::Value> rst = emitTargetBuiltinExpr(builtinID, e, returnValue)) { mlir::Value v = rst.value(); - // CIR dialect operations may have no results, no values will be returned - // even if it executes successfully. + // A null value means either a void builtin or an already diagnosed NYI. if (!v) - return RValue::get(nullptr); + return getUndefRValue(e->getType()); switch (evalKind) { case cir::TEK_Scalar: diff --git a/clang/test/CIR/CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c b/clang/test/CIR/CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c new file mode 100644 index 0000000000000..c464e08746567 --- /dev/null +++ b/clang/test/CIR/CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +avx512f -target-feature +avx512vl -fclangir -emit-cir -verify %s -o - > %t.cir +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s + +typedef int v4si __attribute__((vector_size(16))); + +v4si test_nyi_target_builtin_undef_rvalue(v4si a, v4si b, v4si c, + unsigned char m) { + // expected-error@+1 {{unimplemented X86 builtin call: __builtin_ia32_pternlogd128_maskz}} + return __builtin_ia32_pternlogd128_maskz(a, b, c, 1, m); +} + +// CIR-LABEL: test_nyi_target_builtin_undef_rvalue +// CIR: cir.const #cir.undef : !cir.vector<4 x !s32i> +// CIR: cir.return >From 0326f478233373595ec35d5b3c11ce08b8359d79 Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy <[email protected]> Date: Fri, 13 Nov 2026 10:29:58 +0100 Subject: [PATCH 2/2] address comments --- clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 2 ++ .../CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c | 14 -------------- 2 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 clang/test/CIR/CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 8f23e0f39bcac..07e4f0ffefa22 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -3384,6 +3384,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID, emitTargetBuiltinExpr(builtinID, e, returnValue)) { mlir::Value v = rst.value(); // A null value means either a void builtin or an already diagnosed NYI. + // In the case of a void builtin, getUndefRValue returns + // `RValue::get(nullptr)`. if (!v) return getUndefRValue(e->getType()); diff --git a/clang/test/CIR/CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c b/clang/test/CIR/CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c deleted file mode 100644 index c464e08746567..0000000000000 --- a/clang/test/CIR/CodeGenBuiltins/X86/nyi-builtin-undef-rvalue.c +++ /dev/null @@ -1,14 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -target-feature +avx512f -target-feature +avx512vl -fclangir -emit-cir -verify %s -o - > %t.cir -// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s - -typedef int v4si __attribute__((vector_size(16))); - -v4si test_nyi_target_builtin_undef_rvalue(v4si a, v4si b, v4si c, - unsigned char m) { - // expected-error@+1 {{unimplemented X86 builtin call: __builtin_ia32_pternlogd128_maskz}} - return __builtin_ia32_pternlogd128_maskz(a, b, c, 1, m); -} - -// CIR-LABEL: test_nyi_target_builtin_undef_rvalue -// CIR: cir.const #cir.undef : !cir.vector<4 x !s32i> -// CIR: cir.return _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
