mirror of
https://github.com/RPCS3/llvm.git
synced 2026-01-31 01:25:19 +01:00
Strip invalid TBAA when reading bitcode
This ensures backward compatibility on bitcode loading. Differential Revision: https://reviews.llvm.org/D27839 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289977 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include "llvm/IR/GlobalVariable.h"
|
||||
#include "llvm/IR/GVMaterializer.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/InstIterator.h"
|
||||
#include "llvm/IR/InstrTypes.h"
|
||||
#include "llvm/IR/Instruction.h"
|
||||
#include "llvm/IR/Instructions.h"
|
||||
@@ -60,6 +61,7 @@
|
||||
#include "llvm/IR/TrackingMDRef.h"
|
||||
#include "llvm/IR/Type.h"
|
||||
#include "llvm/IR/ValueHandle.h"
|
||||
#include "llvm/IR/Verifier.h"
|
||||
#include "llvm/Support/AtomicOrdering.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
@@ -148,6 +150,16 @@ static bool convertToString(ArrayRef<uint64_t> Record, unsigned Idx,
|
||||
return false;
|
||||
}
|
||||
|
||||
// Strip all the TBAA attachment for the module.
|
||||
void stripTBAA(Module *M) {
|
||||
for (auto &F : *M) {
|
||||
if (F.isMaterializable())
|
||||
continue;
|
||||
for (auto &I : instructions(F))
|
||||
I.setMetadata(LLVMContext::MD_tbaa, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
/// Read the "IDENTIFICATION_BLOCK_ID" block, do some basic enforcement on the
|
||||
/// "epoch" encoded in the bitcode, and return the producer name if any.
|
||||
Expected<std::string> readIdentificationBlock(BitstreamCursor &Stream) {
|
||||
@@ -460,6 +472,7 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
|
||||
bool WillMaterializeAllForwardRefs = false;
|
||||
|
||||
bool StripDebugInfo = false;
|
||||
TBAAVerifier TBAAVerifyHelper;
|
||||
|
||||
std::vector<std::string> BundleTags;
|
||||
|
||||
@@ -4449,6 +4462,17 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
|
||||
if (DISubprogram *SP = MDLoader->lookupSubprogramForFunction(F))
|
||||
F->setSubprogram(SP);
|
||||
|
||||
// Check if the TBAA Metadata are valid, otherwise we will need to strip them.
|
||||
if (!MDLoader->isStrippingTBAA()) {
|
||||
for (auto &I : instructions(F)) {
|
||||
MDNode *TBAA = I.getMetadata(LLVMContext::MD_tbaa);
|
||||
if (!TBAA || TBAAVerifyHelper.visitTBAAMetadata(I, TBAA))
|
||||
continue;
|
||||
MDLoader->setStripTBAA(true);
|
||||
stripTBAA(F->getParent());
|
||||
}
|
||||
}
|
||||
|
||||
// Bring in any functions that this function forward-referenced via
|
||||
// blockaddresses.
|
||||
return materializeForwardReferencedFunctions();
|
||||
|
||||
Reference in New Issue
Block a user