llvm.org GIT mirror llvm / 168146e
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253194 91177308-0d34-0410-b5e6-96231b3b80d8 Pavel Labath 3 years ago
2 changed file(s) with 49 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
5757 #include "llvm/IR/DIBuilder.h"
5858 #include "llvm/IR/DebugInfo.h"
5959 #include "llvm/IR/Instructions.h"
60 #include "llvm/IR/IntrinsicInst.h"
6061 #include "llvm/IR/LLVMContext.h"
6162 #include "llvm/IR/Module.h"
6263 #include "llvm/Pass.h"
232233 const DILocation *FirstDIL = NULL;
233234 for (auto &I : B.getInstList()) {
234235 CallInst *Current = dyn_cast(&I);
235 if (Current) {
236 DILocation *CurrentDIL = Current->getDebugLoc();
237 if (FirstDIL) {
238 if (CurrentDIL && CurrentDIL->getLine() == FirstDIL->getLine() &&
239 CurrentDIL->getFilename() == FirstDIL->getFilename()) {
240 auto *Scope = FirstDIL->getScope();
241 auto *File = Builder.createFile(FirstDIL->getFilename(),
242 Scope->getDirectory());
243 auto *NewScope = Builder.createLexicalBlockFile(
244 Scope, File, FirstDIL->computeNewDiscriminator());
245 Current->setDebugLoc(DILocation::get(
246 Ctx, CurrentDIL->getLine(), CurrentDIL->getColumn(), NewScope,
247 CurrentDIL->getInlinedAt()));
248 Changed = true;
249 } else {
250 FirstDIL = CurrentDIL;
251 }
236 if (!Current || isa(&I))
237 continue;
238
239 DILocation *CurrentDIL = Current->getDebugLoc();
240 if (FirstDIL) {
241 if (CurrentDIL && CurrentDIL->getLine() == FirstDIL->getLine() &&
242 CurrentDIL->getFilename() == FirstDIL->getFilename()) {
243 auto *Scope = FirstDIL->getScope();
244 auto *File = Builder.createFile(FirstDIL->getFilename(),
245 Scope->getDirectory());
246 auto *NewScope = Builder.createLexicalBlockFile(
247 Scope, File, FirstDIL->computeNewDiscriminator());
248 Current->setDebugLoc(DILocation::get(
249 Ctx, CurrentDIL->getLine(), CurrentDIL->getColumn(), NewScope,
250 CurrentDIL->getInlinedAt()));
251 Changed = true;
252252 } else {
253253 FirstDIL = CurrentDIL;
254254 }
255 } else {
256 FirstDIL = CurrentDIL;
255257 }
256258 }
257259 }
0 ; RUN: opt -S -add-discriminators < %s | FileCheck %s
1
2 declare void @llvm.dbg.declare(metadata, metadata, metadata)
3
4 ; This checks whether the add-discriminators pass producess valid metadata on
5 ; llvm.dbg.declare instructions
6 ;
7 ; CHECK-LABEL: @test_valid_metadata
8 define void @test_valid_metadata() {
9 %a = alloca i8
10 call void @llvm.dbg.declare(metadata i8* %a, metadata !2, metadata !5), !dbg !6
11 %b = alloca i8
12 call void @llvm.dbg.declare(metadata i8* %b, metadata !9, metadata !5), !dbg !11
13 ret void
14 }
15
16 !llvm.module.flags = !{!0, !1}
17
18 !0 = !{i32 2, !"Dwarf Version", i32 4}
19 !1 = !{i32 2, !"Debug Info Version", i32 3}
20 !2 = !DILocalVariable(scope: !3)
21 !3 = distinct !DISubprogram(scope: null, file: !4, isLocal: false, isDefinition: true, isOptimized: false)
22 !4 = !DIFile(filename: "a.cpp", directory: "/tmp")
23 !5 = !DIExpression()
24 !6 = !DILocation(line: 0, scope: !3, inlinedAt: !7)
25 !7 = distinct !DILocation(line: 0, scope: !8)
26 !8 = distinct !DISubprogram(linkageName: "test_valid_metadata", scope: null, isLocal: false, isDefinition: true, isOptimized: false)
27 !9 = !DILocalVariable(scope: !10)
28 !10 = distinct !DISubprogram(scope: null, file: !4, isLocal: false, isDefinition: true, isOptimized: false)
29 !11 = !DILocation(line: 0, scope: !10)