From 5e9570508feaf6a0873aeae9275beaf52322eb7b Mon Sep 17 00:00:00 2001 From: valium007 <49368101+valium007@users.noreply.github.com> Date: Wed, 25 Feb 2026 00:15:13 +0530 Subject: [PATCH] [CIR] Fix cir.call verifier error for implicitly declared variadic functions (#182626) Fixes #182175 --- clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h | 2 +- clang/test/CIR/CodeGen/call-no-decl.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 clang/test/CIR/CodeGen/call-no-decl.c diff --git a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h index 8adfd565ad4c..00b107296d9f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h +++ b/clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h @@ -124,7 +124,7 @@ public: llvm::ArrayRef argTypes) { id.AddBoolean(instanceMethod); id.AddBoolean(info.getNoReturn()); - id.AddBoolean(required.getOpaqueData()); + id.AddInteger(required.getOpaqueData()); resultType.Profile(id); for (const CanQualType &arg : argTypes) arg.Profile(id); diff --git a/clang/test/CIR/CodeGen/call-no-decl.c b/clang/test/CIR/CodeGen/call-no-decl.c new file mode 100644 index 000000000000..d22c03a88b7d --- /dev/null +++ b/clang/test/CIR/CodeGen/call-no-decl.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=gnu89 -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +// Regression test for https://github.com/llvm/llvm-project/issues/182175 +// A function called with no prior declaration must get a variadic CIR function +// type so that multiple call sites with different argument counts do not +// trigger a verifier error. + +char temp[] = "some str"; +int foo(const char *); + +int bar(void) { + int t = foo(temp); + printf("Hello %d!\n", t); + printf("Works!\n"); + return 0; +} + +// CHECK: cir.func private @printf(!cir.ptr, ...) -> !s32i +// CHECK: cir.call @printf({{.*}}, {{.*}}) : (!cir.ptr, !s32i) -> !s32i +// CHECK: cir.call @printf({{.*}}) : (!cir.ptr) -> !s32i