[llvm] r226546 - Bitcode: Don't create comdats when autoupgrading macho bitcode

David Majnemer david.majnemer at gmail.com
Mon Jan 19 21:58:08 PST 2015


Author: majnemer
Date: Mon Jan 19 23:58:07 2015
New Revision: 226546

URL: http://llvm.org/viewvc/llvm-project?rev=226546&view=rev
Log:
Bitcode: Don't create comdats when autoupgrading macho bitcode

Don't infer COMDAT groups from older bitcode if the target is macho,
it doesn't have COMDATs.

Added:
    llvm/trunk/test/Bitcode/weak-macho-3.5.ll
    llvm/trunk/test/Bitcode/weak-macho-3.5.ll.bc
Modified:
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=226546&r1=226545&r2=226546&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Jan 19 23:58:07 2015
@@ -11,6 +11,7 @@
 #include "BitcodeReader.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Bitcode/LLVMBitCodes.h"
 #include "llvm/IR/AutoUpgrade.h"
 #include "llvm/IR/Constants.h"
@@ -1106,6 +1107,8 @@ std::error_code BitcodeReader::ParseValu
 
   SmallVector<uint64_t, 64> Record;
 
+  Triple TT(TheModule->getTargetTriple());
+
   // Read all the records for this value table.
   SmallString<128> ValueName;
   while (1) {
@@ -1137,8 +1140,12 @@ std::error_code BitcodeReader::ParseValu
 
       V->setName(StringRef(ValueName.data(), ValueName.size()));
       if (auto *GO = dyn_cast<GlobalObject>(V)) {
-        if (GO->getComdat() == reinterpret_cast<Comdat *>(1))
-          GO->setComdat(TheModule->getOrInsertComdat(V->getName()));
+        if (GO->getComdat() == reinterpret_cast<Comdat *>(1)) {
+          if (TT.isOSBinFormatMachO())
+            GO->setComdat(nullptr);
+          else
+            GO->setComdat(TheModule->getOrInsertComdat(V->getName()));
+        }
       }
       ValueName.clear();
       break;

Added: llvm/trunk/test/Bitcode/weak-macho-3.5.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/weak-macho-3.5.ll?rev=226546&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/weak-macho-3.5.ll (added)
+++ llvm/trunk/test/Bitcode/weak-macho-3.5.ll Mon Jan 19 23:58:07 2015
@@ -0,0 +1,11 @@
+; RUN:  llvm-dis < %s.bc| FileCheck %s
+
+; weak-macho-3.5.ll.bc was generated by passing this file to llvm-as-3.5
+; The test checks that LLVM does not place weak GlobalVariables into Comdats for
+; macho object files, they don't support it.
+
+target triple = "x86_64-apple-macosx10.9.0"
+; CHECK: target triple = "x86_64-apple-macosx10.9.0"
+
+ at x = weak global i32 0
+; CHECK: @x = weak global i32 0{{$}}

Added: llvm/trunk/test/Bitcode/weak-macho-3.5.ll.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/weak-macho-3.5.ll.bc?rev=226546&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/weak-macho-3.5.ll.bc (added) and llvm/trunk/test/Bitcode/weak-macho-3.5.ll.bc Mon Jan 19 23:58:07 2015 differ





More information about the llvm-commits mailing list