[PATCH] D95329: [llvm-link] Fix crash when materializing appending global
Sergey Dmitriev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 25 18:18:32 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG13cedcaf4538: [llvm-link] Fix crash when materializing appending global (authored by sdmitriev).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95329/new/
https://reviews.llvm.org/D95329
Files:
llvm/lib/Transforms/Utils/ValueMapper.cpp
llvm/test/Linker/appending-global-crash.ll
Index: llvm/test/Linker/appending-global-crash.ll
===================================================================
--- /dev/null
+++ llvm/test/Linker/appending-global-crash.ll
@@ -0,0 +1,10 @@
+; RUN: llvm-link %s -S -o - | FileCheck %s
+
+; Check that llvm-link does not crash when materializing appending global with
+; initializer depending on another appending global.
+
+; CHECK-DAG: @use = appending global [1 x i8*] [i8* bitcast ([1 x i8*]* @var to i8*)]
+; CHECK-DAG: @var = appending global [1 x i8*] undef
+
+ at use = appending global [1 x i8*] [i8* bitcast ([1 x i8*]* @var to i8*)]
+ at var = appending global [1 x i8*] undef
Index: llvm/lib/Transforms/Utils/ValueMapper.cpp
===================================================================
--- llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -819,11 +819,15 @@
break;
case WorklistEntry::MapAppendingVar: {
unsigned PrefixSize = AppendingInits.size() - E.AppendingGVNumNewMembers;
+ // mapAppendingVariable call can change AppendingInits if initalizer for
+ // the variable depends on another appending global, because of that inits
+ // need to be extracted and updated before the call.
+ SmallVector<Constant *, 8> NewInits(
+ drop_begin(AppendingInits, PrefixSize));
+ AppendingInits.resize(PrefixSize);
mapAppendingVariable(*E.Data.AppendingGV.GV,
E.Data.AppendingGV.InitPrefix,
- E.AppendingGVIsOldCtorDtor,
- makeArrayRef(AppendingInits).slice(PrefixSize));
- AppendingInits.resize(PrefixSize);
+ E.AppendingGVIsOldCtorDtor, makeArrayRef(NewInits));
break;
}
case WorklistEntry::MapGlobalIndirectSymbol:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95329.319182.patch
Type: text/x-patch
Size: 1804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210126/c72e0998/attachment.bin>
More information about the llvm-commits
mailing list