GlobalOpt: Handle non-zero offsets for aliases
[oota-llvm.git] / lib / Transforms / IPO / GlobalOpt.cpp
index dc9b2a8105ea7d81fbed15a9dc2b07e71ddb64df..63a6058b9693f996cc03cd097546677c5b262559 100644 (file)
@@ -2865,7 +2865,12 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) {
       continue;
 
     Constant *Aliasee = J->getAliasee();
-    GlobalValue *Target = cast<GlobalValue>(Aliasee->stripPointerCasts());
+    GlobalValue *Target = dyn_cast<GlobalValue>(Aliasee->stripPointerCasts());
+    // We can't trivially replace the alias with the aliasee if the aliasee is
+    // non-trivial in some way.
+    // TODO: Try to handle non-zero GEPs of local aliasees.
+    if (!Target)
+      continue;
     Target->removeDeadConstantUsers();
 
     // Make all users of the alias use the aliasee instead.