Skip to content

Commit 35e53a8

Browse files
committed
[HeterogeneousDWARF] Workarounds to prevent CGDebugInfo crashes
Any path which can produce a DIExpression is invalid when -gheterogeneous-dwarf=diexpr, so stub out these paths to avoid a crash until they are implemented. Change-Id: I81446f887727fb343a2a0527f50aa50f22978d81
1 parent 16a8997 commit 35e53a8

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5515,6 +5515,9 @@ llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
55155515
void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
55165516
const VarDecl *VD, llvm::Value *Storage, CGBuilderTy &Builder,
55175517
const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
5518+
// FIXME: Workaround to prevent crash when using with -gheterogeneous-dwarf
5519+
if (CGM.getCodeGenOpts().isHeterogeneousDwarfEnabled())
5520+
return;
55185521
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
55195522
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
55205523

@@ -5647,6 +5650,9 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
56475650
unsigned ArgNo,
56485651
llvm::AllocaInst *Alloca,
56495652
CGBuilderTy &Builder) {
5653+
// FIXME: Workaround to prevent crash when using with -gheterogeneous-dwarf
5654+
if (CGM.getCodeGenOpts().isHeterogeneousDwarfEnabled())
5655+
return;
56505656
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
56515657
ASTContext &C = CGM.getContext();
56525658
const BlockDecl *blockDecl = block.getBlockDecl();
@@ -6458,6 +6464,12 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
64586464

64596465
void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
64606466
const VarDecl *D) {
6467+
// FIXME: Workaround to prevent crash when using with -gheterogeneous-dwarf
6468+
// NOTE: Only currently reachable for BPF target, but check added for
6469+
// completeness and in case this changes.
6470+
if (CGM.getCodeGenOpts().isHeterogeneousDwarfEnabled())
6471+
return;
6472+
64616473
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
64626474
if (D->hasAttr<NoDebugAttr>())
64636475
return;

clang/test/CodeGen/debug-info-block-expr-heterogeneous-dwarf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void test_local_block() {
3535

3636
// FIXME(KZHURAVL): Update EmitDeclareOfBlockDeclRefVariable and EmitDeclareOfBlockLiteralArgVariable.
3737
// CHECK-LABEL: @__test_local_block_block_invoke
38-
// CHECK: #dbg_declare({{.*}}!DIExpression(DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}, DW_OP_deref, DW_OP_plus_uconst, {{[0-9]+}}){{.*}})
38+
// CHECK-NOT: #dbg_declare({{.*}}
3939
^ { block_var = 1; }();
4040
}
4141

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// REQUIRES: amdgpu-registered-target
2+
// RUN: %clang -Xclang -cl-std=CL2.0 -emit-llvm -g -gheterogeneous-dwarf=diexpr -O0 -S -nogpulib -target amdgcn-amd-amdhsa -mcpu=gfx1010 -o - %s | FileCheck %s
3+
// RUN: %clang -Xclang -cl-std=CL2.0 -emit-llvm -g -gheterogeneous-dwarf=diexpr -O0 -S -nogpulib -target amdgcn-amd-amdhsa-opencl -mcpu=gfx1010 -o - %s | FileCheck %s
4+
5+
// FIXME: Currently just testing that we don't crash; test for the absense
6+
// of meaningful debug information for the block is to identify this test
7+
// to update/replace when this is implemented.
8+
9+
// CHECK-NOT: call void @llvm.dbg.{{.*}}%block.capture.addr
10+
11+
void fn(__global uint* res);
12+
__kernel void kern(__global uint* res) {
13+
void (^kernelBlock)(void) = ^{ fn(res); };
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// REQUIRES: bpf-registered-target
2+
// RUN: %clang -Xclang -cl-std=CL2.0 -emit-llvm -g -gheterogeneous-dwarf=diexpr -O0 -S -nogpulib -target bpf-linux-gnu -o - %s | FileCheck %s
3+
4+
// FIXME: Currently just testing that we don't crash; test for the absense
5+
// of meaningful debug information for the extern is to identify this test
6+
// to update/replace when this is implemented.
7+
8+
// CHECK-NOT: DIGlobalVariable
9+
10+
extern char ch;
11+
int test() {
12+
return ch;
13+
}

0 commit comments

Comments
 (0)