[C++11] Replace some comparisons with 'nullptr' with simple boolean checks to reduce verbosity.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205829 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper 2014-04-09 04:20:00 +00:00
parent e4d89ec8de
commit 725011e72f
19 changed files with 41 additions and 43 deletions

View File

@ -179,7 +179,7 @@ public:
typedef T* (IntrusiveRefCntPtr::*unspecified_bool_type) () const; typedef T* (IntrusiveRefCntPtr::*unspecified_bool_type) () const;
operator unspecified_bool_type() const { operator unspecified_bool_type() const {
return Obj == nullptr ? nullptr : &IntrusiveRefCntPtr::getPtr; return Obj ? &IntrusiveRefCntPtr::getPtr : nullptr;
} }
void swap(IntrusiveRefCntPtr& other) { void swap(IntrusiveRefCntPtr& other) {

View File

@ -186,7 +186,7 @@ namespace llvm {
/// str - Get the contents as an std::string. /// str - Get the contents as an std::string.
std::string str() const { std::string str() const {
if (Data == nullptr) return std::string(); if (!Data) return std::string();
return std::string(Data, Length); return std::string(Data, Length);
} }

View File

@ -383,7 +383,7 @@ public:
// Miscellaneous inspection routines. // Miscellaneous inspection routines.
size_type max_size() const { return size_type(-1); } size_type max_size() const { return size_type(-1); }
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {
return Head == nullptr || Head == getTail(); return !Head || Head == getTail();
} }
// Front and back accessor functions... // Front and back accessor functions...

View File

@ -336,7 +336,7 @@ namespace PBQP {
/// each node in the graph, and handleAddEdge for each edge, to give the /// each node in the graph, and handleAddEdge for each edge, to give the
/// solver an opportunity to set up any requried metadata. /// solver an opportunity to set up any requried metadata.
void setSolver(SolverT &S) { void setSolver(SolverT &S) {
assert(Solver == nullptr && "Solver already set. Call unsetSolver()."); assert(!Solver && "Solver already set. Call unsetSolver().");
Solver = &S; Solver = &S;
for (auto NId : nodeIds()) for (auto NId : nodeIds())
Solver->handleAddNode(NId); Solver->handleAddNode(NId);
@ -346,7 +346,7 @@ namespace PBQP {
/// \brief Release from solver instance. /// \brief Release from solver instance.
void unsetSolver() { void unsetSolver() {
assert(Solver != nullptr && "Solver not set."); assert(Solver && "Solver not set.");
Solver = nullptr; Solver = nullptr;
} }

View File

@ -1664,7 +1664,7 @@ class alias : public Option {
void done() { void done() {
if (!hasArgStr()) if (!hasArgStr())
error("cl::alias must have argument name specified!"); error("cl::alias must have argument name specified!");
if (AliasFor == nullptr) if (!AliasFor)
error("cl::alias must have an cl::aliasopt(option) specified!"); error("cl::alias must have an cl::aliasopt(option) specified!");
addArgument(); addArgument();
} }

View File

@ -828,9 +828,9 @@ public:
bool operator==(const directory_iterator &RHS) const { bool operator==(const directory_iterator &RHS) const {
if (State == RHS.State) if (State == RHS.State)
return true; return true;
if (RHS.State == nullptr) if (!RHS.State)
return State->CurrentEntry == directory_entry(); return State->CurrentEntry == directory_entry();
if (State == nullptr) if (!State)
return RHS.State->CurrentEntry == directory_entry(); return RHS.State->CurrentEntry == directory_entry();
return State->CurrentEntry == RHS.State->CurrentEntry; return State->CurrentEntry == RHS.State->CurrentEntry;
} }

View File

@ -305,7 +305,7 @@ public:
assert(Base && "Attempted to advance iterator past end!"); assert(Base && "Attempted to advance iterator past end!");
Base->increment(); Base->increment();
// Create an end iterator. // Create an end iterator.
if (Base->CurrentEntry == nullptr) if (!Base->CurrentEntry)
Base = nullptr; Base = nullptr;
return *this; return *this;
} }

View File

@ -39,7 +39,7 @@ void MallocSlabAllocator::Deallocate(MemSlab *Slab) {
void BumpPtrAllocatorBase::PrintStats() const { void BumpPtrAllocatorBase::PrintStats() const {
unsigned NumSlabs = 0; unsigned NumSlabs = 0;
size_t TotalMemory = 0; size_t TotalMemory = 0;
for (MemSlab *Slab = CurSlab; Slab != nullptr; Slab = Slab->NextPtr) { for (MemSlab *Slab = CurSlab; Slab; Slab = Slab->NextPtr) {
TotalMemory += Slab->Size; TotalMemory += Slab->Size;
++NumSlabs; ++NumSlabs;
} }
@ -53,7 +53,7 @@ void BumpPtrAllocatorBase::PrintStats() const {
size_t BumpPtrAllocatorBase::getTotalMemory() const { size_t BumpPtrAllocatorBase::getTotalMemory() const {
size_t TotalMemory = 0; size_t TotalMemory = 0;
for (MemSlab *Slab = CurSlab; Slab != nullptr; Slab = Slab->NextPtr) { for (MemSlab *Slab = CurSlab; Slab; Slab = Slab->NextPtr) {
TotalMemory += Slab->Size; TotalMemory += Slab->Size;
} }
return TotalMemory; return TotalMemory;

View File

@ -300,7 +300,7 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName,
// Enforce value requirements // Enforce value requirements
switch (Handler->getValueExpectedFlag()) { switch (Handler->getValueExpectedFlag()) {
case ValueRequired: case ValueRequired:
if (Value.data() == nullptr) { // No value specified? if (!Value.data()) { // No value specified?
if (i+1 >= argc) if (i+1 >= argc)
return Handler->error("requires a value!"); return Handler->error("requires a value!");
// Steal the next argument, like for '-o filename' // Steal the next argument, like for '-o filename'
@ -400,7 +400,7 @@ static Option *HandlePrefixedOrGroupedOption(StringRef &Arg, StringRef &Value,
// Do the lookup! // Do the lookup!
size_t Length = 0; size_t Length = 0;
Option *PGOpt = getOptionPred(Arg, Length, isPrefixedOrGrouping, OptionsMap); Option *PGOpt = getOptionPred(Arg, Length, isPrefixedOrGrouping, OptionsMap);
if (PGOpt == nullptr) return nullptr; if (!PGOpt) return nullptr;
// If the option is a prefixed option, then the value is simply the // If the option is a prefixed option, then the value is simply the
// rest of the name... so fall through to later processing, by // rest of the name... so fall through to later processing, by
@ -770,7 +770,7 @@ void cl::ParseCommandLineOptions(int argc, const char * const *argv,
// Calculate how many positional values are _required_. // Calculate how many positional values are _required_.
bool UnboundedFound = false; bool UnboundedFound = false;
for (size_t i = ConsumeAfterOpt != nullptr, e = PositionalOpts.size(); for (size_t i = ConsumeAfterOpt ? 1 : 0, e = PositionalOpts.size();
i != e; ++i) { i != e; ++i) {
Option *Opt = PositionalOpts[i]; Option *Opt = PositionalOpts[i];
if (RequiresValue(Opt)) if (RequiresValue(Opt))
@ -845,8 +845,7 @@ void cl::ParseCommandLineOptions(int argc, const char * const *argv,
// All of the positional arguments have been fulfulled, give the rest to // All of the positional arguments have been fulfulled, give the rest to
// the consume after option... if it's specified... // the consume after option... if it's specified...
// //
if (PositionalVals.size() >= NumPositionalRequired && if (PositionalVals.size() >= NumPositionalRequired && ConsumeAfterOpt) {
ConsumeAfterOpt != nullptr) {
for (++i; i < argc; ++i) for (++i; i < argc; ++i)
PositionalVals.push_back(std::make_pair(argv[i],i)); PositionalVals.push_back(std::make_pair(argv[i],i));
break; // Handle outside of the argument processing loop... break; // Handle outside of the argument processing loop...
@ -884,18 +883,18 @@ void cl::ParseCommandLineOptions(int argc, const char * const *argv,
Handler = LookupOption(ArgName, Value, Opts); Handler = LookupOption(ArgName, Value, Opts);
// Check to see if this "option" is really a prefixed or grouped argument. // Check to see if this "option" is really a prefixed or grouped argument.
if (Handler == nullptr) if (!Handler)
Handler = HandlePrefixedOrGroupedOption(ArgName, Value, Handler = HandlePrefixedOrGroupedOption(ArgName, Value,
ErrorParsing, Opts); ErrorParsing, Opts);
// Otherwise, look for the closest available option to report to the user // Otherwise, look for the closest available option to report to the user
// in the upcoming error. // in the upcoming error.
if (Handler == nullptr && SinkOpts.empty()) if (!Handler && SinkOpts.empty())
NearestHandler = LookupNearestOption(ArgName, Opts, NearestHandler = LookupNearestOption(ArgName, Opts,
NearestHandlerString); NearestHandlerString);
} }
if (Handler == nullptr) { if (!Handler) {
if (SinkOpts.empty()) { if (SinkOpts.empty()) {
errs() << ProgramName << ": Unknown command line argument '" errs() << ProgramName << ": Unknown command line argument '"
<< argv[i] << "'. Try: '" << argv[0] << " -help'\n"; << argv[i] << "'. Try: '" << argv[0] << " -help'\n";
@ -939,7 +938,7 @@ void cl::ParseCommandLineOptions(int argc, const char * const *argv,
<< " positional arguments: See: " << argv[0] << " -help\n"; << " positional arguments: See: " << argv[0] << " -help\n";
ErrorParsing = true; ErrorParsing = true;
} else if (ConsumeAfterOpt == nullptr) { } else if (!ConsumeAfterOpt) {
// Positional args have already been handled if ConsumeAfter is specified. // Positional args have already been handled if ConsumeAfter is specified.
unsigned ValNo = 0, NumVals = static_cast<unsigned>(PositionalVals.size()); unsigned ValNo = 0, NumVals = static_cast<unsigned>(PositionalVals.size());
for (size_t i = 0, e = PositionalOpts.size(); i != e; ++i) { for (size_t i = 0, e = PositionalOpts.size(); i != e; ++i) {
@ -1044,7 +1043,7 @@ void cl::ParseCommandLineOptions(int argc, const char * const *argv,
// //
bool Option::error(const Twine &Message, StringRef ArgName) { bool Option::error(const Twine &Message, StringRef ArgName) {
if (ArgName.data() == nullptr) ArgName = ArgStr; if (!ArgName.data()) ArgName = ArgStr;
if (ArgName.empty()) if (ArgName.empty())
errs() << HelpStr; // Be nice for positional arguments errs() << HelpStr; // Be nice for positional arguments
else else
@ -1779,7 +1778,7 @@ void cl::SetVersionPrinter(void (*func)()) {
} }
void cl::AddExtraVersionPrinter(void (*func)()) { void cl::AddExtraVersionPrinter(void (*func)()) {
if (ExtraVersionPrinters == nullptr) if (!ExtraVersionPrinters)
ExtraVersionPrinters = new std::vector<void (*)()>; ExtraVersionPrinters = new std::vector<void (*)()>;
ExtraVersionPrinters->push_back(func); ExtraVersionPrinters->push_back(func);

View File

@ -58,7 +58,7 @@ DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename,
SmartScopedLock<true> lock(*SymbolsMutex); SmartScopedLock<true> lock(*SymbolsMutex);
void *handle = dlopen(filename, RTLD_LAZY|RTLD_GLOBAL); void *handle = dlopen(filename, RTLD_LAZY|RTLD_GLOBAL);
if (handle == nullptr) { if (!handle) {
if (errMsg) *errMsg = dlerror(); if (errMsg) *errMsg = dlerror();
return DynamicLibrary(); return DynamicLibrary();
} }
@ -66,11 +66,11 @@ DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename,
#ifdef __CYGWIN__ #ifdef __CYGWIN__
// Cygwin searches symbols only in the main // Cygwin searches symbols only in the main
// with the handle of dlopen(NULL, RTLD_GLOBAL). // with the handle of dlopen(NULL, RTLD_GLOBAL).
if (filename == NULL) if (!filename)
handle = RTLD_DEFAULT; handle = RTLD_DEFAULT;
#endif #endif
if (OpenedHandles == nullptr) if (!OpenedHandles)
OpenedHandles = new DenseSet<void *>(); OpenedHandles = new DenseSet<void *>();
// If we've already loaded this library, dlclose() the handle in order to // If we've already loaded this library, dlclose() the handle in order to

View File

@ -323,7 +323,7 @@ void FoldingSetImpl::InsertNode(Node *N, void *InsertPos) {
// If this is the first insertion into this bucket, its next pointer will be // If this is the first insertion into this bucket, its next pointer will be
// null. Pretend as if it pointed to itself, setting the low bit to indicate // null. Pretend as if it pointed to itself, setting the low bit to indicate
// that it is a pointer to the bucket. // that it is a pointer to the bucket.
if (Next == nullptr) if (!Next)
Next = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(Bucket)|1); Next = reinterpret_cast<void*>(reinterpret_cast<intptr_t>(Bucket)|1);
// Set the node's next pointer, and make the bucket point to the node. // Set the node's next pointer, and make the bucket point to the node.
@ -337,7 +337,7 @@ bool FoldingSetImpl::RemoveNode(Node *N) {
// Because each bucket is a circular list, we don't need to compute N's hash // Because each bucket is a circular list, we don't need to compute N's hash
// to remove it. // to remove it.
void *Ptr = N->getNextInBucket(); void *Ptr = N->getNextInBucket();
if (Ptr == nullptr) return false; // Not in folding set. if (!Ptr) return false; // Not in folding set.
--NumNodes; --NumNodes;
N->SetNextInBucket(nullptr); N->SetNextInBucket(nullptr);
@ -390,7 +390,7 @@ FoldingSetImpl::Node *FoldingSetImpl::GetOrInsertNode(FoldingSetImpl::Node *N) {
FoldingSetIteratorImpl::FoldingSetIteratorImpl(void **Bucket) { FoldingSetIteratorImpl::FoldingSetIteratorImpl(void **Bucket) {
// Skip to the first non-null non-self-cycle bucket. // Skip to the first non-null non-self-cycle bucket.
while (*Bucket != reinterpret_cast<void*>(-1) && while (*Bucket != reinterpret_cast<void*>(-1) &&
(*Bucket == nullptr || GetNextPtr(*Bucket) == nullptr)) (!*Bucket || !GetNextPtr(*Bucket)))
++Bucket; ++Bucket;
NodePtr = static_cast<FoldingSetNode*>(*Bucket); NodePtr = static_cast<FoldingSetNode*>(*Bucket);
@ -410,7 +410,7 @@ void FoldingSetIteratorImpl::advance() {
do { do {
++Bucket; ++Bucket;
} while (*Bucket != reinterpret_cast<void*>(-1) && } while (*Bucket != reinterpret_cast<void*>(-1) &&
(*Bucket == nullptr || GetNextPtr(*Bucket) == nullptr)); (!*Bucket || !GetNextPtr(*Bucket)));
NodePtr = static_cast<FoldingSetNode*>(*Bucket); NodePtr = static_cast<FoldingSetNode*>(*Bucket);
} }
@ -420,6 +420,5 @@ void FoldingSetIteratorImpl::advance() {
// FoldingSetBucketIteratorImpl Implementation // FoldingSetBucketIteratorImpl Implementation
FoldingSetBucketIteratorImpl::FoldingSetBucketIteratorImpl(void **Bucket) { FoldingSetBucketIteratorImpl::FoldingSetBucketIteratorImpl(void **Bucket) {
Ptr = (*Bucket == nullptr || GetNextPtr(*Bucket) == nullptr) ? (void*) Bucket Ptr = (!*Bucket || !GetNextPtr(*Bucket)) ? (void*) Bucket : *Bucket;
: *Bucket;
} }

View File

@ -24,7 +24,7 @@ void ManagedStaticBase::RegisterManagedStatic(void *(*Creator)(),
if (llvm_is_multithreaded()) { if (llvm_is_multithreaded()) {
llvm_acquire_global_lock(); llvm_acquire_global_lock();
if (Ptr == nullptr) { if (!Ptr) {
void* tmp = Creator ? Creator() : nullptr; void* tmp = Creator ? Creator() : nullptr;
TsanHappensBefore(this); TsanHappensBefore(this);

View File

@ -46,7 +46,7 @@ static unsigned PrintStack(const PrettyStackTraceEntry *Entry, raw_ostream &OS){
/// PrintCurStackTrace - Print the current stack trace to the specified stream. /// PrintCurStackTrace - Print the current stack trace to the specified stream.
static void PrintCurStackTrace(raw_ostream &OS) { static void PrintCurStackTrace(raw_ostream &OS) {
// Don't print an empty trace. // Don't print an empty trace.
if (PrettyStackTraceHead->get() == nullptr) return; if (!PrettyStackTraceHead->get()) return;
// If there are pretty stack frames registered, walk and emit them. // If there are pretty stack frames registered, walk and emit them.
OS << "Stack dump:\n"; OS << "Stack dump:\n";

View File

@ -114,7 +114,7 @@ SourceMgr::getLineAndColumn(SMLoc Loc, int BufferID) const {
if (*Ptr == '\n') ++LineNo; if (*Ptr == '\n') ++LineNo;
// Allocate the line number cache if it doesn't exist. // Allocate the line number cache if it doesn't exist.
if (LineNoCache == nullptr) if (!LineNoCache)
LineNoCache = new LineNoCacheTy(); LineNoCache = new LineNoCacheTy();
// Update the line # cache. // Update the line # cache.

View File

@ -70,7 +70,7 @@ unsigned StringMapImpl::LookupBucketFor(StringRef Name) {
while (1) { while (1) {
StringMapEntryBase *BucketItem = TheTable[BucketNo]; StringMapEntryBase *BucketItem = TheTable[BucketNo];
// If we found an empty bucket, this key isn't in the table yet, return it. // If we found an empty bucket, this key isn't in the table yet, return it.
if (LLVM_LIKELY(BucketItem == nullptr)) { if (LLVM_LIKELY(!BucketItem)) {
// If we found a tombstone, we want to reuse the tombstone instead of an // If we found a tombstone, we want to reuse the tombstone instead of an
// empty bucket. This reduces probing. // empty bucket. This reduces probing.
if (FirstTombstone != -1) { if (FirstTombstone != -1) {
@ -124,7 +124,7 @@ int StringMapImpl::FindKey(StringRef Key) const {
while (1) { while (1) {
StringMapEntryBase *BucketItem = TheTable[BucketNo]; StringMapEntryBase *BucketItem = TheTable[BucketNo];
// If we found an empty bucket, this key isn't in the table yet, return. // If we found an empty bucket, this key isn't in the table yet, return.
if (LLVM_LIKELY(BucketItem == nullptr)) if (LLVM_LIKELY(!BucketItem))
return -1; return -1;
if (BucketItem == getTombstoneVal()) { if (BucketItem == getTombstoneVal()) {
@ -212,7 +212,7 @@ void StringMapImpl::RehashTable() {
// Fast case, bucket available. // Fast case, bucket available.
unsigned FullHash = HashTable[I]; unsigned FullHash = HashTable[I];
unsigned NewBucket = FullHash & (NewSize-1); unsigned NewBucket = FullHash & (NewSize-1);
if (NewTableArray[NewBucket] == nullptr) { if (!NewTableArray[NewBucket]) {
NewTableArray[FullHash & (NewSize-1)] = Bucket; NewTableArray[FullHash & (NewSize-1)] = Bucket;
NewHashArray[FullHash & (NewSize-1)] = FullHash; NewHashArray[FullHash & (NewSize-1)] = FullHash;
continue; continue;

View File

@ -53,7 +53,7 @@ const Target *TargetRegistry::lookupTarget(const std::string &ArchName,
// Get the target specific parser. // Get the target specific parser.
std::string TempError; std::string TempError;
TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), TempError); TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), TempError);
if (TheTarget == nullptr) { if (!TheTarget) {
Error = ": error: unable to get target for '" Error = ": error: unable to get target for '"
+ TheTriple.getTriple() + TheTriple.getTriple()
+ "', see --version and --triple.\n"; + "', see --version and --triple.\n";

View File

@ -264,7 +264,7 @@ TimerGroup::TimerGroup(StringRef name)
TimerGroup::~TimerGroup() { TimerGroup::~TimerGroup() {
// If the timer group is destroyed before the timers it owns, accumulate and // If the timer group is destroyed before the timers it owns, accumulate and
// print the timing data. // print the timing data.
while (FirstTimer != nullptr) while (FirstTimer)
removeTimer(*FirstTimer); removeTimer(*FirstTimer);
// Remove the group from the TimerGroupList. // Remove the group from the TimerGroupList.
@ -291,7 +291,7 @@ void TimerGroup::removeTimer(Timer &T) {
// Print the report when all timers in this group are destroyed if some of // Print the report when all timers in this group are destroyed if some of
// them were started. // them were started.
if (FirstTimer != nullptr || TimersToPrint.empty()) if (FirstTimer || TimersToPrint.empty())
return; return;
raw_ostream *OutStream = CreateInfoOutputFile(); raw_ostream *OutStream = CreateInfoOutputFile();

View File

@ -1941,7 +1941,7 @@ void SequenceNode::increment() {
case Token::TK_BlockEntry: case Token::TK_BlockEntry:
getNext(); getNext();
CurrentEntry = parseBlockNode(); CurrentEntry = parseBlockNode();
if (CurrentEntry == nullptr) { // An error occurred. if (!CurrentEntry) { // An error occurred.
IsAtEnd = true; IsAtEnd = true;
CurrentEntry = nullptr; CurrentEntry = nullptr;
} }
@ -1963,7 +1963,7 @@ void SequenceNode::increment() {
case Token::TK_BlockEntry: case Token::TK_BlockEntry:
getNext(); getNext();
CurrentEntry = parseBlockNode(); CurrentEntry = parseBlockNode();
if (CurrentEntry == nullptr) { // An error occurred. if (!CurrentEntry) { // An error occurred.
IsAtEnd = true; IsAtEnd = true;
CurrentEntry = nullptr; CurrentEntry = nullptr;
} }

View File

@ -111,7 +111,7 @@ static bool IsEliminableAddrSpaceCast(Operator *Cast) {
bool NVPTXFavorNonGenericAddrSpaces::hoistAddrSpaceCastFromGEP( bool NVPTXFavorNonGenericAddrSpaces::hoistAddrSpaceCastFromGEP(
GEPOperator *GEP) { GEPOperator *GEP) {
Operator *Cast = dyn_cast<Operator>(GEP->getPointerOperand()); Operator *Cast = dyn_cast<Operator>(GEP->getPointerOperand());
if (Cast == nullptr) if (!Cast)
return false; return false;
if (!IsEliminableAddrSpaceCast(Cast)) if (!IsEliminableAddrSpaceCast(Cast))