]> granicus.if.org Git - llvm/commitdiff
Fix NameAnonFunctions pass: for ThinLTO we need to rename global variables as well
authorMehdi Amini <mehdi.amini@apple.com>
Fri, 16 Sep 2016 16:56:25 +0000 (16:56 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Fri, 16 Sep 2016 16:56:25 +0000 (16:56 +0000)
A follow-up patch will rename this pass and the source file accordingly,
but I figured the non-NFC change will be easier to spot in isolation.

Differential Revision: https://reviews.llvm.org/D24641

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281744 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/NameAnonFunctions.cpp
test/Transforms/NameAnonFunctions/rename.ll

index 6dc3520b61ac18af3a19f0a666664538d3afbec1..f6dd98d12abf55ffee6e2567d71b87a09c95d147 100644 (file)
@@ -67,12 +67,17 @@ bool llvm::nameUnamedFunctions(Module &M) {
   bool Changed = false;
   ModuleHasher ModuleHash(M);
   int count = 0;
-  for (auto &F : M) {
-    if (F.hasName())
-      continue;
-    F.setName(Twine("anon.") + ModuleHash.get() + "." + Twine(count++));
+  auto RenameIfNeed = [&] (GlobalValue &GV) {
+    if (GV.hasName())
+      return;
+    GV.setName(Twine("anon.") + ModuleHash.get() + "." + Twine(count++));
     Changed = true;
-  }
+  };
+  for (auto &GO : M.global_objects())
+    RenameIfNeed(GO);
+  for (auto &GA : M.aliases())
+    RenameIfNeed(GA);
+
   return Changed;
 }
 
index 851746f7a979c5c675b07f858246dad559a3df49..de576cb95c5eec72ce55b363f8422c5dc905c7c0 100644 (file)
@@ -11,6 +11,8 @@ define internal void @bar() {
     ret void
 }
 
+; CHECK: @anon.acbd18db4cc2f85cedef654fccc4a4d8.3 = global i8 0
+; CHECK: @anon.acbd18db4cc2f85cedef654fccc4a4d8.4 = alias i8, i8* @anon.acbd18db4cc2f85cedef654fccc4a4d8.3
 ; CHECK: define void @anon.acbd18db4cc2f85cedef654fccc4a4d8.0()
 ; CHECK: define void @anon.acbd18db4cc2f85cedef654fccc4a4d8.1()
 ; CHECK: define void @anon.acbd18db4cc2f85cedef654fccc4a4d8.2()
@@ -25,3 +27,7 @@ define void @2() {
     ret void
 }
 
+
+@3 = global i8 0
+
+@4 = alias i8, i8 *@3