diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -44,6 +44,7 @@ //===----------------------------------------------------------------------===// #include "llvm/IR/Verifier.h" +#include "LLVMContextImpl.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" @@ -308,6 +309,8 @@ void checkAtomicMemAccessSize(Type *Ty, const Instruction *I); + using BlockAddressMapTy = decltype(LLVMContextImpl::BlockAddresses); + public: explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError, const Module &M) @@ -381,6 +384,8 @@ for (const StringMapEntry &SMEC : M.getComdatSymbolTable()) visitComdat(SMEC.getValue()); + verifyBlockAddressConstants(M.getContext().pImpl->BlockAddresses); + visitModuleFlags(M); visitModuleIdents(M); visitModuleCommandLines(M); @@ -525,6 +530,9 @@ /// Verify all-or-nothing property of DIFile source attribute within a CU. void verifySourceDebugInfo(const DICompileUnit &U, const DIFile &F); + + /// Verify all blockaddresses in \p CM have at least one user. + void verifyBlockAddressConstants(const BlockAddressMapTy &CM); }; } // end anonymous namespace @@ -4971,6 +4979,12 @@ "inconsistent use of embedded source"); } +void Verifier::verifyBlockAddressConstants(const BlockAddressMapTy &CM) { + for (auto &KV : CM) + Assert(!KV.second->use_empty(), "Blockaddress does not have any users", + KV.second); +} + //===----------------------------------------------------------------------===// // Implement the public interfaces to this file... //===----------------------------------------------------------------------===//