Skip to content

Commit bcbbb2c

Browse files
authored
[clang] Fix clang debug info generation for unprtototyped function (llvm#150022)
Consider this declaration: `int foo();` This function is described in LLVM with `clang::FunctionNoProtoType` class. ([See description](https://clang.llvm.org/doxygen/classclang_1_1FunctionNoProtoType.html)) Judging by [this comment](https://github.com/llvm/llvm-project/blob/a1bf0d1394e48894be05d274d3942ff77c35ce87/clang/lib/CodeGen/CGCall.cpp#L159C11-L159C12) all such functions are treated like functions with variadic number of parameters. When we want to [emit debug info](https://github.com/llvm/llvm-project/blob/0a8ddd396546bec7eaa4c3b7ef2f495e52bca0b8/clang/lib/CodeGen/CGDebugInfo.cpp#L4808) we have to know function that we calling. In method [getCalledFunction()](https://github.com/llvm/llvm-project/blob/0a8ddd396546bec7eaa4c3b7ef2f495e52bca0b8/llvm/include/llvm/IR/InstrTypes.h#L1348) we compare two types of function: 1. Function that we deduce from calling operand, and 2. Function that we store locally If they differ we get `nullptr` and can't emit appropriate debug info. The only thing they differ is: lhs function is variadic, but rhs function isn't Reason of this difference is that under RISC-V there is no overridden function that tells us about treating functions with no parameters. [Default function](https://github.com/llvm/llvm-project/blob/0a8ddd396546bec7eaa4c3b7ef2f495e52bca0b8/clang/lib/CodeGen/TargetInfo.cpp#L87) always return `false`. This patch overrides this function for RISC-V
1 parent 05b16af commit bcbbb2c

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4801,7 +4801,7 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke,
48014801
const FunctionDecl *CalleeDecl) {
48024802
if (!CallOrInvoke)
48034803
return;
4804-
auto *Func = CallOrInvoke->getCalledFunction();
4804+
auto *Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
48054805
if (!Func)
48064806
return;
48074807
if (Func->getSubprogram())
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Test that call site debug info is (un)supported in various configurations.
2+
3+
// Supported: DWARF5, -O1, standalone DI
4+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
5+
// RUN: -O1 -disable-llvm-passes \
6+
// RUN: -debug-info-kind=standalone -dwarf-version=5 \
7+
// RUN: | FileCheck %s -check-prefix=HAS-ATTR \
8+
// RUN: -implicit-check-not=DISubprogram -implicit-check-not=DIFlagAllCallsDescribed
9+
10+
// Supported: DWARF4 + LLDB tuning, -O1, limited DI
11+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
12+
// RUN: -O1 -disable-llvm-passes \
13+
// RUN: -debugger-tuning=lldb \
14+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
15+
// RUN: | FileCheck %s -check-prefix=HAS-ATTR \
16+
// RUN: -implicit-check-not=DISubprogram -implicit-check-not=DIFlagAllCallsDescribed
17+
18+
// Note: DIFlagAllCallsDescribed may have been enabled prematurely when tuning
19+
// for GDB under -gdwarf-4 in https://reviews.llvm.org/D69743. It's possible
20+
// this should have been 'Unsupported' until entry values emission was enabled
21+
// by default.
22+
//
23+
// Supported: DWARF4 + GDB tuning
24+
// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu \
25+
// RUN: %s -o - -O1 -disable-llvm-passes -debugger-tuning=gdb \
26+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
27+
// RUN: | FileCheck %s -check-prefix=HAS-ATTR \
28+
// RUN: -implicit-check-not=DIFlagAllCallsDescribed
29+
30+
// Supported: DWARF4 + LLDB, -O1
31+
// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu \
32+
// RUN: %s -o - -O1 -disable-llvm-passes -debugger-tuning=lldb \
33+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
34+
// RUN: | FileCheck %s -check-prefix=HAS-ATTR \
35+
// RUN: -implicit-check-not=DIFlagAllCallsDescribed
36+
37+
// Unsupported: -O0
38+
// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu \
39+
// RUN: %s -o - -O0 -disable-llvm-passes -debugger-tuning=gdb \
40+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
41+
// RUN: | FileCheck %s -check-prefix=NO-ATTR
42+
43+
// Supported: DWARF4 + LLDB tuning, -O1, line-tables only DI
44+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
45+
// RUN: -O1 -disable-llvm-passes \
46+
// RUN: -debugger-tuning=lldb \
47+
// RUN: -debug-info-kind=line-tables-only -dwarf-version=4 \
48+
// RUN: | FileCheck %s -check-prefix=LINE-TABLES-ONLY
49+
50+
// Unsupported: -O0
51+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
52+
// RUN: -O0 \
53+
// RUN: -debug-info-kind=standalone -dwarf-version=5 \
54+
// RUN: | FileCheck %s -check-prefix=NO-ATTR
55+
56+
// Unsupported: DWARF4
57+
// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - \
58+
// RUN: -O1 -disable-llvm-passes \
59+
// RUN: -debug-info-kind=standalone -dwarf-version=4 \
60+
// RUN: | FileCheck %s -check-prefix=NO-ATTR
61+
62+
// NO-ATTR-NOT: FlagAllCallsDescribed
63+
64+
// HAS-ATTR-DAG: DISubprogram(name: "declaration1", {{.*}}, spFlags: DISPFlagOptimized)
65+
// HAS-ATTR-DAG: DISubprogram(name: "declaration2", {{.*}}, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized
66+
// HAS-ATTR-DAG: DISubprogram(name: "declaration3", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
67+
// HAS-ATTR-DAG: DISubprogram(name: "declaration4", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized
68+
69+
// HAS-ATTR-DAG: DISubprogram(name: "force_irgen", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition
70+
71+
// LINE-TABLES-ONLY: DISubprogram(name: "force_irgen", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition
72+
73+
void declaration1();
74+
75+
void declaration2();
76+
77+
void declaration2() {}
78+
79+
void declaration3(void);
80+
81+
void declaration4(void);
82+
83+
void declaration4(void) {}
84+
85+
void __attribute__((optnone)) force_irgen(void) {
86+
declaration1();
87+
declaration3();
88+
}

0 commit comments

Comments
 (0)