[llvm] r254240 - Fix a crash when writing merged bitcode.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 28 19:21:30 PST 2015
Author: rafael
Date: Sat Nov 28 21:21:30 2015
New Revision: 254240
URL: http://llvm.org/viewvc/llvm-project?rev=254240&view=rev
Log:
Fix a crash when writing merged bitcode.
Playing with mutateType in here was making getValueType and getType
incompatible.
Modified:
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/test/Linker/ctors.ll
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=254240&r1=254239&r2=254240&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Sat Nov 28 21:21:30 2015
@@ -537,7 +537,7 @@ private:
bool linkGlobalValueProto(GlobalValue *GV);
bool linkModuleFlagsMetadata();
- void linkAppendingVarInit(const AppendingVarInfo &AVI);
+ void linkAppendingVarInit(AppendingVarInfo &AVI);
void linkGlobalInit(GlobalVariable &Dst, GlobalVariable &Src);
bool linkFunctionBody(Function &Dst, Function &Src);
@@ -1493,7 +1493,7 @@ static void getArrayElements(const Const
Dest.push_back(C->getAggregateElement(i));
}
-void ModuleLinker::linkAppendingVarInit(const AppendingVarInfo &AVI) {
+void ModuleLinker::linkAppendingVarInit(AppendingVarInfo &AVI) {
// Merge the initializer.
SmallVector<Constant *, 16> DstElements;
getArrayElements(AVI.DstInit, DstElements);
@@ -1517,9 +1517,18 @@ void ModuleLinker::linkAppendingVarInit(
DstElements.push_back(
MapValue(V, ValueMap, RF_MoveDistinctMDs, &TypeMap, &ValMaterializer));
}
- if (IsNewStructor) {
+ if (DstElements.size() != NewType->getNumElements()) {
NewType = ArrayType::get(NewType->getElementType(), DstElements.size());
- AVI.NewGV->mutateType(PointerType::get(NewType, 0));
+ GlobalVariable *Old = AVI.NewGV;
+ GlobalVariable *NG = new GlobalVariable(
+ *DstM, NewType, Old->isConstant(), Old->getLinkage(), /*init*/ nullptr,
+ /*name*/ "", Old, Old->getThreadLocalMode(),
+ Old->getType()->getAddressSpace());
+ copyGVAttributes(NG, Old);
+ AVI.NewGV->replaceAllUsesWith(
+ ConstantExpr::getBitCast(NG, AVI.NewGV->getType()));
+ AVI.NewGV->eraseFromParent();
+ AVI.NewGV = NG;
}
AVI.NewGV->setInitializer(ConstantArray::get(NewType, DstElements));
@@ -1909,7 +1918,7 @@ bool ModuleLinker::run() {
if (linkGlobalValueProto(&GA))
return true;
- for (const AppendingVarInfo &AppendingVar : AppendingVars)
+ for (AppendingVarInfo &AppendingVar : AppendingVars)
linkAppendingVarInit(AppendingVar);
for (const auto &Entry : DstM->getComdatSymbolTable()) {
Modified: llvm/trunk/test/Linker/ctors.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/ctors.ll?rev=254240&r1=254239&r2=254240&view=diff
==============================================================================
--- llvm/trunk/test/Linker/ctors.ll (original)
+++ llvm/trunk/test/Linker/ctors.ll Sat Nov 28 21:21:30 2015
@@ -3,6 +3,9 @@
; RUN: llvm-link %p/Inputs/ctors.ll %s -S -o - | \
; RUN: FileCheck --check-prefix=ALL --check-prefix=CHECK2 %s
+; Test the bitcode writer too. It used to crash.
+; RUN: llvm-link %s %p/Inputs/ctors.ll -o t.bc
+
@v = weak global i8 0
; CHECK1: @v = weak global i8 0
; CHECK2: @v = weak global i8 1
More information about the llvm-commits
mailing list