[llvm-bugs] [Bug 36234] New: Mem2Reg removes debug info from IR generated from CLANG
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Feb 4 23:49:38 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=36234
Bug ID: 36234
Summary: Mem2Reg removes debug info from IR generated from
CLANG
Product: libraries
Version: 5.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Transformation Utilities
Assignee: unassignedbugs at nondot.org
Reporter: agupta at tifr.res.in
CC: llvm-bugs at lists.llvm.org
Please consider the following example:
int main()
{
int i;
i=0;
i=2;
}
If we emit IR of the above function via clang. We obtain the following:
define i32 @main() #0 !dbg !7 {
entry:
%i = alloca i32, align 4
call void @llvm.dbg.declare(metadata i32* %i, metadata !12, metadata !13),
!dbg !14
store i32 0, i32* %i, align 4, !dbg !15
store i32 2, i32* %i, align 4, !dbg !16
ret i32 0, !dbg !17
}
!12 = !DILocalVariable(name: "i", scope: !7, file: !8, line: 4, type: !11)
!13 = !DIExpression()
!14 = !DILocation(line: 4, column: 7, scope: !7)
!15 = !DILocation(line: 6, column: 4, scope: !7)
!16 = !DILocation(line: 8, column: 4, scope: !7)
!17 = !DILocation(line: 11, column: 1, scope: !7)
Please note that both the stores have debug information !15 and !16 that
correctly identifies the correct location of the writes on i.
If we pass the above function via Mem2Reg pass we obtain the following IR:
; Function Attrs: noinline nounwind
define i32 @main() #0 !dbg !7 {
call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !12, metadata !13),
!dbg !14
call void @llvm.dbg.value(metadata i32 2, i64 0, metadata !12, metadata !13),
!dbg !14
ret i32 0, !dbg !15
}
!12 = !DILocalVariable(name: "i", scope: !7, file: !8, line: 4, type: !11)
!13 = !DIExpression()
!14 = !DILocation(line: 4, column: 7, scope: !7)
!15 = !DILocation(line: 11, column: 1, scope: !7)
Please note that both store calls are replaced by dbg.value calls. Both of them
have debug value !14 that points at the declaration of the variable i. There is
no more debug info that points to the two assignments.
IMHO, this is bug in Mem2Reg. I think this is stemming from the functions
like the following function at Local.cpp:1104 (version 5.0.1)
void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
StoreInst *SI, DIBuilder &Builder) {
....
....
....
....
....
....
....
....
....
1139: Builder.insertDbgValueIntrinsic(DV, 0, DIVar, DIExpr, DDI->getDebugLoc(),
SI);
}
Please note that the new debugValue instruction at line 1139 is not taking
debug info from SI but it is getting DDI->getDebugLoc(). Therefore,
SI->getDebugLoc() is being lost.
I believe the debug information of declaration is already preserved in DIVar.
So there is no need to another copy on the new debugValue instruction.
Therefore, the fifth parameter should be SI->getDebugLoc().
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180205/e8e2dc3a/attachment.html>
More information about the llvm-bugs
mailing list