Index: llvm/trunk/include/llvm/ADT/DenseMap.h =================================================================== --- llvm/trunk/include/llvm/ADT/DenseMap.h +++ llvm/trunk/include/llvm/ADT/DenseMap.h @@ -19,20 +19,20 @@ #include "llvm/Support/AlignOf.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm/Support/type_traits.h" #include #include -#include #include #include #include +#include #include #include namespace llvm { namespace detail { + // We extend a pair to allow users to override the bucket type with their own // implementation without requiring two members. template @@ -42,7 +42,8 @@ ValueT &getSecond() { return std::pair::second; } const ValueT &getSecond() const { return std::pair::second; } }; -} + +} // end namespace detail template < typename KeyT, typename ValueT, typename KeyInfoT = DenseMapInfo, @@ -239,7 +240,6 @@ insert(*I); } - bool erase(const KeyT &Val) { BucketT *TheBucket; if (!LookupBucketFor(Val, TheBucket)) @@ -528,7 +528,7 @@ unsigned BucketNo = getHashValue(Val) & (NumBuckets-1); unsigned ProbeAmt = 1; - while (1) { + while (true) { const BucketT *ThisBucket = BucketsPtr + BucketNo; // Found Val's bucket? If so, return it. if (LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) { @@ -966,7 +966,8 @@ return NumEntries; } void setNumEntries(unsigned Num) { - assert(Num < INT_MAX && "Cannot support more than INT_MAX entries"); + assert(Num < std::numeric_limits::max() && + "Cannot support more than std::numeric_limits::max() entries"); NumEntries = Num; } @@ -1040,8 +1041,10 @@ typedef value_type *pointer; typedef value_type &reference; typedef std::forward_iterator_tag iterator_category; + private: pointer Ptr, End; + public: DenseMapIterator() : Ptr(nullptr), End(nullptr) {} @@ -1115,4 +1118,4 @@ } // end namespace llvm -#endif +#endif // LLVM_ADT_DENSEMAP_H Index: llvm/trunk/include/llvm/ADT/Statistic.h =================================================================== --- llvm/trunk/include/llvm/ADT/Statistic.h +++ llvm/trunk/include/llvm/ADT/Statistic.h @@ -32,6 +32,7 @@ #include namespace llvm { + class raw_ostream; class raw_fd_ostream; @@ -140,13 +141,14 @@ TsanHappensAfter(this); return *this; } + void RegisterStatistic(); }; // STATISTIC - A macro to make definition of statistics really simple. This // automatically passes the DEBUG_TYPE of the file into the statistic. #define STATISTIC(VARNAME, DESC) \ - static llvm::Statistic VARNAME = {DEBUG_TYPE, #VARNAME, DESC, {0}, 0} + static llvm::Statistic VARNAME = {DEBUG_TYPE, #VARNAME, DESC, {0}, false} /// \brief Enable the collection and printing of statistics. void EnableStatistics(); @@ -166,6 +168,6 @@ /// Print statistics in JSON format. void PrintStatisticsJSON(raw_ostream &OS); -} // end llvm namespace +} // end namespace llvm #endif // LLVM_ADT_STATISTIC_H Index: llvm/trunk/include/llvm/Support/AtomicOrdering.h =================================================================== --- llvm/trunk/include/llvm/Support/AtomicOrdering.h +++ llvm/trunk/include/llvm/Support/AtomicOrdering.h @@ -73,8 +73,8 @@ // Validate an integral value which isn't known to fit within the enum's range // is a valid AtomicOrdering. template static inline bool isValidAtomicOrdering(Int I) { - return (Int)AtomicOrdering::NotAtomic <= I && - I <= (Int)AtomicOrdering::SequentiallyConsistent; + return static_cast(AtomicOrdering::NotAtomic) <= I && + I <= static_cast(AtomicOrdering::SequentiallyConsistent); } /// String used by LLVM IR to represent atomic ordering. @@ -82,40 +82,40 @@ static const char *names[8] = {"not_atomic", "unordered", "monotonic", "consume", "acquire", "release", "acq_rel", "seq_cst"}; - return names[(size_t)ao]; + return names[static_cast(ao)]; } /// Returns true if ao is stronger than other as defined by the AtomicOrdering /// lattice, which is based on C++'s definition. static inline bool isStrongerThan(AtomicOrdering ao, AtomicOrdering other) { static const bool lookup[8][8] = { - // NA UN RX CO AC RE AR SC - /* NotAtomic */ {0, 0, 0, 0, 0, 0, 0, 0}, - /* Unordered */ {1, 0, 0, 0, 0, 0, 0, 0}, - /* relaxed */ {1, 1, 0, 0, 0, 0, 0, 0}, - /* consume */ {1, 1, 1, 0, 0, 0, 0, 0}, - /* acquire */ {1, 1, 1, 1, 0, 0, 0, 0}, - /* release */ {1, 1, 1, 0, 0, 0, 0, 0}, - /* acq_rel */ {1, 1, 1, 1, 1, 1, 0, 0}, - /* seq_cst */ {1, 1, 1, 1, 1, 1, 1, 0}, + // NA UN RX CO AC RE AR SC + /* NotAtomic */ {false, false, false, false, false, false, false, false}, + /* Unordered */ { true, false, false, false, false, false, false, false}, + /* relaxed */ { true, true, false, false, false, false, false, false}, + /* consume */ { true, true, true, false, false, false, false, false}, + /* acquire */ { true, true, true, true, false, false, false, false}, + /* release */ { true, true, true, false, false, false, false, false}, + /* acq_rel */ { true, true, true, true, true, true, false, false}, + /* seq_cst */ { true, true, true, true, true, true, true, false}, }; - return lookup[(size_t)ao][(size_t)other]; + return lookup[static_cast(ao)][static_cast(other)]; } static inline bool isAtLeastOrStrongerThan(AtomicOrdering ao, AtomicOrdering other) { static const bool lookup[8][8] = { - // NA UN RX CO AC RE AR SC - /* NotAtomic */ {1, 0, 0, 0, 0, 0, 0, 0}, - /* Unordered */ {1, 1, 0, 0, 0, 0, 0, 0}, - /* relaxed */ {1, 1, 1, 0, 0, 0, 0, 0}, - /* consume */ {1, 1, 1, 1, 0, 0, 0, 0}, - /* acquire */ {1, 1, 1, 1, 1, 0, 0, 0}, - /* release */ {1, 1, 1, 0, 0, 1, 0, 0}, - /* acq_rel */ {1, 1, 1, 1, 1, 1, 1, 0}, - /* seq_cst */ {1, 1, 1, 1, 1, 1, 1, 1}, + // NA UN RX CO AC RE AR SC + /* NotAtomic */ { true, false, false, false, false, false, false, false}, + /* Unordered */ { true, true, false, false, false, false, false, false}, + /* relaxed */ { true, true, true, false, false, false, false, false}, + /* consume */ { true, true, true, true, false, false, false, false}, + /* acquire */ { true, true, true, true, true, false, false, false}, + /* release */ { true, true, true, false, false, true, false, false}, + /* acq_rel */ { true, true, true, true, true, true, true, false}, + /* seq_cst */ { true, true, true, true, true, true, true, true}, }; - return lookup[(size_t)ao][(size_t)other]; + return lookup[static_cast(ao)][static_cast(other)]; } static inline bool isStrongerThanUnordered(AtomicOrdering ao) { @@ -145,7 +145,7 @@ /* acq_rel */ AtomicOrderingCABI::acq_rel, /* seq_cst */ AtomicOrderingCABI::seq_cst, }; - return lookup[(size_t)ao]; + return lookup[static_cast(ao)]; } } // end namespace llvm Index: llvm/trunk/include/llvm/Support/Debug.h =================================================================== --- llvm/trunk/include/llvm/Support/Debug.h +++ llvm/trunk/include/llvm/Support/Debug.h @@ -29,6 +29,7 @@ #define LLVM_SUPPORT_DEBUG_H namespace llvm { + class raw_ostream; #ifndef NDEBUG @@ -61,12 +62,12 @@ /// is not specified, or is specified as "bitset". #define DEBUG_WITH_TYPE(TYPE, X) \ do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)) { X; } \ - } while (0) + } while (false) #else #define isCurrentDebugType(X) (false) #define setCurrentDebugType(X) -#define DEBUG_WITH_TYPE(TYPE, X) do { } while (0) +#define DEBUG_WITH_TYPE(TYPE, X) do { } while (false) #endif /// EnableDebugBuffering - This defaults to false. If true, the debug @@ -91,6 +92,6 @@ // #define DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X) -} // End llvm namespace +} // end namespace llvm -#endif +#endif // LLVM_SUPPORT_DEBUG_H Index: llvm/trunk/lib/Analysis/Lint.cpp =================================================================== --- llvm/trunk/lib/Analysis/Lint.cpp +++ llvm/trunk/lib/Analysis/Lint.cpp @@ -35,27 +35,48 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/Lint.h" -#include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/Twine.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/Loads.h" +#include "llvm/Analysis/MemoryLocation.h" #include "llvm/Analysis/Passes.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" +#include "llvm/IR/Argument.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/CallSite.h" +#include "llvm/IR/Constant.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" +#include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Module.h" #include "llvm/IR/InstVisitor.h" +#include "llvm/IR/InstrTypes.h" +#include "llvm/IR/Instruction.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LegacyPassManager.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Value.h" #include "llvm/Pass.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include + using namespace llvm; namespace { @@ -64,7 +85,7 @@ static const unsigned Write = 2; static const unsigned Callee = 4; static const unsigned Branchee = 8; - } + } // end namespace MemRef class Lint : public FunctionPass, public InstVisitor { friend class InstVisitor; @@ -159,7 +180,7 @@ WriteValues({V1, Vs...}); } }; -} +} // end anonymous namespace char Lint::ID = 0; INITIALIZE_PASS_BEGIN(Lint, "lint", "Statically lint-checks LLVM IR", @@ -173,7 +194,7 @@ // Assert - We know that cond should be true, if not print an error message. #define Assert(C, ...) \ - do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (0) + do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (false) // Lint::run - This is the main Analysis entry point for a // function. Index: llvm/trunk/lib/IR/Verifier.cpp =================================================================== --- llvm/trunk/lib/IR/Verifier.cpp +++ llvm/trunk/lib/IR/Verifier.cpp @@ -45,44 +45,80 @@ //===----------------------------------------------------------------------===// #include "llvm/IR/Verifier.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/APInt.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/ilist.h" #include "llvm/ADT/MapVector.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" +#include "llvm/IR/Argument.h" +#include "llvm/IR/Attributes.h" +#include "llvm/IR/BasicBlock.h" #include "llvm/IR/CFG.h" #include "llvm/IR/CallSite.h" #include "llvm/IR/CallingConv.h" +#include "llvm/IR/Comdat.h" +#include "llvm/IR/Constant.h" #include "llvm/IR/ConstantRange.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DebugInfo.h" +#include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DebugLoc.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Dominators.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalAlias.h" +#include "llvm/IR/GlobalValue.h" +#include "llvm/IR/GlobalVariable.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" #include "llvm/IR/InstVisitor.h" #include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/IR/ModuleSlotTracker.h" #include "llvm/IR/PassManager.h" #include "llvm/IR/Statepoint.h" +#include "llvm/IR/Type.h" +#include "llvm/IR/Use.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Value.h" #include "llvm/Pass.h" +#include "llvm/Support/AtomicOrdering.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/Dwarf.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include -#include +#include +#include +#include +#include +#include + using namespace llvm; static cl::opt VerifyDebugInfo("verify-debug-info", cl::init(true)); namespace { + struct VerifierSupport { raw_ostream *OS; const Module &M; @@ -120,6 +156,7 @@ *OS << '\n'; } } + void Write(ImmutableCallSite CS) { Write(CS.getInstruction()); } @@ -458,17 +495,17 @@ /// declarations share the same calling convention. void verifyDeoptimizeCallingConvs(); }; -} // End anonymous namespace + +} // end anonymous namespace /// We know that cond should be true, if not print an error message. #define Assert(C, ...) \ - do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (0) + do { if (!(C)) { CheckFailed(__VA_ARGS__); return; } } while (false) /// We know that a debug info condition should be true, if not print /// an error message. #define AssertDI(C, ...) \ - do { if (!(C)) { DebugInfoCheckFailed(__VA_ARGS__); return; } } while (0) - + do { if (!(C)) { DebugInfoCheckFailed(__VA_ARGS__); return; } } while (false) void Verifier::visit(Instruction &I) { for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) @@ -928,7 +965,7 @@ for (Metadata *Op : N.getRetainedTypes()->operands()) { AssertDI(Op && (isa(Op) || (isa(Op) && - cast(Op)->isDefinition() == false)), + !cast(Op)->isDefinition())), "invalid retained type", &N, Op); } } @@ -2037,7 +2074,7 @@ if (F.getIntrinsicID() && F.getParent()->isMaterialized()) { const User *U; if (F.hasAddressTaken(&U)) - Assert(0, "Invalid user of intrinsic instruction!", U); + Assert(false, "Invalid user of intrinsic instruction!", U); } Assert(!F.hasDLLImportStorageClass() || @@ -2220,7 +2257,7 @@ /// a pass, if any exist, it's an error. /// void Verifier::visitUserOp1(Instruction &I) { - Assert(0, "User-defined operators should not live outside of a pass!", &I); + Assert(false, "User-defined operators should not live outside of a pass!", &I); } void Verifier::visitTruncInst(TruncInst &I) { @@ -3666,7 +3703,7 @@ // Check to make sure that only first-class-values are operands to // instructions. if (!I.getOperand(i)->getType()->isFirstClassType()) { - Assert(0, "Instruction operands must be first-class values!", &I); + Assert(false, "Instruction operands must be first-class values!", &I); } if (Function *F = dyn_cast(I.getOperand(i))) { @@ -4356,6 +4393,7 @@ } namespace { + struct VerifierLegacyPass : public FunctionPass { static char ID; @@ -4411,7 +4449,8 @@ AU.setPreservesAll(); } }; -} + +} // end anonymous namespace char VerifierLegacyPass::ID = 0; INITIALIZE_PASS(VerifierLegacyPass, "verify", "Module Verifier", false, false)