[PATCH] D12851: [GlobalOpt] Sort members of llvm.used deterministically

Jake VanAdrighem via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 10:37:32 PDT 2015


JakeVanAdrighem created this revision.
JakeVanAdrighem added a subscriber: llvm-commits.

Fix the way we sort the llvm.used and llvm.compiler.used members. Previously we were retrieving empty strings with getName and "sorting" them.

This bug seems to have been introduced in Revision rL183756 and has somehow survived.

http://reviews.llvm.org/D12851

Files:
  lib/Transforms/IPO/GlobalOpt.cpp
  test/Transforms/GlobalOpt/alias-used.ll

Index: test/Transforms/GlobalOpt/alias-used.ll
===================================================================
--- test/Transforms/GlobalOpt/alias-used.ll
+++ test/Transforms/GlobalOpt/alias-used.ll
@@ -7,7 +7,7 @@
 @ia = internal alias i8, i8* @i
 
 @llvm.used = appending global [3 x i8*] [i8* bitcast (void ()* @fa to i8*), i8* bitcast (void ()* @f to i8*), i8* @ca], section "llvm.metadata"
-; CHECK-DAG: @llvm.used = appending global [3 x i8*] [i8* bitcast (void ()* @fa to i8*), i8* bitcast (void ()* @f to i8*), i8* @ca], section "llvm.metadata"
+; CHECK-DAG: @llvm.used = appending global [3 x i8*] [i8* @ca, i8* bitcast (void ()* @fa to i8*), i8* bitcast (void ()* @f to i8*)], section "llvm.metadata"
 
 @llvm.compiler.used = appending global [4 x i8*] [i8* bitcast (void ()* @fa3 to i8*), i8* bitcast (void ()* @fa to i8*), i8* @ia, i8* @i], section "llvm.metadata"
 ; CHECK-DAG: @llvm.compiler.used = appending global [2 x i8*] [i8* bitcast (void ()* @fa3 to i8*), i8* @ia], section "llvm.metadata"
Index: lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- lib/Transforms/IPO/GlobalOpt.cpp
+++ lib/Transforms/IPO/GlobalOpt.cpp
@@ -2712,7 +2712,8 @@
 }
 
 static int compareNames(Constant *const *A, Constant *const *B) {
-  return (*A)->getName().compare((*B)->getName());
+  return (*A)->stripPointerCasts()->getName().compare(
+      (*B)->stripPointerCasts()->getName());
 }
 
 static void setUsedInitializer(GlobalVariable &V,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12851.34699.patch
Type: text/x-patch
Size: 1501 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150914/c911f227/attachment.bin>


More information about the llvm-commits mailing list