Skip to content

Commit fc0d70f

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. (cherry picked from commit 35e53a8) Change-Id: I54a67e80408f2bae9a30a99d91c1fb1dce084664
1 parent 6043cca commit fc0d70f

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
@@ -5467,6 +5467,9 @@ llvm::DIType *CGDebugInfo::CreateSelfType(const QualType &QualTy,
54675467
void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
54685468
const VarDecl *VD, llvm::Value *Storage, CGBuilderTy &Builder,
54695469
const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
5470+
// FIXME: Workaround to prevent crash when using with -gheterogeneous-dwarf
5471+
if (CGM.getCodeGenOpts().isHeterogeneousDwarfEnabled())
5472+
return;
54705473
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
54715474
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
54725475

@@ -5599,6 +5602,9 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
55995602
unsigned ArgNo,
56005603
llvm::AllocaInst *Alloca,
56015604
CGBuilderTy &Builder) {
5605+
// FIXME: Workaround to prevent crash when using with -gheterogeneous-dwarf
5606+
if (CGM.getCodeGenOpts().isHeterogeneousDwarfEnabled())
5607+
return;
56025608
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
56035609
ASTContext &C = CGM.getContext();
56045610
const BlockDecl *blockDecl = block.getBlockDecl();
@@ -6410,6 +6416,12 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
64106416

64116417
void CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
64126418
const VarDecl *D) {
6419+
// FIXME: Workaround to prevent crash when using with -gheterogeneous-dwarf
6420+
// NOTE: Only currently reachable for BPF target, but check added for
6421+
// completeness and in case this changes.
6422+
if (CGM.getCodeGenOpts().isHeterogeneousDwarfEnabled())
6423+
return;
6424+
64136425
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
64146426
if (D->hasAttr<NoDebugAttr>())
64156427
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)