Skip to content

Commit 978060c

Browse files
committedNov 16, 2015
Don't generate discriminators for calls to debug intrinsics
Summary: This fails a check in Verifier.cpp, which checks for location matches between the declared variable and the !dbg attachments. Reviewers: dnovillo, dblaikie, danielcdh Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14657 llvm-svn: 253194
1 parent db9081b commit 978060c

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed
 

‎llvm/lib/Transforms/Utils/AddDiscriminators.cpp

+19-17
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "llvm/IR/DIBuilder.h"
5959
#include "llvm/IR/DebugInfo.h"
6060
#include "llvm/IR/Instructions.h"
61+
#include "llvm/IR/IntrinsicInst.h"
6162
#include "llvm/IR/LLVMContext.h"
6263
#include "llvm/IR/Module.h"
6364
#include "llvm/Pass.h"
@@ -233,26 +234,27 @@ bool AddDiscriminators::runOnFunction(Function &F) {
233234
const DILocation *FirstDIL = NULL;
234235
for (auto &I : B.getInstList()) {
235236
CallInst *Current = dyn_cast<CallInst>(&I);
236-
if (Current) {
237-
DILocation *CurrentDIL = Current->getDebugLoc();
238-
if (FirstDIL) {
239-
if (CurrentDIL && CurrentDIL->getLine() == FirstDIL->getLine() &&
240-
CurrentDIL->getFilename() == FirstDIL->getFilename()) {
241-
auto *Scope = FirstDIL->getScope();
242-
auto *File = Builder.createFile(FirstDIL->getFilename(),
243-
Scope->getDirectory());
244-
auto *NewScope = Builder.createLexicalBlockFile(
245-
Scope, File, FirstDIL->computeNewDiscriminator());
246-
Current->setDebugLoc(DILocation::get(
247-
Ctx, CurrentDIL->getLine(), CurrentDIL->getColumn(), NewScope,
248-
CurrentDIL->getInlinedAt()));
249-
Changed = true;
250-
} else {
251-
FirstDIL = CurrentDIL;
252-
}
237+
if (!Current || isa<DbgInfoIntrinsic>(&I))
238+
continue;
239+
240+
DILocation *CurrentDIL = Current->getDebugLoc();
241+
if (FirstDIL) {
242+
if (CurrentDIL && CurrentDIL->getLine() == FirstDIL->getLine() &&
243+
CurrentDIL->getFilename() == FirstDIL->getFilename()) {
244+
auto *Scope = FirstDIL->getScope();
245+
auto *File = Builder.createFile(FirstDIL->getFilename(),
246+
Scope->getDirectory());
247+
auto *NewScope = Builder.createLexicalBlockFile(
248+
Scope, File, FirstDIL->computeNewDiscriminator());
249+
Current->setDebugLoc(DILocation::get(
250+
Ctx, CurrentDIL->getLine(), CurrentDIL->getColumn(), NewScope,
251+
CurrentDIL->getInlinedAt()));
252+
Changed = true;
253253
} else {
254254
FirstDIL = CurrentDIL;
255255
}
256+
} else {
257+
FirstDIL = CurrentDIL;
256258
}
257259
}
258260
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: opt -S -add-discriminators < %s | FileCheck %s
2+
3+
declare void @llvm.dbg.declare(metadata, metadata, metadata)
4+
5+
; This checks whether the add-discriminators pass producess valid metadata on
6+
; llvm.dbg.declare instructions
7+
;
8+
; CHECK-LABEL: @test_valid_metadata
9+
define void @test_valid_metadata() {
10+
%a = alloca i8
11+
call void @llvm.dbg.declare(metadata i8* %a, metadata !2, metadata !5), !dbg !6
12+
%b = alloca i8
13+
call void @llvm.dbg.declare(metadata i8* %b, metadata !9, metadata !5), !dbg !11
14+
ret void
15+
}
16+
17+
!llvm.module.flags = !{!0, !1}
18+
19+
!0 = !{i32 2, !"Dwarf Version", i32 4}
20+
!1 = !{i32 2, !"Debug Info Version", i32 3}
21+
!2 = !DILocalVariable(scope: !3)
22+
!3 = distinct !DISubprogram(scope: null, file: !4, isLocal: false, isDefinition: true, isOptimized: false)
23+
!4 = !DIFile(filename: "a.cpp", directory: "/tmp")
24+
!5 = !DIExpression()
25+
!6 = !DILocation(line: 0, scope: !3, inlinedAt: !7)
26+
!7 = distinct !DILocation(line: 0, scope: !8)
27+
!8 = distinct !DISubprogram(linkageName: "test_valid_metadata", scope: null, isLocal: false, isDefinition: true, isOptimized: false)
28+
!9 = !DILocalVariable(scope: !10)
29+
!10 = distinct !DISubprogram(scope: null, file: !4, isLocal: false, isDefinition: true, isOptimized: false)
30+
!11 = !DILocation(line: 0, scope: !10)

0 commit comments

Comments
 (0)
Please sign in to comment.