Skip to content

Commit 5b342e6

Browse files
authored
[RemoveDIs][DebugInfo] Check for null marker when printing DPValues (llvm#82238)
The function to print DPValues currently tries to incorporate the function it is part of, which is found through its marker; this means when we try to print a DPValue with no marker, we dereference a nullptr. We can print instructions without parents, and so the same should be true for DPValues; this patch changes DPValue::print to check for a null marker and avoid dereferencing it. Fixes issue: llvm#82230
1 parent 769c22f commit 5b342e6

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

llvm/lib/IR/AsmWriter.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ static const Module *getModuleFromDPI(const DPMarker *Marker) {
293293
}
294294

295295
static const Module *getModuleFromDPI(const DPValue *DPV) {
296-
return getModuleFromDPI(DPV->getMarker());
296+
return DPV->getMarker() ? getModuleFromDPI(DPV->getMarker()) : nullptr;
297297
}
298298

299299
static void PrintCallingConv(unsigned cc, raw_ostream &Out) {
@@ -4886,8 +4886,9 @@ void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST,
48864886
if (F)
48874887
MST.incorporateFunction(*F);
48884888
};
4889-
incorporateFunction(Marker->getParent() ? Marker->getParent()->getParent()
4890-
: nullptr);
4889+
incorporateFunction(Marker && Marker->getParent()
4890+
? Marker->getParent()->getParent()
4891+
: nullptr);
48914892
AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug);
48924893
W.printDPValue(*this);
48934894
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
;; Tests that we can debug-print DPValues that have no markers attached.
2+
; RUN: opt -passes="instcombine" -debug %s -o /dev/null 2>&1 | FileCheck %s
3+
; REQUIRES: asserts
4+
5+
; CHECK: CLONE: DPValue value {
6+
; CHECK-SAME: marker @0x0
7+
8+
define ptr @func_10(i32 %p_11) {
9+
entry:
10+
%conv108 = zext i32 %p_11 to i64
11+
tail call void @llvm.dbg.value(metadata i64 %conv108, metadata !4, metadata !DIExpression()), !dbg !12
12+
br label %func_29.exit
13+
14+
func_29.exit: ; preds = %entry
15+
store i64 %conv108, ptr null, align 1
16+
ret ptr null
17+
}
18+
19+
declare void @llvm.dbg.value(metadata, metadata, metadata)
20+
21+
!llvm.dbg.cu = !{!0}
22+
!llvm.module.flags = !{!3}
23+
24+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None)
25+
!1 = !DIFile(filename: "csmith5961503756960.c", directory: "/llvm")
26+
!2 = !{}
27+
!3 = !{i32 2, !"Debug Info Version", i32 3}
28+
!4 = !DILocalVariable(name: "p_31", arg: 2, scope: !5, file: !1, line: 148, type: !7)
29+
!5 = distinct !DISubprogram(name: "func_29", scope: !1, file: !1, line: 148, type: !6, scopeLine: 149, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
30+
!6 = !DISubroutineType(types: !2)
31+
!7 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint64_t", file: !8, line: 60, baseType: !9)
32+
!8 = !DIFile(filename: "/foo/_stdint.h", directory: "")
33+
!9 = !DIDerivedType(tag: DW_TAG_typedef, name: "__uint64_t", file: !10, line: 108, baseType: !11)
34+
!10 = !DIFile(filename: "/foo/_default_types.h", directory: "")
35+
!11 = !DIBasicType(name: "unsigned long long", size: 64, encoding: DW_ATE_unsigned)
36+
!12 = !DILocation(line: 0, scope: !5)

0 commit comments

Comments
 (0)