<div dir="ltr">I missed any earlier discussion about this. Don't we want to keep this optimization, even if it's a real corner case that fires once in a blue moon? isLeakCheckerRoot() doesn't check any flags to see if any of the sanitizers are on.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Sep 25, 2013 at 4:32 AM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi nicholas,<br>
<br>
This change prevents GlobalOpt from turning globals into<br>
stack-allocated locals, if these variables may serve as a leak checker<br>
root. For instance, transforming<br>
Foo *x;<br>
int main() { x = new Foo(); }<br>
into<br>
int main() { Foo *x = new Foo(); }<br>
will make LeakSanitizer treat "x" as definitely leaked, which is<br>
undesirable.<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D1754" target="_blank">http://llvm-reviews.chandlerc.com/D1754</a><br>
<br>
Files:<br>
test/Transforms/GlobalOpt/metadata.ll<br>
test/Transforms/GlobalOpt/dont-localize-pointer.ll<br>
lib/Transforms/IPO/GlobalOpt.cpp<br>
<br>
Index: test/Transforms/GlobalOpt/metadata.ll<br>
===================================================================<br>
--- test/Transforms/GlobalOpt/metadata.ll<br>
+++ test/Transforms/GlobalOpt/metadata.ll<br>
@@ -3,24 +3,24 @@<br>
; PR6112 - When globalopt does RAUW(@G, %G), the metadata reference should drop<br>
; to null. Function local metadata that references @G from a different function<br>
; to that containing %G should likewise drop to null.<br>
-@G = internal global i8** null<br>
+@G = internal global i32 0<br>
<br>
define i32 @main(i32 %argc, i8** %argv) {<br>
; CHECK-LABEL: @main(<br>
; CHECK: %G = alloca<br>
- store i8** %argv, i8*** @G<br>
+ store i32 %argc, i32* @G<br>
ret i32 0<br>
}<br>
<br>
define void @foo(i32 %x) {<br>
- call void @llvm.foo(metadata !{i8*** @G, i32 %x})<br>
+ call void @llvm.foo(metadata !{i32* @G, i32 %x})<br>
; CHECK: call void @llvm.foo(metadata !{null, i32 %x})<br>
ret void<br>
}<br>
<br>
declare void @llvm.foo(metadata) nounwind readnone<br>
<br>
!named = !{!0}<br>
<br>
-!0 = metadata !{i8*** @G}<br>
+!0 = metadata !{i32* @G}<br>
; CHECK: !0 = metadata !{null}<br>
Index: test/Transforms/GlobalOpt/dont-localize-pointer.ll<br>
===================================================================<br>
--- /dev/null<br>
+++ test/Transforms/GlobalOpt/dont-localize-pointer.ll<br>
@@ -0,0 +1,10 @@<br>
+; RUN: opt -S -globalopt < %s | FileCheck %s<br>
+<br>
+@G = internal global i8** null<br>
+<br>
+define i32 @main(i32 %argc, i8** %argv) {<br>
+; CHECK-LABEL: @main(<br>
+; CHECK-NOT: alloca<br>
+ store i8** %argv, i8*** @G<br>
+ ret i32 0<br>
+}<br>
Index: lib/Transforms/IPO/GlobalOpt.cpp<br>
===================================================================<br>
--- lib/Transforms/IPO/GlobalOpt.cpp<br>
+++ lib/Transforms/IPO/GlobalOpt.cpp<br>
@@ -1951,7 +1951,8 @@<br>
GV->getType()->getElementType()->isSingleValueType() &&<br>
GS.AccessingFunction->getName() == "main" &&<br>
GS.AccessingFunction->hasExternalLinkage() &&<br>
- GV->getType()->getAddressSpace() == 0) {<br>
+ GV->getType()->getAddressSpace() == 0 &&<br>
+ !isLeakCheckerRoot(GV)) {<br>
DEBUG(dbgs() << "LOCALIZING GLOBAL: " << *GV);<br>
Instruction &FirstI = const_cast<Instruction&>(*GS.AccessingFunction<br>
->getEntryBlock().begin());<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>