summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/GlobalSplit.cpp
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2017-03-07 22:18:48 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2017-03-07 22:18:48 +0000
commit7a5cfa9a11d6342e3a8254f8bcaa28bf40580c0b (patch)
tree0d79401784d8df1feaddf8c26011ac222b781e24 /llvm/lib/Transforms/IPO/GlobalSplit.cpp
parent1dc735bf64bfde087c0d004e8be14987af19c6dc (diff)
downloadbcm5719-llvm-7a5cfa9a11d6342e3a8254f8bcaa28bf40580c0b.tar.gz
bcm5719-llvm-7a5cfa9a11d6342e3a8254f8bcaa28bf40580c0b.zip
Fix one-after-the-end type metadata handling in globalsplit.
Itanium ABI may have an address point one byte after the end of a vtable. When such vtable global is split, the !type metadata needs to follow the right vtable. Differential Revision: https://reviews.llvm.org/D30716 llvm-svn: 297236
Diffstat (limited to 'llvm/lib/Transforms/IPO/GlobalSplit.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/GlobalSplit.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalSplit.cpp b/llvm/lib/Transforms/IPO/GlobalSplit.cpp
index bbbd096e89c..4705ebe265a 100644
--- a/llvm/lib/Transforms/IPO/GlobalSplit.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalSplit.cpp
@@ -85,7 +85,16 @@ bool splitGlobal(GlobalVariable &GV) {
uint64_t ByteOffset = cast<ConstantInt>(
cast<ConstantAsMetadata>(Type->getOperand(0))->getValue())
->getZExtValue();
- if (ByteOffset < SplitBegin || ByteOffset >= SplitEnd)
+ // Type metadata may be attached one byte after the end of the vtable, for
+ // classes without virtual methods in Itanium ABI. AFAIK, it is never
+ // attached to the first byte of a vtable. Subtract one to get the right
+ // slice.
+ // This is making an assumption that vtable groups are the only kinds of
+ // global variables that !type metadata can be attached to, and that they
+ // are either Itanium ABI vtable groups or contain a single vtable (i.e.
+ // Microsoft ABI vtables).
+ uint64_t AttachedTo = (ByteOffset == 0) ? ByteOffset : ByteOffset - 1;
+ if (AttachedTo < SplitBegin || AttachedTo >= SplitEnd)
continue;
SplitGV->addMetadata(
LLVMContext::MD_type,
OpenPOWER on IntegriCloud