[llvm] r312686 - Object: Downgrade invalid weak externals from an assert fail to an llvm::Error when creating an irsymtab.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 6 18:33:52 PDT 2017


Author: pcc
Date: Wed Sep  6 18:33:52 2017
New Revision: 312686

URL: http://llvm.org/viewvc/llvm-project?rev=312686&view=rev
Log:
Object: Downgrade invalid weak externals from an assert fail to an llvm::Error when creating an irsymtab.

This fixes bitcode emission for modules containing invalid weak externals.

Added:
    llvm/trunk/test/Bitcode/invalid-weak-external.ll
Modified:
    llvm/trunk/lib/Object/IRSymtab.cpp

Modified: llvm/trunk/lib/Object/IRSymtab.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRSymtab.cpp?rev=312686&r1=312685&r2=312686&view=diff
==============================================================================
--- llvm/trunk/lib/Object/IRSymtab.cpp (original)
+++ llvm/trunk/lib/Object/IRSymtab.cpp Wed Sep  6 18:33:52 2017
@@ -231,11 +231,14 @@ Error Builder::addSymbol(const ModuleSym
 
     if ((Flags & object::BasicSymbolRef::SF_Weak) &&
         (Flags & object::BasicSymbolRef::SF_Indirect)) {
+      auto *Fallback = dyn_cast<GlobalValue>(
+          cast<GlobalAlias>(GV)->getAliasee()->stripPointerCasts());
+      if (!Fallback)
+        return make_error<StringError>("Invalid weak external",
+                                       inconvertibleErrorCode());
       std::string FallbackName;
       raw_string_ostream OS(FallbackName);
-      Msymtab.printSymbolName(
-          OS, cast<GlobalValue>(
-                  cast<GlobalAlias>(GV)->getAliasee()->stripPointerCasts()));
+      Msymtab.printSymbolName(OS, Fallback);
       OS.flush();
       setStr(Uncommon().COFFWeakExternFallbackName, Saver.save(FallbackName));
     }

Added: llvm/trunk/test/Bitcode/invalid-weak-external.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid-weak-external.ll?rev=312686&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/invalid-weak-external.ll (added)
+++ llvm/trunk/test/Bitcode/invalid-weak-external.ll Wed Sep  6 18:33:52 2017
@@ -0,0 +1,11 @@
+; REQUIRES: x86-registered-target
+; RUN: opt -o %t %s
+; RUN: not llvm-lto2 dump-symtab %t 2>&1 | FileCheck %s
+
+target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "x86_64-pc-windows-msvc"
+
+ at bar = global i32 0
+
+; CHECK: Invalid weak external
+ at foo = weak alias i32, i32* getelementptr (i32, i32* @bar, i32 1)




More information about the llvm-commits mailing list