Skip to content

Commit

Permalink
Extract a TBAAVerifier out of the verifier (NFC)
Browse files Browse the repository at this point in the history
This is intended to be used (in a later patch) by the BitcodeReader
to detect invalid TBAA and drop them when loading bitcode, so that
we don't break client that have legacy bitcode with possible invalid
TBAA.

Differential Revision: https://reviews.llvm.org/D27838

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289927 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
joker-eph committed Dec 16, 2016
1 parent bd86de4 commit 5d882e8
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 268 deletions.
39 changes: 39 additions & 0 deletions include/llvm/IR/Verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

#include "llvm/IR/PassManager.h"

namespace {
struct VerifierSupport;
}

namespace llvm {

class Function;
Expand All @@ -31,6 +35,41 @@ class ModulePass;
class Module;
class raw_ostream;

/// Verify that the TBAA Metadatas are valid.
class TBAAVerifier {
VerifierSupport *Diagnostic = nullptr;

/// Helper to diagnose a failure
template <typename... Tys> void CheckFailed(Tys &&... Args);

/// Cache of TBAA base nodes that have already been visited. This cachce maps
/// a node that has been visited to a pair (IsInvalid, BitWidth) where
///
/// \c IsInvalid is true iff the node is invalid.
/// \c BitWidth, if non-zero, is the bitwidth of the integer used to denoting
/// the offset of the access. If zero, only a zero offset is allowed.
///
/// \c BitWidth has no meaning if \c IsInvalid is true.
typedef std::pair<bool, unsigned> TBAABaseNodeSummary;
DenseMap<MDNode *, TBAABaseNodeSummary> TBAABaseNodes;

/// \name Helper functions used by \c visitTBAAMetadata.
/// @{
MDNode *getFieldNodeFromTBAABaseNode(Instruction &I, MDNode *BaseNode,
APInt &Offset);
TBAAVerifier::TBAABaseNodeSummary verifyTBAABaseNode(Instruction &I,
MDNode *BaseNode);
TBAABaseNodeSummary verifyTBAABaseNodeImpl(Instruction &I, MDNode *BaseNode);
/// @}

public:
TBAAVerifier(VerifierSupport *Diagnostic = nullptr)
: Diagnostic(Diagnostic) {}
// Visit an instruction and return true if it is valid, return false it an
// invalid TBAA is attached.
bool visitTBAAMetadata(Instruction &I, MDNode *MD);
};

/// \brief Check a function for errors, useful for use when debugging a
/// pass.
///
Expand Down
Loading

0 comments on commit 5d882e8

Please sign in to comment.