https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/172564
>From b0663d43af64466d1ae51ddebbb996c3053bdca6 Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Tue, 16 Dec 2025 23:04:53 +0100 Subject: [PATCH 1/2] [CIR] Support PredefinedExpr for ConstantLValue --- clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp | 3 +-- clang/test/CIR/CodeGen/predefined-expr.c | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp index a474defb7f627..ecb65d901de54 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp @@ -1458,8 +1458,7 @@ ConstantLValueEmitter::VisitObjCBoxedExpr(const ObjCBoxedExpr *e) { ConstantLValue ConstantLValueEmitter::VisitPredefinedExpr(const PredefinedExpr *e) { - cgm.errorNYI(e->getSourceRange(), "ConstantLValueEmitter: predefined expr"); - return {}; + return cgm.getAddrOfConstantStringFromLiteral(e->getFunctionName()); } ConstantLValue diff --git a/clang/test/CIR/CodeGen/predefined-expr.c b/clang/test/CIR/CodeGen/predefined-expr.c index 674c9bd02b5cf..229c990699f0f 100644 --- a/clang/test/CIR/CodeGen/predefined-expr.c +++ b/clang/test/CIR/CodeGen/predefined-expr.c @@ -5,6 +5,8 @@ // RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -o %t.ll // RUN: FileCheck %s --input-file=%t.ll --check-prefix=OGCG +// CIR: cir.global "private" constant cir_private dso_local @".str" = #cir.zero : !cir.array<!s8i x 1> +// CIR: cir.global external @func = #cir.global_view<@".str"> : !cir.ptr<!s8i> // CIR: cir.global "private" constant cir_private dso_local @__func__.plainFunction = #cir.const_array<"plainFunction\00" : !cir.array<!s8i x 14>> // CIR: cir.global "private" constant cir_private dso_local @__PRETTY_FUNCTION__.plainFunction = #cir.const_array<"void plainFunction(void)\00" : !cir.array<!s8i x 25>> // CIR: cir.global "private" constant cir_private dso_local @__func__.externFunction = #cir.const_array<"externFunction\00" : !cir.array<!s8i x 15>> @@ -15,6 +17,8 @@ // CIR: cir.global "private" constant cir_private dso_local @__PRETTY_FUNCTION__.staticFunction = #cir.const_array<"void staticFunction(void)\00" : !cir.array<!s8i x 26>> // TODO(cir): These should be unnamed_addr +// LLVM: @.str = private constant [1 x i8] zeroinitializer, align 1 +// LLVM: @func = global ptr @.str, align 8 // LLVM: @__func__.plainFunction = private constant [14 x i8] c"plainFunction\00" // LLVM: @__PRETTY_FUNCTION__.plainFunction = private constant [25 x i8] c"void plainFunction(void)\00" // LLVM: @__func__.externFunction = private constant [15 x i8] c"externFunction\00" @@ -24,6 +28,8 @@ // LLVM: @__func__.staticFunction = private constant [15 x i8] c"staticFunction\00" // LLVM: @__PRETTY_FUNCTION__.staticFunction = private constant [26 x i8] c"void staticFunction(void)\00" +// OGCG: @.str = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 +// OGCG: @func = global ptr @.str, align 8 // OGCG: @__func__.plainFunction = private unnamed_addr constant [14 x i8] c"plainFunction\00" // OGCG: @__PRETTY_FUNCTION__.plainFunction = private unnamed_addr constant [25 x i8] c"void plainFunction(void)\00" // OGCG: @__func__.externFunction = private unnamed_addr constant [15 x i8] c"externFunction\00" @@ -33,6 +39,8 @@ // OGCG: @__func__.staticFunction = private unnamed_addr constant [15 x i8] c"staticFunction\00" // OGCG: @__PRETTY_FUNCTION__.staticFunction = private unnamed_addr constant [26 x i8] c"void staticFunction(void)\00" +const char* func = __func__; + int printf(const char *, ...); void plainFunction(void) { >From e57e533287dcad00b592bf130a23c59239d272b6 Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Wed, 17 Dec 2025 13:00:31 +0100 Subject: [PATCH 2/2] Add one more test case --- clang/test/CIR/CodeGen/predefined-expr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/test/CIR/CodeGen/predefined-expr.c b/clang/test/CIR/CodeGen/predefined-expr.c index 229c990699f0f..73b842fd49bf9 100644 --- a/clang/test/CIR/CodeGen/predefined-expr.c +++ b/clang/test/CIR/CodeGen/predefined-expr.c @@ -5,6 +5,7 @@ // RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -o %t.ll // RUN: FileCheck %s --input-file=%t.ll --check-prefix=OGCG +// CIR: cir.global "private" internal dso_local @staticFuncName.name = #cir.global_view<@".str.4"> : !cir.ptr<!s8i> {alignment = 8 : i64} loc(#loc1) // CIR: cir.global "private" constant cir_private dso_local @".str" = #cir.zero : !cir.array<!s8i x 1> // CIR: cir.global external @func = #cir.global_view<@".str"> : !cir.ptr<!s8i> // CIR: cir.global "private" constant cir_private dso_local @__func__.plainFunction = #cir.const_array<"plainFunction\00" : !cir.array<!s8i x 14>> @@ -13,10 +14,12 @@ // CIR: cir.global "private" constant cir_private dso_local @__PRETTY_FUNCTION__.externFunction = #cir.const_array<"void externFunction(void)\00" : !cir.array<!s8i x 26>> // CIR: cir.global "private" constant cir_private dso_local @__func__.privateExternFunction = #cir.const_array<"privateExternFunction\00" : !cir.array<!s8i x 22>> // CIR: cir.global "private" constant cir_private dso_local @__PRETTY_FUNCTION__.privateExternFunction = #cir.const_array<"void privateExternFunction(void)\00" : !cir.array<!s8i x 33>> +// CIR: cir.global "private" constant cir_private dso_local @".str.4" = #cir.const_array<"staticFuncName\00" : !cir.array<!s8i x 15>> : !cir.array<!s8i x 15> // CIR: cir.global "private" constant cir_private dso_local @__func__.staticFunction = #cir.const_array<"staticFunction\00" : !cir.array<!s8i x 15>> // CIR: cir.global "private" constant cir_private dso_local @__PRETTY_FUNCTION__.staticFunction = #cir.const_array<"void staticFunction(void)\00" : !cir.array<!s8i x 26>> // TODO(cir): These should be unnamed_addr +// LLVM: @staticFuncName.name = internal global ptr @.str.4, align 8 // LLVM: @.str = private constant [1 x i8] zeroinitializer, align 1 // LLVM: @func = global ptr @.str, align 8 // LLVM: @__func__.plainFunction = private constant [14 x i8] c"plainFunction\00" @@ -36,6 +39,7 @@ // OGCG: @__PRETTY_FUNCTION__.externFunction = private unnamed_addr constant [26 x i8] c"void externFunction(void)\00" // OGCG: @__func__.privateExternFunction = private unnamed_addr constant [22 x i8] c"privateExternFunction\00" // OGCG: @__PRETTY_FUNCTION__.privateExternFunction = private unnamed_addr constant [33 x i8] c"void privateExternFunction(void)\00" +// OGCG: @staticFuncName.name = internal global ptr @.str.4, align 8 // OGCG: @__func__.staticFunction = private unnamed_addr constant [15 x i8] c"staticFunction\00" // OGCG: @__PRETTY_FUNCTION__.staticFunction = private unnamed_addr constant [26 x i8] c"void staticFunction(void)\00" @@ -69,11 +73,15 @@ static void staticFunction(void) { printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); } +void staticFuncName(void) { + static const char *name = __func__; +} + int main(void) { plainFunction(); externFunction(); privateExternFunction(); staticFunction(); - + staticFuncName(); return 0; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
