[llvm] r248728 - [GlobalOpt] Sort members of llvm.used deterministically

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 12:02:12 PDT 2015


Author: silvas
Date: Mon Sep 28 14:02:11 2015
New Revision: 248728

URL: http://llvm.org/viewvc/llvm-project?rev=248728&view=rev
Log:
[GlobalOpt] Sort members of llvm.used deterministically

Patch by Jake VanAdrighem!

Summary:
Fix the way we sort the llvm.used and llvm.compiler.used members.

This bug seems to have been introduced in rL183756 through a set of improper casts to GlobalValue*. In subsequent patches this problem was missed and transformed into a getName call on a ConstantExpr.

Reviewers: silvas

Subscribers: silvas, llvm-commits

Differential Revision: http://reviews.llvm.org/D12851

Modified:
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/trunk/test/Transforms/GlobalOpt/alias-used.ll

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=248728&r1=248727&r2=248728&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Mon Sep 28 14:02:11 2015
@@ -2712,7 +2712,8 @@ static bool EvaluateStaticConstructor(Fu
 }
 
 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,

Modified: llvm/trunk/test/Transforms/GlobalOpt/alias-used.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/alias-used.ll?rev=248728&r1=248727&r2=248728&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/alias-used.ll (original)
+++ llvm/trunk/test/Transforms/GlobalOpt/alias-used.ll Mon Sep 28 14:02:11 2015
@@ -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"




More information about the llvm-commits mailing list