| 1 |
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -o %t.cir |
| 2 |
// RUN: FileCheck %s --input-file=%t.cir --check-prefix=CIR |
| 3 |
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm -o %t-cir.ll |
| 4 |
// RUN: FileCheck %s --input-file=%t-cir.ll --check-prefix=LLVM |
| 5 |
// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -o %t.ll |
| 6 |
// RUN: FileCheck %s --input-file=%t.ll --check-prefix=OGCG |
| 7 |
|
| 8 |
// CIR: cir.global "private" internal dso_local @staticFuncName.name = #cir.global_view<@".str.4"> : !cir.ptr<!s8i> {alignment = 8 : i64} loc(#loc1) |
| 9 |
// CIR: cir.global "private" constant cir_private dso_local @".str" = #cir.zero : !cir.array<!s8i x 1> |
| 10 |
// CIR: cir.global external @func = #cir.global_view<@".str"> : !cir.ptr<!s8i> |
| 11 |
// CIR: cir.global "private" constant cir_private dso_local @__func__.plainFunction = #cir.const_array<"plainFunction\00" : !cir.array<!s8i x 14>> |
| 12 |
// CIR: cir.global "private" constant cir_private dso_local @__PRETTY_FUNCTION__.plainFunction = #cir.const_array<"void plainFunction(void)\00" : !cir.array<!s8i x 25>> |
| 13 |
// CIR: cir.global "private" constant cir_private dso_local @__func__.externFunction = #cir.const_array<"externFunction\00" : !cir.array<!s8i x 15>> |
| 14 |
// CIR: cir.global "private" constant cir_private dso_local @__PRETTY_FUNCTION__.externFunction = #cir.const_array<"void externFunction(void)\00" : !cir.array<!s8i x 26>> |
| 15 |
// CIR: cir.global "private" constant cir_private dso_local @__func__.privateExternFunction = #cir.const_array<"privateExternFunction\00" : !cir.array<!s8i x 22>> |
| 16 |
// CIR: cir.global "private" constant cir_private dso_local @__PRETTY_FUNCTION__.privateExternFunction = #cir.const_array<"void privateExternFunction(void)\00" : !cir.array<!s8i x 33>> |
| 17 |
// 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> |
| 18 |
// CIR: cir.global "private" constant cir_private dso_local @__func__.staticFunction = #cir.const_array<"staticFunction\00" : !cir.array<!s8i x 15>> |
| 19 |
// CIR: cir.global "private" constant cir_private dso_local @__PRETTY_FUNCTION__.staticFunction = #cir.const_array<"void staticFunction(void)\00" : !cir.array<!s8i x 26>> |
| 20 |
|
| 21 |
// TODO(cir): These should be unnamed_addr |
| 22 |
// LLVM: @staticFuncName.name = internal global ptr @.str.4, align 8 |
| 23 |
// LLVM: @.str = private constant [1 x i8] zeroinitializer, align 1 |
| 24 |
// LLVM: @func = global ptr @.str, align 8 |
| 25 |
// LLVM: @__func__.plainFunction = private constant [14 x i8] c"plainFunction\00" |
| 26 |
// LLVM: @__PRETTY_FUNCTION__.plainFunction = private constant [25 x i8] c"void plainFunction(void)\00" |
| 27 |
// LLVM: @__func__.externFunction = private constant [15 x i8] c"externFunction\00" |
| 28 |
// LLVM: @__PRETTY_FUNCTION__.externFunction = private constant [26 x i8] c"void externFunction(void)\00" |
| 29 |
// LLVM: @__func__.privateExternFunction = private constant [22 x i8] c"privateExternFunction\00" |
| 30 |
// LLVM: @__PRETTY_FUNCTION__.privateExternFunction = private constant [33 x i8] c"void privateExternFunction(void)\00" |
| 31 |
// LLVM: @__func__.staticFunction = private constant [15 x i8] c"staticFunction\00" |
| 32 |
// LLVM: @__PRETTY_FUNCTION__.staticFunction = private constant [26 x i8] c"void staticFunction(void)\00" |
| 33 |
|
| 34 |
// OGCG: @.str = private unnamed_addr constant [1 x i8] zeroinitializer, align 1 |
| 35 |
// OGCG: @func = global ptr @.str, align 8 |
| 36 |
// OGCG: @__func__.plainFunction = private unnamed_addr constant [14 x i8] c"plainFunction\00" |
| 37 |
// OGCG: @__PRETTY_FUNCTION__.plainFunction = private unnamed_addr constant [25 x i8] c"void plainFunction(void)\00" |
| 38 |
// OGCG: @__func__.externFunction = private unnamed_addr constant [15 x i8] c"externFunction\00" |
| 39 |
// OGCG: @__PRETTY_FUNCTION__.externFunction = private unnamed_addr constant [26 x i8] c"void externFunction(void)\00" |
| 40 |
// OGCG: @__func__.privateExternFunction = private unnamed_addr constant [22 x i8] c"privateExternFunction\00" |
| 41 |
// OGCG: @__PRETTY_FUNCTION__.privateExternFunction = private unnamed_addr constant [33 x i8] c"void privateExternFunction(void)\00" |
| 42 |
// OGCG: @staticFuncName.name = internal global ptr @.str.4, align 8 |
| 43 |
// OGCG: @__func__.staticFunction = private unnamed_addr constant [15 x i8] c"staticFunction\00" |
| 44 |
// OGCG: @__PRETTY_FUNCTION__.staticFunction = private unnamed_addr constant [26 x i8] c"void staticFunction(void)\00" |
| 45 |
|
| 46 |
const char* func = __func__; |
| 47 |
|
| 48 |
int printf(const char *, ...); |
| 49 |
|
| 50 |
void plainFunction(void) { |
| 51 |
printf("__func__ %s\n", __func__); |
| 52 |
printf("__FUNCTION__ %s\n", __FUNCTION__); |
| 53 |
printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); |
| 54 |
} |
| 55 |
|
| 56 |
extern void externFunction(void) { |
| 57 |
printf("__func__ %s\n", __func__); |
| 58 |
printf("__FUNCTION__ %s\n", __FUNCTION__); |
| 59 |
printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); |
| 60 |
} |
| 61 |
|
| 62 |
__private_extern__ void privateExternFunction(void) { |
| 63 |
printf("__func__ %s\n", __func__); |
| 64 |
printf("__FUNCTION__ %s\n", __FUNCTION__); |
| 65 |
printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); |
| 66 |
} |
| 67 |
|
| 68 |
// TODO(cir): Add support for __captured_stmt |
| 69 |
|
| 70 |
static void staticFunction(void) { |
| 71 |
printf("__func__ %s\n", __func__); |
| 72 |
printf("__FUNCTION__ %s\n", __FUNCTION__); |
| 73 |
printf("__PRETTY_FUNCTION__ %s\n\n", __PRETTY_FUNCTION__); |
| 74 |
} |
| 75 |
|
| 76 |
void staticFuncName(void) { |
| 77 |
static const char *name = __func__; |
| 78 |
} |
| 79 |
|
| 80 |
int main(void) { |
| 81 |
plainFunction(); |
| 82 |
externFunction(); |
| 83 |
privateExternFunction(); |
| 84 |
staticFunction(); |
| 85 |
staticFuncName(); |
| 86 |
return 0; |
| 87 |
} |