<div dir="ltr"><span style="font-family:'helvetica neue',helvetica,arial,sans-serif">Patch breaks this bot <a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/12589/steps/check-llvm%20msan/logs/stdio">http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/12589/steps/check-llvm%20msan/logs/stdio</a></span><br></div><br><div class="gmail_quote"><div dir="ltr">On Fri, May 6, 2016 at 6:48 PM Mehdi Amini via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: mehdi_amini<br>
Date: Fri May 6 20:42:36 2016<br>
New Revision: 268832<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=268832&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=268832&view=rev</a><br>
Log:<br>
Refactor stripDebugInfo(Function) to handle intrinsic<br>
<br>
This moves the code that handles stripping debug info intrinsic from<br>
StripDebugInfo(Module) to StripDebugInfo(Function). The latter is<br>
already walking every instructions so it makes sense to do it at the<br>
same time.<br>
This makes also stripDebugInfo(Function) as an API more useful: it<br>
is really dropping every debug info in the Function.<br>
Finally the existing code is trigerring an assertion when the Module<br>
is not fully materialized.<br>
<br>
From: Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>><br>
<br>
Added:<br>
llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.bc<br>
llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.ll<br>
llvm/trunk/test/ThinLTO/X86/drop-debug-info.ll<br>
Modified:<br>
llvm/trunk/lib/IR/DebugInfo.cpp<br>
<br>
Modified: llvm/trunk/lib/IR/DebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=268832&r1=268831&r2=268832&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfo.cpp?rev=268832&r1=268831&r2=268832&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/IR/DebugInfo.cpp (original)<br>
+++ llvm/trunk/lib/IR/DebugInfo.cpp Fri May 6 20:42:36 2016<br>
@@ -247,8 +247,20 @@ bool llvm::stripDebugInfo(Function &F) {<br>
Changed = true;<br>
F.setSubprogram(nullptr);<br>
}<br>
+<br>
+ Function *Declare = F.getParent()->getFunction("llvm.dbg.declare");<br>
+ Function *DbgVal = F.getParent()->getFunction("llvm.dbg.value");<br>
for (BasicBlock &BB : F) {<br>
- for (Instruction &I : BB) {<br>
+ for (auto II = BB.begin(), End = BB.end(); II != End;) {<br>
+ Instruction &I = *II++; // We may delete the instruction, increment now.<br>
+ // Remove all of the calls to the debugger intrinsics, and remove them<br>
+ // from the module.<br>
+ CallInst *CI = dyn_cast<CallInst>(&I);<br>
+ if (CI && (CI->getCalledFunction() == Declare ||<br>
+ CI->getCalledFunction() == DbgVal)) {<br>
+ CI->eraseFromParent();<br>
+ Changed = true;<br>
+ }<br>
if (I.getDebugLoc()) {<br>
Changed = true;<br>
I.setDebugLoc(DebugLoc());<br>
@@ -261,26 +273,6 @@ bool llvm::stripDebugInfo(Function &F) {<br>
bool llvm::StripDebugInfo(Module &M) {<br>
bool Changed = false;<br>
<br>
- // Remove all of the calls to the debugger intrinsics, and remove them from<br>
- // the module.<br>
- if (Function *Declare = M.getFunction("llvm.dbg.declare")) {<br>
- while (!Declare->use_empty()) {<br>
- CallInst *CI = cast<CallInst>(Declare->user_back());<br>
- CI->eraseFromParent();<br>
- }<br>
- Declare->eraseFromParent();<br>
- Changed = true;<br>
- }<br>
-<br>
- if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {<br>
- while (!DbgVal->use_empty()) {<br>
- CallInst *CI = cast<CallInst>(DbgVal->user_back());<br>
- CI->eraseFromParent();<br>
- }<br>
- DbgVal->eraseFromParent();<br>
- Changed = true;<br>
- }<br>
-<br>
for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),<br>
NME = M.named_metadata_end(); NMI != NME;) {<br>
NamedMDNode *NMD = &*NMI;<br>
<br>
Added: llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.bc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.bc?rev=268832&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.bc?rev=268832&view=auto</a><br>
==============================================================================<br>
Binary files llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.bc (added) and llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.bc Fri May 6 20:42:36 2016 differ<br>
<br>
Added: llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.ll?rev=268832&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.ll?rev=268832&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.ll (added)<br>
+++ llvm/trunk/test/ThinLTO/X86/Inputs/drop-debug-info.ll Fri May 6 20:42:36 2016<br>
@@ -0,0 +1,47 @@<br>
+; This file is checked-in as a .bc file, because the debug info version is<br>
+; intentionally out-of-date and llvm-as will drop it before writing the bitcode<br>
+<br>
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-apple-macosx10.11.0"<br>
+<br>
+<br>
+@argc = global i8 0, align 1<br>
+<br>
+define void @globalfunc() {<br>
+entry:<br>
+ %0 = load i8, i8* @argc, align 1<br>
+ tail call void @llvm.dbg.value(metadata i8 %0, i64 0, metadata !19, metadata !29), !dbg !DILocation(scope: !13)<br>
+ ret void<br>
+}<br>
+<br>
+<br>
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata)<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!0}<br>
+!llvm.module.flags = !{!22, !23}<br>
+<br>
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, enums: !2, retainedTypes: !3, globals: !20, imports: !2, emissionKind: FullDebug)<br>
+!1 = !DIFile(filename: "test.cpp", directory: "")<br>
+!2 = !{}<br>
+!3 = !{!4}<br>
+!4 = !DICompositeType(tag: DW_TAG_class_type, name: "C", line: 2, size: 8, align: 8, file: !1, elements: !5, identifier: "_ZTS1C")<br>
+!5 = !{!6}<br>
+!6 = !DISubprogram(name: "test", file: !1, scope: !4, type: !7, isDefinition: false)<br>
+!7 = !DISubroutineType(types: !8)<br>
+!8 = !{!9, !10, !11, !11, !11, null}<br>
+!9 = !DIBasicType(encoding: DW_ATE_signed, size: 32, align: 32, name: "int")<br>
+!10 = !DIDerivedType(baseType: !4, tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial)<br>
+!11 = !DIBasicType(tag: DW_TAG_base_type, name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)<br>
+!13 = distinct !DISubprogram(name: "test_with_debug", linkageName: "test_with_debug", line: 6, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 6, file: !1, scope: !14, type: !15, variables: !17)<br>
+!14 = !DIFile(filename: "test.cpp", directory: "")<br>
+!15 = !DISubroutineType(types: !16)<br>
+!16 = !{null}<br>
+!17 = !{!18, !19}<br>
+!18 = !DILocalVariable(name: "c", line: 7, scope: !13, file: !14, type: !4)<br>
+!19 = !DILocalVariable(name: "lc", line: 8, scope: !13, file: !14, type: !11)<br>
+!20 = !{!21}<br>
+!21 = !DIGlobalVariable(name: "argc", line: 1, isLocal: false, isDefinition: true, scope: null, file: !14, type: !11, variable: i8* @argc)<br>
+!22 = !{i32 2, !"Dwarf Version", i32 4}<br>
+!23 = !{i32 2, !"Debug Info Version", i32 0}<br>
+!25 = !DILocation(line: 8, column: 3, scope: !13)<br>
+!29 = !DIExpression()<br>
<br>
Added: llvm/trunk/test/ThinLTO/X86/drop-debug-info.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/drop-debug-info.ll?rev=268832&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/drop-debug-info.ll?rev=268832&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/ThinLTO/X86/drop-debug-info.ll (added)<br>
+++ llvm/trunk/test/ThinLTO/X86/drop-debug-info.ll Fri May 6 20:42:36 2016<br>
@@ -0,0 +1,20 @@<br>
+; RUN: opt -module-summary %s -o %t.bc<br>
+; RUN: llvm-lto -thinlto-action=thinlink -o %t.index.bc %t.bc %p/Inputs/drop-debug-info.bc<br>
+<br>
+; The imported module has out-of-date debug information, let's make sure we can<br>
+; drop them without crashing when materializing later.<br>
+; RUN: llvm-lto -thinlto-action=import %t.bc -thinlto-index=%t.index.bc -o - | llvm-dis -o - | FileCheck %s<br>
+; CHECK: define available_externally void @globalfunc<br>
+; CHECK-NOT: llvm.dbg.value<br>
+<br>
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br>
+target triple = "x86_64-apple-macosx10.11.0"<br>
+<br>
+<br>
+define i32 @main() #0 {<br>
+entry:<br>
+ call void (...) @globalfunc()<br>
+ ret i32 0<br>
+}<br>
+<br>
+declare void @globalfunc(...)<br>
\ No newline at end of file<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>