From: Craig Topper Date: Tue, 20 May 2014 04:30:07 +0000 (+0000) Subject: [C++11] Use 'nullptr'. Analysis edition. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fa361696b1ec1ab8ee0a6f25a61e1c1a529d1bc4;p=clang [C++11] Use 'nullptr'. Analysis edition. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209191 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/AnalysisDeclContext.cpp b/lib/Analysis/AnalysisDeclContext.cpp index fa4bd33fa1..90d4b13b88 100644 --- a/lib/Analysis/AnalysisDeclContext.cpp +++ b/lib/Analysis/AnalysisDeclContext.cpp @@ -41,11 +41,11 @@ AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr, : Manager(Mgr), D(d), cfgBuildOptions(buildOptions), - forcedBlkExprs(0), + forcedBlkExprs(nullptr), builtCFG(false), builtCompleteCFG(false), - ReferencedBlockVars(0), - ManagedAnalyses(0) + ReferencedBlockVars(nullptr), + ManagedAnalyses(nullptr) { cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs; } @@ -54,11 +54,11 @@ AnalysisDeclContext::AnalysisDeclContext(AnalysisDeclContextManager *Mgr, const Decl *d) : Manager(Mgr), D(d), - forcedBlkExprs(0), + forcedBlkExprs(nullptr), builtCFG(false), builtCompleteCFG(false), - ReferencedBlockVars(0), - ManagedAnalyses(0) + ReferencedBlockVars(nullptr), + ManagedAnalyses(nullptr) { cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs; } @@ -140,7 +140,7 @@ const ImplicitParamDecl *AnalysisDeclContext::getSelfDecl() const { } } - return NULL; + return nullptr; } void AnalysisDeclContext::registerForcedBlockExpression(const Stmt *stmt) { @@ -191,7 +191,7 @@ CFG *AnalysisDeclContext::getCFG() { addParentsForSyntheticStmts(cfg.get(), *PM); // The Observer should only observe one build of the CFG. - getCFGBuildOptions().Observer = 0; + getCFGBuildOptions().Observer = nullptr; } return cfg.get(); } @@ -210,7 +210,7 @@ CFG *AnalysisDeclContext::getUnoptimizedCFG() { addParentsForSyntheticStmts(completeCFG.get(), *PM); // The Observer should only observe one build of the CFG. - getCFGBuildOptions().Observer = 0; + getCFGBuildOptions().Observer = nullptr; } return completeCFG.get(); } @@ -223,8 +223,8 @@ CFGStmtMap *AnalysisDeclContext::getCFGStmtMap() { cfgStmtMap.reset(CFGStmtMap::Build(c, &getParentMap())); return cfgStmtMap.get(); } - - return 0; + + return nullptr; } CFGReverseBlockReachabilityAnalysis *AnalysisDeclContext::getCFGReachablityAnalysis() { @@ -235,8 +235,8 @@ CFGReverseBlockReachabilityAnalysis *AnalysisDeclContext::getCFGReachablityAnaly CFA.reset(new CFGReverseBlockReachabilityAnalysis(*c)); return CFA.get(); } - - return 0; + + return nullptr; } void AnalysisDeclContext::dumpCFG(bool ShowColors) { @@ -401,7 +401,7 @@ const StackFrameContext *LocationContext::getCurrentStackFrame() const { return SFC; LC = LC->getParent(); } - return NULL; + return nullptr; } bool LocationContext::inTopFrame() const { diff --git a/lib/Analysis/BodyFarm.cpp b/lib/Analysis/BodyFarm.cpp index 039911e3e2..316a18b421 100644 --- a/lib/Analysis/BodyFarm.cpp +++ b/lib/Analysis/BodyFarm.cpp @@ -128,20 +128,20 @@ UnaryOperator *ASTMaker::makeDereference(const Expr *Arg, QualType Ty) { ImplicitCastExpr *ASTMaker::makeLvalueToRvalue(const Expr *Arg, QualType Ty) { return ImplicitCastExpr::Create(C, Ty, CK_LValueToRValue, - const_cast(Arg), 0, VK_RValue); + const_cast(Arg), nullptr, VK_RValue); } Expr *ASTMaker::makeIntegralCast(const Expr *Arg, QualType Ty) { if (Arg->getType() == Ty) return const_cast(Arg); - + return ImplicitCastExpr::Create(C, Ty, CK_IntegralCast, - const_cast(Arg), 0, VK_RValue); + const_cast(Arg), nullptr, VK_RValue); } ImplicitCastExpr *ASTMaker::makeIntegralCastToBoolean(const Expr *Arg) { return ImplicitCastExpr::Create(C, C.BoolTy, CK_IntegralToBoolean, - const_cast(Arg), 0, VK_RValue); + const_cast(Arg), nullptr, VK_RValue); } ObjCBoolLiteralExpr *ASTMaker::makeObjCBool(bool Val) { @@ -159,7 +159,8 @@ ObjCIvarRefExpr *ASTMaker::makeObjCIvarRef(const Expr *Base, ReturnStmt *ASTMaker::makeReturn(const Expr *RetVal) { - return new (C) ReturnStmt(SourceLocation(), const_cast(RetVal), 0); + return new (C) ReturnStmt(SourceLocation(), const_cast(RetVal), + nullptr); } //===----------------------------------------------------------------------===// @@ -172,24 +173,24 @@ typedef Stmt *(*FunctionFarmer)(ASTContext &C, const FunctionDecl *D); static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) { // Check if we have at least two parameters. if (D->param_size() != 2) - return 0; + return nullptr; // Check if the first parameter is a pointer to integer type. const ParmVarDecl *Predicate = D->getParamDecl(0); QualType PredicateQPtrTy = Predicate->getType(); const PointerType *PredicatePtrTy = PredicateQPtrTy->getAs(); if (!PredicatePtrTy) - return 0; + return nullptr; QualType PredicateTy = PredicatePtrTy->getPointeeType(); if (!PredicateTy->isIntegerType()) - return 0; - + return nullptr; + // Check if the second parameter is the proper block type. const ParmVarDecl *Block = D->getParamDecl(1); QualType Ty = Block->getType(); if (!isDispatchBlock(Ty)) - return 0; - + return nullptr; + // Everything checks out. Create a fakse body that checks the predicate, // sets it, and calls the block. Basically, an AST dump of: // @@ -242,7 +243,7 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) { SourceLocation()); // (5) Create the 'if' statement. - IfStmt *If = new (C) IfStmt(C, SourceLocation(), 0, UO, CS); + IfStmt *If = new (C) IfStmt(C, SourceLocation(), nullptr, UO, CS); return If; } @@ -250,14 +251,14 @@ static Stmt *create_dispatch_once(ASTContext &C, const FunctionDecl *D) { static Stmt *create_dispatch_sync(ASTContext &C, const FunctionDecl *D) { // Check if we have at least two parameters. if (D->param_size() != 2) - return 0; - + return nullptr; + // Check if the second parameter is a block. const ParmVarDecl *PV = D->getParamDecl(1); QualType Ty = PV->getType(); if (!isDispatchBlock(Ty)) - return 0; - + return nullptr; + // Everything checks out. Create a fake body that just calls the block. // This is basically just an AST dump of: // @@ -277,8 +278,8 @@ static Stmt *create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D) { // There are exactly 3 arguments. if (D->param_size() != 3) - return 0; - + return nullptr; + // Signature: // _Bool OSAtomicCompareAndSwapPtr(void *__oldValue, // void *__newValue, @@ -293,8 +294,8 @@ static Stmt *create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D) QualType ResultTy = D->getReturnType(); bool isBoolean = ResultTy->isBooleanType(); if (!isBoolean && !ResultTy->isIntegralType(C)) - return 0; - + return nullptr; + const ParmVarDecl *OldValue = D->getParamDecl(0); QualType OldValueTy = OldValue->getType(); @@ -307,7 +308,7 @@ static Stmt *create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D) QualType TheValueTy = TheValue->getType(); const PointerType *PT = TheValueTy->getAs(); if (!PT) - return 0; + return nullptr; QualType PointeeTy = PT->getPointeeType(); ASTMaker M(C); @@ -346,9 +347,9 @@ static Stmt *create_OSAtomicCompareAndSwap(ASTContext &C, const FunctionDecl *D) /// Construct the If. Stmt *If = - new (C) IfStmt(C, SourceLocation(), 0, Comparison, Body, + new (C) IfStmt(C, SourceLocation(), nullptr, Comparison, Body, SourceLocation(), Else); - + return If; } @@ -358,15 +359,15 @@ Stmt *BodyFarm::getBody(const FunctionDecl *D) { Optional &Val = Bodies[D]; if (Val.hasValue()) return Val.getValue(); - - Val = 0; - - if (D->getIdentifier() == 0) - return 0; + + Val = nullptr; + + if (D->getIdentifier() == nullptr) + return nullptr; StringRef Name = D->getName(); if (Name.empty()) - return 0; + return nullptr; FunctionFarmer FF; @@ -378,7 +379,7 @@ Stmt *BodyFarm::getBody(const FunctionDecl *D) { FF = llvm::StringSwitch(Name) .Case("dispatch_sync", create_dispatch_sync) .Case("dispatch_once", create_dispatch_once) - .Default(NULL); + .Default(nullptr); } if (FF) { Val = FF(C, D); } @@ -390,11 +391,11 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx, // First, find the backing ivar. const ObjCIvarDecl *IVar = Prop->getPropertyIvarDecl(); if (!IVar) - return 0; + return nullptr; // Ignore weak variables, which have special behavior. if (Prop->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_weak) - return 0; + return nullptr; // Look to see if Sema has synthesized a body for us. This happens in // Objective-C++ because the return value may be a C++ class type with a @@ -420,10 +421,10 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx, // copyable. if (!Ctx.hasSameUnqualifiedType(IVar->getType(), Prop->getType().getNonReferenceType())) - return 0; + return nullptr; if (!IVar->getType()->isObjCLifetimeType() && !IVar->getType().isTriviallyCopyableType(Ctx)) - return 0; + return nullptr; // Generate our body: // return self->_ivar; @@ -447,22 +448,22 @@ static Stmt *createObjCPropertyGetter(ASTContext &Ctx, Stmt *BodyFarm::getBody(const ObjCMethodDecl *D) { // We currently only know how to synthesize property accessors. if (!D->isPropertyAccessor()) - return 0; + return nullptr; D = D->getCanonicalDecl(); Optional &Val = Bodies[D]; if (Val.hasValue()) return Val.getValue(); - Val = 0; + Val = nullptr; const ObjCPropertyDecl *Prop = D->findPropertyDecl(); if (!Prop) - return 0; + return nullptr; // For now, we only synthesize getters. if (D->param_size() != 0) - return 0; + return nullptr; Val = createObjCPropertyGetter(C, Prop); diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index fc0cc2dba8..3139ae4c5d 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -112,7 +112,7 @@ public: /// Incrementing invalid iterator is allowed and will result in invalid /// iterator. const_iterator() - : Scope(NULL), VarIter(0) {} + : Scope(nullptr), VarIter(0) {} /// Create valid iterator. In case when S.Prev is an invalid iterator and /// I is equal to 0, this will create invalid iterator. @@ -207,7 +207,7 @@ int LocalScope::const_iterator::distance(LocalScope::const_iterator L) { /// build process. It consists of CFGBlock that specifies position in CFG graph /// and LocalScope::const_iterator that specifies position in LocalScope graph. struct BlockScopePosPair { - BlockScopePosPair() : block(0) {} + BlockScopePosPair() : block(nullptr) {} BlockScopePosPair(CFGBlock *b, LocalScope::const_iterator scopePos) : block(b), scopePosition(scopePos) {} @@ -336,11 +336,11 @@ public: explicit CFGBuilder(ASTContext *astContext, const CFG::BuildOptions &buildOpts) : Context(astContext), cfg(new CFG()), // crew a new CFG - Block(NULL), Succ(NULL), - SwitchTerminatedBlock(NULL), DefaultCaseBlock(NULL), - TryTerminatedBlock(NULL), badCFG(false), BuildOpts(buildOpts), - switchExclusivelyCovered(false), switchCond(0), - cachedEntry(0), lastLookup(0) {} + Block(nullptr), Succ(nullptr), + SwitchTerminatedBlock(nullptr), DefaultCaseBlock(nullptr), + TryTerminatedBlock(nullptr), badCFG(false), BuildOpts(buildOpts), + switchExclusivelyCovered(false), switchCond(nullptr), + cachedEntry(nullptr), lastLookup(nullptr) {} // buildCFG - Used by external clients to construct the CFG. CFG* buildCFG(const Decl *D, Stmt *Statement); @@ -443,8 +443,9 @@ private: LocalScope* createOrReuseLocalScope(LocalScope* Scope); void addLocalScopeForStmt(Stmt *S); - LocalScope* addLocalScopeForDeclStmt(DeclStmt *DS, LocalScope* Scope = NULL); - LocalScope* addLocalScopeForVarDecl(VarDecl *VD, LocalScope* Scope = NULL); + LocalScope* addLocalScopeForDeclStmt(DeclStmt *DS, + LocalScope* Scope = nullptr); + LocalScope* addLocalScopeForVarDecl(VarDecl *VD, LocalScope* Scope = nullptr); void addLocalScopeAndDtors(Stmt *S); @@ -840,13 +841,13 @@ bool CFGBuilder::alwaysAdd(const Stmt *stmt) { if (!fb) { // No need to update 'cachedEntry', since it will always be null. - assert(cachedEntry == 0); + assert(!cachedEntry); return shouldAdd; } CFG::BuildOptions::ForcedBlkExprs::iterator itr = fb->find(stmt); if (itr == fb->end()) { - cachedEntry = 0; + cachedEntry = nullptr; return shouldAdd; } @@ -865,7 +866,7 @@ static const VariableArrayType *FindVA(const Type *t) { t = vt->getElementType().getTypePtr(); } - return 0; + return nullptr; } /// BuildCFG - Constructs a CFG from an AST (a Stmt*). The AST can represent an @@ -876,14 +877,14 @@ static const VariableArrayType *FindVA(const Type *t) { CFG* CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) { assert(cfg.get()); if (!Statement) - return NULL; + return nullptr; // Create an empty block that will serve as the exit block for the CFG. Since // this is the first block added to the CFG, it will be implicitly registered // as the exit block. Succ = createBlock(); assert(Succ == &cfg->getExit()); - Block = NULL; // the EXIT block is empty. Create all other blocks lazily. + Block = nullptr; // the EXIT block is empty. Create all other blocks lazily. if (BuildOpts.AddImplicitDtors) if (const CXXDestructorDecl *DD = dyn_cast_or_null(D)) @@ -893,7 +894,7 @@ CFG* CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) { CFGBlock *B = addStmt(Statement); if (badCFG) - return NULL; + return nullptr; // For C++ constructor add initializers to CFG. if (const CXXConstructorDecl *CD = dyn_cast_or_null(D)) { @@ -901,7 +902,7 @@ CFG* CFGBuilder::buildCFG(const Decl *D, Stmt *Statement) { E = CD->init_rend(); I != E; ++I) { B = addInitializer(*I); if (badCFG) - return NULL; + return nullptr; } } @@ -1156,7 +1157,7 @@ void CFGBuilder::addLocalScopeForStmt(Stmt *S) { if (!BuildOpts.AddImplicitDtors) return; - LocalScope *Scope = 0; + LocalScope *Scope = nullptr; // For compound statement we will be creating explicit scope. if (CompoundStmt *CS = dyn_cast(S)) { @@ -1278,7 +1279,7 @@ void CFGBuilder::prependAutomaticObjDtorsWithTerminator(CFGBlock *Blk, CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc) { if (!S) { badCFG = true; - return 0; + return nullptr; } if (Expr *E = dyn_cast(S)) @@ -1503,9 +1504,10 @@ CFGBlock *CFGBuilder::VisitLogicalOperator(BinaryOperator *B) { appendStmt(ConfluenceBlock, B); if (badCFG) - return 0; + return nullptr; - return VisitLogicalOperator(B, 0, ConfluenceBlock, ConfluenceBlock).first; + return VisitLogicalOperator(B, nullptr, ConfluenceBlock, + ConfluenceBlock).first; } std::pair @@ -1553,7 +1555,7 @@ CFGBuilder::VisitLogicalOperator(BinaryOperator *B, while (false); if (badCFG) - return std::make_pair((CFGBlock*)0, (CFGBlock*)0); + return std::make_pair(nullptr, nullptr); // Generate the blocks for evaluating the LHS. Expr *LHS = B->getLHS()->IgnoreParens(); @@ -1580,7 +1582,7 @@ CFGBuilder::VisitLogicalOperator(BinaryOperator *B, CFGBlock *EntryLHSBlock = addStmt(LHS); if (badCFG) - return std::make_pair((CFGBlock*)0, (CFGBlock*)0); + return std::make_pair(nullptr, nullptr); // See if this is a known constant. TryResult KnownVal = tryEvaluateBool(LHS); @@ -1646,7 +1648,7 @@ CFGBlock *CFGBuilder::VisitBreakStmt(BreakStmt *B) { // "break" is a control-flow statement. Thus we stop processing the current // block. if (badCFG) - return 0; + return nullptr; // Now create a new block that ends with the break statement. Block = createBlock(false); @@ -1734,7 +1736,7 @@ CFGBlock *CFGBuilder::VisitCallExpr(CallExpr *C, AddStmtChoice asc) { if (Block) { Succ = Block; if (badCFG) - return 0; + return nullptr; } if (NoReturn) @@ -1760,26 +1762,26 @@ CFGBlock *CFGBuilder::VisitChooseExpr(ChooseExpr *C, CFGBlock *ConfluenceBlock = Block ? Block : createBlock(); appendStmt(ConfluenceBlock, C); if (badCFG) - return 0; + return nullptr; AddStmtChoice alwaysAdd = asc.withAlwaysAdd(true); Succ = ConfluenceBlock; - Block = NULL; + Block = nullptr; CFGBlock *LHSBlock = Visit(C->getLHS(), alwaysAdd); if (badCFG) - return 0; + return nullptr; Succ = ConfluenceBlock; - Block = NULL; + Block = nullptr; CFGBlock *RHSBlock = Visit(C->getRHS(), alwaysAdd); if (badCFG) - return 0; + return nullptr; Block = createBlock(false); // See if this is a known constant. const TryResult& KnownVal = tryEvaluateBool(C->getCond()); - addSuccessor(Block, KnownVal.isFalse() ? NULL : LHSBlock); - addSuccessor(Block, KnownVal.isTrue() ? NULL : RHSBlock); + addSuccessor(Block, KnownVal.isFalse() ? nullptr : LHSBlock); + addSuccessor(Block, KnownVal.isTrue() ? nullptr : RHSBlock); Block->setTerminator(C); return addStmt(C->getCond()); } @@ -1797,7 +1799,7 @@ CFGBlock *CFGBuilder::VisitCompoundStmt(CompoundStmt *C) { LastBlock = newBlock; if (badCFG) - return NULL; + return nullptr; } return LastBlock; @@ -1806,14 +1808,14 @@ CFGBlock *CFGBuilder::VisitCompoundStmt(CompoundStmt *C) { CFGBlock *CFGBuilder::VisitConditionalOperator(AbstractConditionalOperator *C, AddStmtChoice asc) { const BinaryConditionalOperator *BCO = dyn_cast(C); - const OpaqueValueExpr *opaqueValue = (BCO ? BCO->getOpaqueValue() : NULL); + const OpaqueValueExpr *opaqueValue = (BCO ? BCO->getOpaqueValue() : nullptr); // Create the confluence block that will "merge" the results of the ternary // expression. CFGBlock *ConfluenceBlock = Block ? Block : createBlock(); appendStmt(ConfluenceBlock, C); if (badCFG) - return 0; + return nullptr; AddStmtChoice alwaysAdd = asc.withAlwaysAdd(true); @@ -1822,14 +1824,14 @@ CFGBlock *CFGBuilder::VisitConditionalOperator(AbstractConditionalOperator *C, // value that is returned instead. // e.g: x ?: y is shorthand for: x ? x : y; Succ = ConfluenceBlock; - Block = NULL; - CFGBlock *LHSBlock = 0; + Block = nullptr; + CFGBlock *LHSBlock = nullptr; const Expr *trueExpr = C->getTrueExpr(); if (trueExpr != opaqueValue) { LHSBlock = Visit(C->getTrueExpr(), alwaysAdd); if (badCFG) - return 0; - Block = NULL; + return nullptr; + Block = nullptr; } else LHSBlock = ConfluenceBlock; @@ -1838,7 +1840,7 @@ CFGBlock *CFGBuilder::VisitConditionalOperator(AbstractConditionalOperator *C, Succ = ConfluenceBlock; CFGBlock *RHSBlock = Visit(C->getFalseExpr(), alwaysAdd); if (badCFG) - return 0; + return nullptr; // If the condition is a logical '&&' or '||', build a more accurate CFG. if (BinaryOperator *Cond = @@ -1880,7 +1882,7 @@ CFGBlock *CFGBuilder::VisitDeclStmt(DeclStmt *DS) { if (DS->isSingleDecl()) return VisitDeclSubExpr(DS); - CFGBlock *B = 0; + CFGBlock *B = nullptr; // Build an individual DeclStmt for each decl. for (DeclStmt::reverse_decl_iterator I = DS->decl_rbegin(), @@ -1921,16 +1923,16 @@ CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) { bool HasTemporaries = false; // Guard static initializers under a branch. - CFGBlock *blockAfterStaticInit = 0; + CFGBlock *blockAfterStaticInit = nullptr; if (BuildOpts.AddStaticInitBranches && VD->isStaticLocal()) { // For static variables, we need to create a branch to track // whether or not they are initialized. if (Block) { Succ = Block; - Block = 0; + Block = nullptr; if (badCFG) - return 0; + return nullptr; } blockAfterStaticInit = Succ; } @@ -1973,7 +1975,7 @@ CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) { // If the type of VD is a VLA, then we must process its size expressions. for (const VariableArrayType* VA = FindVA(VD->getType().getTypePtr()); - VA != 0; VA = FindVA(VA->getElementType().getTypePtr())) { + VA != nullptr; VA = FindVA(VA->getElementType().getTypePtr())) { if (CFGBlock *newBlock = addStmt(VA->getSizeExpr())) LastBlock = newBlock; } @@ -2020,7 +2022,7 @@ CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) { if (Block) { Succ = Block; if (badCFG) - return 0; + return nullptr; } // Process the false branch. @@ -2031,7 +2033,7 @@ CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) { // NULL out Block so that the recursive call to Visit will // create a new basic block. - Block = NULL; + Block = nullptr; // If branch is not a compound statement create implicit scope // and add destructors. @@ -2044,7 +2046,7 @@ CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) { ElseBlock = sv.get(); else if (Block) { if (badCFG) - return 0; + return nullptr; } } @@ -2054,7 +2056,7 @@ CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) { Stmt *Then = I->getThen(); assert(Then); SaveAndRestore sv(Succ); - Block = NULL; + Block = nullptr; // If branch is not a compound statement create implicit scope // and add destructors. @@ -2071,7 +2073,7 @@ CFGBlock *CFGBuilder::VisitIfStmt(IfStmt *I) { addSuccessor(ThenBlock, sv.get()); } else if (Block) { if (badCFG) - return 0; + return nullptr; } } @@ -2159,10 +2161,10 @@ CFGBlock *CFGBuilder::VisitLabelStmt(LabelStmt *L) { // about. LabelBlock->setLabel(L); if (badCFG) - return 0; + return nullptr; // We set Block to NULL to allow lazy creation of a new block (if necessary); - Block = NULL; + Block = nullptr; // This block is now the implicit successor of other blocks. Succ = LabelBlock; @@ -2176,7 +2178,7 @@ CFGBlock *CFGBuilder::VisitLambdaExpr(LambdaExpr *E, AddStmtChoice asc) { et = E->capture_init_end(); it != et; ++it) { if (Expr *Init = *it) { CFGBlock *Tmp = Visit(Init); - if (Tmp != 0) + if (Tmp) LastBlock = Tmp; } } @@ -2206,7 +2208,7 @@ CFGBlock *CFGBuilder::VisitGotoStmt(GotoStmt *G) { } CFGBlock *CFGBuilder::VisitForStmt(ForStmt *F) { - CFGBlock *LoopSuccessor = NULL; + CFGBlock *LoopSuccessor = nullptr; // Save local scope position because in case of condition variable ScopePos // won't be restored when traversing AST. @@ -2229,7 +2231,7 @@ CFGBlock *CFGBuilder::VisitForStmt(ForStmt *F) { // block. if (Block) { if (badCFG) - return 0; + return nullptr; LoopSuccessor = Block; } else LoopSuccessor = Succ; @@ -2239,7 +2241,7 @@ CFGBlock *CFGBuilder::VisitForStmt(ForStmt *F) { SaveAndRestore save_break(BreakJumpTarget); BreakJumpTarget = JumpTarget(LoopSuccessor, ScopePos); - CFGBlock *BodyBlock = 0, *TransitionBlock = 0; + CFGBlock *BodyBlock = nullptr, *TransitionBlock = nullptr; // Now create the loop body. { @@ -2265,8 +2267,8 @@ CFGBlock *CFGBuilder::VisitForStmt(ForStmt *F) { if (Block) { assert(Block == Succ); if (badCFG) - return 0; - Block = 0; + return nullptr; + Block = nullptr; } // The starting block for the loop increment is the block that should @@ -2292,13 +2294,13 @@ CFGBlock *CFGBuilder::VisitForStmt(ForStmt *F) { BodyBlock = ContinueJumpTarget.block; } else if (badCFG) - return 0; + return nullptr; } // Because of short-circuit evaluation, the condition of the loop can span // multiple basic blocks. Thus we need the "Entry" and "Exit" blocks that // evaluate the condition. - CFGBlock *EntryConditionBlock = 0, *ExitConditionBlock = 0; + CFGBlock *EntryConditionBlock = nullptr, *ExitConditionBlock = nullptr; do { Expr *C = F->getCond(); @@ -2306,7 +2308,7 @@ CFGBlock *CFGBuilder::VisitForStmt(ForStmt *F) { // Specially handle logical operators, which have a slightly // more optimal CFG representation. if (BinaryOperator *Cond = - dyn_cast_or_null(C ? C->IgnoreParens() : 0)) + dyn_cast_or_null(C ? C->IgnoreParens() : nullptr)) if (Cond->isLogicalOp()) { std::tie(EntryConditionBlock, ExitConditionBlock) = VisitLogicalOperator(Cond, F, BodyBlock, LoopSuccessor); @@ -2339,16 +2341,17 @@ CFGBlock *CFGBuilder::VisitForStmt(ForStmt *F) { } if (Block && badCFG) - return 0; + return nullptr; KnownVal = tryEvaluateBool(C); } // Add the loop body entry as a successor to the condition. - addSuccessor(ExitConditionBlock, KnownVal.isFalse() ? NULL : BodyBlock); + addSuccessor(ExitConditionBlock, KnownVal.isFalse() ? nullptr : BodyBlock); // Link up the condition block with the code that follows the loop. (the // false branch). - addSuccessor(ExitConditionBlock, KnownVal.isTrue() ? NULL : LoopSuccessor); + addSuccessor(ExitConditionBlock, + KnownVal.isTrue() ? nullptr : LoopSuccessor); } while (false); @@ -2367,7 +2370,7 @@ CFGBlock *CFGBuilder::VisitForStmt(ForStmt *F) { // There is no loop initialization. We are thus basically a while loop. // NULL out Block to force lazy block construction. - Block = NULL; + Block = nullptr; Succ = EntryConditionBlock; return EntryConditionBlock; } @@ -2413,13 +2416,13 @@ CFGBlock *CFGBuilder::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { // a DeclStmt and the other returns a DeclRefExpr. // - CFGBlock *LoopSuccessor = 0; + CFGBlock *LoopSuccessor = nullptr; if (Block) { if (badCFG) - return 0; + return nullptr; LoopSuccessor = Block; - Block = 0; + Block = nullptr; } else LoopSuccessor = Succ; @@ -2442,8 +2445,8 @@ CFGBlock *CFGBuilder::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { AddStmtChoice::NotAlwaysAdd); if (Block) { if (badCFG) - return 0; - Block = 0; + return nullptr; + Block = nullptr; } // The condition block is the implicit successor for the loop body as well as @@ -2460,7 +2463,7 @@ CFGBlock *CFGBuilder::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { // Add an intermediate block between the BodyBlock and the // EntryConditionBlock to represent the "loop back" transition, for looping // back to the head of the loop. - CFGBlock *LoopBackBlock = 0; + CFGBlock *LoopBackBlock = nullptr; Succ = LoopBackBlock = createBlock(); LoopBackBlock->setLoopTarget(S); @@ -2473,7 +2476,7 @@ CFGBlock *CFGBuilder::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { BodyBlock = ContinueJumpTarget.block; // can happen for "for (X in Y) ;" else if (Block) { if (badCFG) - return 0; + return nullptr; } // This new body block is a successor to our "exit" condition block. @@ -2505,9 +2508,9 @@ CFGBlock *CFGBuilder::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { // for diagnostic clients. if (SyncBlock) { if (badCFG) - return 0; + return nullptr; - Block = 0; + Block = nullptr; Succ = SyncBlock; } @@ -2550,7 +2553,7 @@ CFGBlock *CFGBuilder::VisitPseudoObjectExpr(PseudoObjectExpr *E) { } CFGBlock *CFGBuilder::VisitWhileStmt(WhileStmt *W) { - CFGBlock *LoopSuccessor = NULL; + CFGBlock *LoopSuccessor = nullptr; // Save local scope position because in case of condition variable ScopePos // won't be restored when traversing AST. @@ -2568,14 +2571,14 @@ CFGBlock *CFGBuilder::VisitWhileStmt(WhileStmt *W) { // block. if (Block) { if (badCFG) - return 0; + return nullptr; LoopSuccessor = Block; - Block = 0; + Block = nullptr; } else { LoopSuccessor = Succ; } - CFGBlock *BodyBlock = 0, *TransitionBlock = 0; + CFGBlock *BodyBlock = nullptr, *TransitionBlock = nullptr; // Process the loop body. { @@ -2609,13 +2612,13 @@ CFGBlock *CFGBuilder::VisitWhileStmt(WhileStmt *W) { if (!BodyBlock) BodyBlock = ContinueJumpTarget.block; // can happen for "while(...) ;" else if (Block && badCFG) - return 0; + return nullptr; } // Because of short-circuit evaluation, the condition of the loop can span // multiple basic blocks. Thus we need the "Entry" and "Exit" blocks that // evaluate the condition. - CFGBlock *EntryConditionBlock = 0, *ExitConditionBlock = 0; + CFGBlock *EntryConditionBlock = nullptr, *ExitConditionBlock = nullptr; do { Expr *C = W->getCond(); @@ -2651,16 +2654,17 @@ CFGBlock *CFGBuilder::VisitWhileStmt(WhileStmt *W) { } if (Block && badCFG) - return 0; + return nullptr; // See if this is a known constant. const TryResult& KnownVal = tryEvaluateBool(C); // Add the loop body entry as a successor to the condition. - addSuccessor(ExitConditionBlock, KnownVal.isFalse() ? NULL : BodyBlock); + addSuccessor(ExitConditionBlock, KnownVal.isFalse() ? nullptr : BodyBlock); // Link up the condition block with the code that follows the loop. (the // false branch). - addSuccessor(ExitConditionBlock, KnownVal.isTrue() ? NULL : LoopSuccessor); + addSuccessor(ExitConditionBlock, + KnownVal.isTrue() ? nullptr : LoopSuccessor); } while(false); @@ -2669,7 +2673,7 @@ CFGBlock *CFGBuilder::VisitWhileStmt(WhileStmt *W) { // There can be no more statements in the condition block since we loop back // to this block. NULL out Block to force lazy creation of another block. - Block = NULL; + Block = nullptr; // Return the condition block, which is the dominating block for the loop. Succ = EntryConditionBlock; @@ -2689,7 +2693,7 @@ CFGBlock *CFGBuilder::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { // If we were in the middle of a block we stop processing that block. if (badCFG) - return 0; + return nullptr; // Create the new block. Block = createBlock(false); @@ -2705,7 +2709,7 @@ CFGBlock *CFGBuilder::VisitObjCAtThrowStmt(ObjCAtThrowStmt *S) { CFGBlock *CFGBuilder::VisitCXXThrowExpr(CXXThrowExpr *T) { // If we were in the middle of a block we stop processing that block. if (badCFG) - return 0; + return nullptr; // Create the new block. Block = createBlock(false); @@ -2723,13 +2727,13 @@ CFGBlock *CFGBuilder::VisitCXXThrowExpr(CXXThrowExpr *T) { } CFGBlock *CFGBuilder::VisitDoStmt(DoStmt *D) { - CFGBlock *LoopSuccessor = NULL; + CFGBlock *LoopSuccessor = nullptr; // "do...while" is a control-flow statement. Thus we stop processing the // current block. if (Block) { if (badCFG) - return 0; + return nullptr; LoopSuccessor = Block; } else LoopSuccessor = Succ; @@ -2750,7 +2754,7 @@ CFGBlock *CFGBuilder::VisitDoStmt(DoStmt *D) { EntryConditionBlock = addStmt(C); if (Block) { if (badCFG) - return 0; + return nullptr; } } @@ -2761,7 +2765,7 @@ CFGBlock *CFGBuilder::VisitDoStmt(DoStmt *D) { const TryResult &KnownVal = tryEvaluateBool(D->getCond()); // Process the loop body. - CFGBlock *BodyBlock = NULL; + CFGBlock *BodyBlock = nullptr; { assert(D->getBody()); @@ -2777,7 +2781,7 @@ CFGBlock *CFGBuilder::VisitDoStmt(DoStmt *D) { BreakJumpTarget = JumpTarget(LoopSuccessor, ScopePos); // NULL out Block to force lazy instantiation of blocks for the body. - Block = NULL; + Block = nullptr; // If body is not a compound statement create implicit scope // and add destructors. @@ -2791,7 +2795,7 @@ CFGBlock *CFGBuilder::VisitDoStmt(DoStmt *D) { BodyBlock = EntryConditionBlock; // can happen for "do ; while(...)" else if (Block) { if (badCFG) - return 0; + return nullptr; } if (!KnownVal.isFalse()) { @@ -2800,7 +2804,7 @@ CFGBlock *CFGBuilder::VisitDoStmt(DoStmt *D) { // empty block to represent the transition block for looping back to the // head of the loop. // FIXME: Can we do this more efficiently without adding another block? - Block = NULL; + Block = nullptr; Succ = BodyBlock; CFGBlock *LoopBackBlock = createBlock(); LoopBackBlock->setLoopTarget(D); @@ -2809,16 +2813,16 @@ CFGBlock *CFGBuilder::VisitDoStmt(DoStmt *D) { addSuccessor(ExitConditionBlock, LoopBackBlock); } else - addSuccessor(ExitConditionBlock, NULL); + addSuccessor(ExitConditionBlock, nullptr); } // Link up the condition block with the code that follows the loop. // (the false branch). - addSuccessor(ExitConditionBlock, KnownVal.isTrue() ? NULL : LoopSuccessor); + addSuccessor(ExitConditionBlock, KnownVal.isTrue() ? nullptr : LoopSuccessor); // There can be no more statements in the body block(s) since we loop back to // the body. NULL out Block to force lazy creation of another block. - Block = NULL; + Block = nullptr; // Return the loop body, which is the dominating block for the loop. Succ = BodyBlock; @@ -2829,7 +2833,7 @@ CFGBlock *CFGBuilder::VisitContinueStmt(ContinueStmt *C) { // "continue" is a control-flow statement. Thus we stop processing the // current block. if (badCFG) - return 0; + return nullptr; // Now create a new block that ends with the continue statement. Block = createBlock(false); @@ -2859,7 +2863,7 @@ CFGBlock *CFGBuilder::VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E, if (E->isArgumentType()) { for (const VariableArrayType *VA =FindVA(E->getArgumentType().getTypePtr()); - VA != 0; VA = FindVA(VA->getElementType().getTypePtr())) + VA != nullptr; VA = FindVA(VA->getElementType().getTypePtr())) lastBlock = addStmt(VA->getSizeExpr()); } return lastBlock; @@ -2878,7 +2882,7 @@ CFGBlock *CFGBuilder::VisitStmtExpr(StmtExpr *SE, AddStmtChoice asc) { CFGBlock *CFGBuilder::VisitSwitchStmt(SwitchStmt *Terminator) { // "switch" is a control-flow statement. Thus we stop processing the current // block. - CFGBlock *SwitchSuccessor = NULL; + CFGBlock *SwitchSuccessor = nullptr; // Save local scope position because in case of condition variable ScopePos // won't be restored when traversing AST. @@ -2894,7 +2898,7 @@ CFGBlock *CFGBuilder::VisitSwitchStmt(SwitchStmt *Terminator) { if (Block) { if (badCFG) - return 0; + return nullptr; SwitchSuccessor = Block; } else SwitchSuccessor = Succ; @@ -2920,7 +2924,7 @@ CFGBlock *CFGBuilder::VisitSwitchStmt(SwitchStmt *Terminator) { // up to the switch. We also don't keep a pointer to the body, since all // control-flow from the switch goes to case/default statements. assert(Terminator->getBody() && "switch must contain a non-NULL body"); - Block = NULL; + Block = nullptr; // For pruning unreachable case statements, save the current state // for tracking the condition value. @@ -2932,7 +2936,7 @@ CFGBlock *CFGBuilder::VisitSwitchStmt(SwitchStmt *Terminator) { Expr::EvalResult result; bool b = tryEvaluate(Terminator->getCond(), result); SaveAndRestore save_switchCond(switchCond, - b ? &result : 0); + b ? &result : nullptr); // If body is not a compound statement create implicit scope // and add destructors. @@ -2942,7 +2946,7 @@ CFGBlock *CFGBuilder::VisitSwitchStmt(SwitchStmt *Terminator) { addStmt(Terminator->getBody()); if (Block) { if (badCFG) - return 0; + return nullptr; } // If we have no "default:" case, the default transition is to the code @@ -3015,7 +3019,7 @@ static bool shouldAddCase(bool &switchExclusivelyCovered, CFGBlock *CFGBuilder::VisitCaseStmt(CaseStmt *CS) { // CaseStmts are essentially labels, so they are the first statement in a // block. - CFGBlock *TopBlock = 0, *LastBlock = 0; + CFGBlock *TopBlock = nullptr, *LastBlock = nullptr; if (Stmt *Sub = CS->getSubStmt()) { // For deeply nested chains of CaseStmts, instead of doing a recursion @@ -3033,7 +3037,7 @@ CFGBlock *CFGBuilder::VisitCaseStmt(CaseStmt *CS) { addSuccessor(SwitchTerminatedBlock, shouldAddCase(switchExclusivelyCovered, switchCond, CS, *Context) - ? currentBlock : 0); + ? currentBlock : nullptr); LastBlock = currentBlock; CS = cast(Sub); @@ -3052,7 +3056,7 @@ CFGBlock *CFGBuilder::VisitCaseStmt(CaseStmt *CS) { CaseBlock->setLabel(CS); if (badCFG) - return 0; + return nullptr; // Add this block to the list of successors for the block with the switch // statement. @@ -3062,7 +3066,7 @@ CFGBlock *CFGBuilder::VisitCaseStmt(CaseStmt *CS) { CS, *Context)); // We set Block to NULL to allow lazy creation of a new block (if necessary) - Block = NULL; + Block = nullptr; if (TopBlock) { addSuccessor(LastBlock, CaseBlock); @@ -3089,7 +3093,7 @@ CFGBlock *CFGBuilder::VisitDefaultStmt(DefaultStmt *Terminator) { DefaultCaseBlock->setLabel(Terminator); if (badCFG) - return 0; + return nullptr; // Unlike case statements, we don't add the default block to the successors // for the switch statement immediately. This is done when we finish @@ -3098,7 +3102,7 @@ CFGBlock *CFGBuilder::VisitDefaultStmt(DefaultStmt *Terminator) { // be the last successor of a switch-terminated block. // We set Block to NULL to allow lazy creation of a new block (if necessary) - Block = NULL; + Block = nullptr; // This block is now the implicit successor of other blocks. Succ = DefaultCaseBlock; @@ -3109,11 +3113,11 @@ CFGBlock *CFGBuilder::VisitDefaultStmt(DefaultStmt *Terminator) { CFGBlock *CFGBuilder::VisitCXXTryStmt(CXXTryStmt *Terminator) { // "try"/"catch" is a control-flow statement. Thus we stop processing the // current block. - CFGBlock *TrySuccessor = NULL; + CFGBlock *TrySuccessor = nullptr; if (Block) { if (badCFG) - return 0; + return nullptr; TrySuccessor = Block; } else TrySuccessor = Succ; @@ -3129,13 +3133,13 @@ CFGBlock *CFGBuilder::VisitCXXTryStmt(CXXTryStmt *Terminator) { // The code after the try is the implicit successor. Succ = TrySuccessor; CXXCatchStmt *CS = Terminator->getHandler(h); - if (CS->getExceptionDecl() == 0) { + if (CS->getExceptionDecl() == nullptr) { HasCatchAll = true; } - Block = NULL; + Block = nullptr; CFGBlock *CatchBlock = VisitCXXCatchStmt(CS); - if (CatchBlock == 0) - return 0; + if (!CatchBlock) + return nullptr; // Add this block to the list of successors for the block with the try // statement. addSuccessor(NewTryTerminatedBlock, CatchBlock); @@ -3155,7 +3159,7 @@ CFGBlock *CFGBuilder::VisitCXXTryStmt(CXXTryStmt *Terminator) { cfg->addTryDispatchBlock(TryTerminatedBlock); assert(Terminator->getTryBlock() && "try must contain a non-NULL body"); - Block = NULL; + Block = nullptr; return addStmt(Terminator->getTryBlock()); } @@ -3194,10 +3198,10 @@ CFGBlock *CFGBuilder::VisitCXXCatchStmt(CXXCatchStmt *CS) { // Bail out if the CFG is bad. if (badCFG) - return 0; + return nullptr; // We set Block to NULL to allow lazy creation of a new block (if necessary) - Block = NULL; + Block = nullptr; return CatchBlock; } @@ -3230,10 +3234,10 @@ CFGBlock *CFGBuilder::VisitCXXForRangeStmt(CXXForRangeStmt *S) { // "for" is a control-flow statement. Thus we stop processing the current // block. - CFGBlock *LoopSuccessor = NULL; + CFGBlock *LoopSuccessor = nullptr; if (Block) { if (badCFG) - return 0; + return nullptr; LoopSuccessor = Block; } else LoopSuccessor = Succ; @@ -3252,7 +3256,7 @@ CFGBlock *CFGBuilder::VisitCXXForRangeStmt(CXXForRangeStmt *S) { Block = ConditionBlock; CFGBlock *BeginConditionBlock = addStmt(C); if (badCFG) - return 0; + return nullptr; assert(BeginConditionBlock == ConditionBlock && "condition block in for-range was unexpectedly complex"); (void)BeginConditionBlock; @@ -3278,7 +3282,7 @@ CFGBlock *CFGBuilder::VisitCXXForRangeStmt(CXXForRangeStmt *S) { // Generate increment code in its own basic block. This is the target of // continue statements. - Block = 0; + Block = nullptr; Succ = addStmt(S->getInc()); ContinueJumpTarget = JumpTarget(Succ, ContinueScopePos); @@ -3289,9 +3293,8 @@ CFGBlock *CFGBuilder::VisitCXXForRangeStmt(CXXForRangeStmt *S) { // Finish up the increment block and prepare to start the loop body. assert(Block); if (badCFG) - return 0; - Block = 0; - + return nullptr; + Block = nullptr; // Add implicit scope and dtors for loop variable. addLocalScopeAndDtors(S->getLoopVarStmt()); @@ -3299,18 +3302,19 @@ CFGBlock *CFGBuilder::VisitCXXForRangeStmt(CXXForRangeStmt *S) { // Populate a new block to contain the loop body and loop variable. addStmt(S->getBody()); if (badCFG) - return 0; + return nullptr; CFGBlock *LoopVarStmtBlock = addStmt(S->getLoopVarStmt()); if (badCFG) - return 0; - + return nullptr; + // This new body block is a successor to our condition block. - addSuccessor(ConditionBlock, KnownVal.isFalse() ? 0 : LoopVarStmtBlock); + addSuccessor(ConditionBlock, + KnownVal.isFalse() ? nullptr : LoopVarStmtBlock); } // Link up the condition block with the code that follows the loop (the // false branch). - addSuccessor(ConditionBlock, KnownVal.isTrue() ? 0 : LoopSuccessor); + addSuccessor(ConditionBlock, KnownVal.isTrue() ? nullptr : LoopSuccessor); // Add the initialization statements. Block = createBlock(); @@ -3424,7 +3428,7 @@ CFGBlock *CFGBuilder::VisitIndirectGotoStmt(IndirectGotoStmt *I) { // IndirectGoto is a control-flow statement. Thus we stop processing the // current block and create a new one. if (badCFG) - return 0; + return nullptr; Block = createBlock(false); Block->setTerminator(I); @@ -3438,7 +3442,7 @@ CFGBlock *CFGBuilder::VisitForTemporaryDtors(Stmt *E, bool BindToTemporary) { tryAgain: if (!E) { badCFG = true; - return NULL; + return nullptr; } switch (E->getStmtClass()) { default: @@ -3493,15 +3497,15 @@ CFGBlock *CFGBuilder::VisitBinaryOperatorForTemporaryDtors(BinaryOperator *E) { autoCreateBlock(); CFGBlock *ConfluenceBlock = VisitForTemporaryDtors(E->getLHS()); if (badCFG) - return NULL; + return nullptr; Succ = ConfluenceBlock; - Block = NULL; + Block = nullptr; CFGBlock *RHSBlock = VisitForTemporaryDtors(E->getRHS()); if (RHSBlock) { if (badCFG) - return NULL; + return nullptr; // If RHS expression did produce destructors we need to connect created // blocks to CFG in same manner as for binary operator itself. @@ -3521,12 +3525,12 @@ CFGBlock *CFGBuilder::VisitBinaryOperatorForTemporaryDtors(BinaryOperator *E) { // Link LHSBlock with RHSBlock exactly the same way as for binary operator // itself. if (E->getOpcode() == BO_LOr) { - addSuccessor(LHSBlock, KnownVal.isTrue() ? NULL : ConfluenceBlock); - addSuccessor(LHSBlock, KnownVal.isFalse() ? NULL : RHSBlock); + addSuccessor(LHSBlock, KnownVal.isTrue() ? nullptr : ConfluenceBlock); + addSuccessor(LHSBlock, KnownVal.isFalse() ? nullptr : RHSBlock); } else { assert (E->getOpcode() == BO_LAnd); - addSuccessor(LHSBlock, KnownVal.isFalse() ? NULL : RHSBlock); - addSuccessor(LHSBlock, KnownVal.isTrue() ? NULL : ConfluenceBlock); + addSuccessor(LHSBlock, KnownVal.isFalse() ? nullptr : RHSBlock); + addSuccessor(LHSBlock, KnownVal.isTrue() ? nullptr : ConfluenceBlock); } Block = LHSBlock; @@ -3586,29 +3590,29 @@ CFGBlock *CFGBuilder::VisitConditionalOperatorForTemporaryDtors( autoCreateBlock(); CFGBlock *ConfluenceBlock = VisitForTemporaryDtors(E->getCond()); if (badCFG) - return NULL; + return nullptr; if (BinaryConditionalOperator *BCO = dyn_cast(E)) { ConfluenceBlock = VisitForTemporaryDtors(BCO->getCommon()); if (badCFG) - return NULL; + return nullptr; } // Try to add block with destructors for LHS expression. - CFGBlock *LHSBlock = NULL; + CFGBlock *LHSBlock = nullptr; Succ = ConfluenceBlock; - Block = NULL; + Block = nullptr; LHSBlock = VisitForTemporaryDtors(E->getTrueExpr(), BindToTemporary); if (badCFG) - return NULL; + return nullptr; // Try to add block with destructors for RHS expression; Succ = ConfluenceBlock; - Block = NULL; + Block = nullptr; CFGBlock *RHSBlock = VisitForTemporaryDtors(E->getFalseExpr(), BindToTemporary); if (badCFG) - return NULL; + return nullptr; if (!RHSBlock && !LHSBlock) { // If neither LHS nor RHS expression had temporaries to destroy don't create @@ -3627,7 +3631,7 @@ CFGBlock *CFGBuilder::VisitConditionalOperatorForTemporaryDtors( if (LHSBlock) { addSuccessor(Block, LHSBlock, !KnownVal.isFalse()); } else if (KnownVal.isFalse()) { - addSuccessor(Block, NULL); + addSuccessor(Block, nullptr); } else { addSuccessor(Block, ConfluenceBlock); std::reverse(ConfluenceBlock->pred_begin(), ConfluenceBlock->pred_end()); @@ -3708,7 +3712,7 @@ CFGImplicitDtor::getDestructorDecl(ASTContext &astContext) const { case CFGElement::MemberDtor: // Not yet supported. - return 0; + return nullptr; } llvm_unreachable("getKind() returned bogus value"); } @@ -3724,13 +3728,13 @@ bool CFGImplicitDtor::isNoReturn(ASTContext &astContext) const { //===----------------------------------------------------------------------===// CFGBlock::AdjacentBlock::AdjacentBlock(CFGBlock *B, bool IsReachable) - : ReachableBlock(IsReachable ? B : 0), - UnreachableBlock(!IsReachable ? B : 0, + : ReachableBlock(IsReachable ? B : nullptr), + UnreachableBlock(!IsReachable ? B : nullptr, B && IsReachable ? AB_Normal : AB_Unreachable) {} CFGBlock::AdjacentBlock::AdjacentBlock(CFGBlock *B, CFGBlock *AlternateBlock) : ReachableBlock(B), - UnreachableBlock(B == AlternateBlock ? 0 : AlternateBlock, + UnreachableBlock(B == AlternateBlock ? nullptr : AlternateBlock, B == AlternateBlock ? AB_Alternate : AB_Normal) {} void CFGBlock::addSuccessor(AdjacentBlock Succ, @@ -4330,16 +4334,16 @@ void CFGBlock::print(raw_ostream &OS, const CFG* cfg, /// printTerminator - A simple pretty printer of the terminator of a CFGBlock. void CFGBlock::printTerminator(raw_ostream &OS, const LangOptions &LO) const { - CFGBlockTerminatorPrint TPrinter(OS, NULL, PrintingPolicy(LO)); + CFGBlockTerminatorPrint TPrinter(OS, nullptr, PrintingPolicy(LO)); TPrinter.print(getTerminator()); } Stmt *CFGBlock::getTerminatorCondition(bool StripParens) { Stmt *Terminator = this->Terminator; if (!Terminator) - return NULL; + return nullptr; - Expr *E = NULL; + Expr *E = nullptr; switch (Terminator->getStmtClass()) { default: @@ -4396,7 +4400,7 @@ Stmt *CFGBlock::getTerminatorCondition(bool StripParens) { if (!StripParens) return E; - return E ? E->IgnoreParens() : NULL; + return E ? E->IgnoreParens() : nullptr; } //===----------------------------------------------------------------------===// @@ -4413,7 +4417,7 @@ void CFG::viewCFG(const LangOptions &LO) const { StmtPrinterHelper H(this, LO); GraphHelper = &H; llvm::ViewGraph(this,"CFG"); - GraphHelper = NULL; + GraphHelper = nullptr; #endif } diff --git a/lib/Analysis/CFGStmtMap.cpp b/lib/Analysis/CFGStmtMap.cpp index 87c2f5bdc1..19b80191f7 100644 --- a/lib/Analysis/CFGStmtMap.cpp +++ b/lib/Analysis/CFGStmtMap.cpp @@ -42,8 +42,8 @@ CFGBlock *CFGStmtMap::getBlock(Stmt *S) { X = PM->getParentIgnoreParens(X); } - - return 0; + + return nullptr; } static void Accumulate(SMap &SM, CFGBlock *B) { @@ -77,7 +77,7 @@ static void Accumulate(SMap &SM, CFGBlock *B) { CFGStmtMap *CFGStmtMap::Build(CFG *C, ParentMap *PM) { if (!C || !PM) - return 0; + return nullptr; SMap *SM = new SMap(); diff --git a/lib/Analysis/CallGraph.cpp b/lib/Analysis/CallGraph.cpp index f78f6740d4..f41a96d30e 100644 --- a/lib/Analysis/CallGraph.cpp +++ b/lib/Analysis/CallGraph.cpp @@ -49,7 +49,7 @@ public: return Block->getBlockDecl(); } - return 0; + return nullptr; } void addCalledDecl(Decl *D) { @@ -70,7 +70,7 @@ public: Selector Sel = ME->getSelector(); // Find the callee definition within the same translation unit. - Decl *D = 0; + Decl *D = nullptr; if (ME->isInstanceMessage()) D = IDecl->lookupPrivateMethod(Sel); else @@ -101,7 +101,7 @@ void CallGraph::addNodesForBlocks(DeclContext *D) { } CallGraph::CallGraph() { - Root = getOrInsertNode(0); + Root = getOrInsertNode(nullptr); } CallGraph::~CallGraph() { @@ -147,7 +147,7 @@ void CallGraph::addNodeForDecl(Decl* D, bool IsGlobal) { CallGraphNode *CallGraph::getNode(const Decl *F) const { FunctionMapTy::const_iterator I = FunctionMap.find(F); - if (I == FunctionMap.end()) return 0; + if (I == FunctionMap.end()) return nullptr; return I->second; } @@ -158,7 +158,7 @@ CallGraphNode *CallGraph::getOrInsertNode(Decl *F) { Node = new CallGraphNode(F); // Make Root node a parent of all functions to make sure all are reachable. - if (F != 0) + if (F) Root->addCallee(Node, this); return Node; } diff --git a/lib/Analysis/Consumed.cpp b/lib/Analysis/Consumed.cpp index e3dcb92378..2027e77bbf 100644 --- a/lib/Analysis/Consumed.cpp +++ b/lib/Analysis/Consumed.cpp @@ -710,7 +710,7 @@ void ConsumedStmtVisitor::VisitBinaryOperator(const BinaryOperator *BinOp) { LTest = LEntry->second.getVarTest(); } else { - LTest.Var = NULL; + LTest.Var = nullptr; LTest.TestsFor = CS_None; } @@ -718,11 +718,11 @@ void ConsumedStmtVisitor::VisitBinaryOperator(const BinaryOperator *BinOp) { RTest = REntry->second.getVarTest(); } else { - RTest.Var = NULL; + RTest.Var = nullptr; RTest.TestsFor = CS_None; } - - if (!(LTest.Var == NULL && RTest.Var == NULL)) + + if (!(LTest.Var == nullptr && RTest.Var == nullptr)) PropagationMap.insert(PairType(BinOp, PropagationInfo(BinOp, static_cast(BinOp->getOpcode() == BO_LOr), LTest, RTest))); @@ -763,7 +763,7 @@ void ConsumedStmtVisitor::VisitCallExpr(const CallExpr *Call) { return; } - handleCall(Call, 0, FunDecl); + handleCall(Call, nullptr, FunDecl); propagateReturnType(Call, FunDecl); } @@ -1072,9 +1072,9 @@ void ConsumedBlockInfo::addInfo(const CFGBlock *Block, void ConsumedBlockInfo::addInfo(const CFGBlock *Block, ConsumedStateMap *StateMap) { - - assert(Block != NULL && "Block pointer must not be NULL"); - + + assert(Block && "Block pointer must not be NULL"); + ConsumedStateMap *Entry = StateMapsArray[Block->getBlockID()]; if (Entry) { @@ -1096,7 +1096,7 @@ ConsumedStateMap* ConsumedBlockInfo::borrowInfo(const CFGBlock *Block) { void ConsumedBlockInfo::discardInfo(const CFGBlock *Block) { unsigned int BlockID = Block->getBlockID(); delete StateMapsArray[BlockID]; - StateMapsArray[BlockID] = NULL; + StateMapsArray[BlockID] = nullptr; } ConsumedStateMap* ConsumedBlockInfo::getInfo(const CFGBlock *Block) { @@ -1106,7 +1106,7 @@ ConsumedStateMap* ConsumedBlockInfo::getInfo(const CFGBlock *Block) { if (isBackEdgeTarget(Block)) { return new ConsumedStateMap(*StateMap); } else { - StateMapsArray[Block->getBlockID()] = NULL; + StateMapsArray[Block->getBlockID()] = nullptr; return StateMap; } } @@ -1119,8 +1119,8 @@ bool ConsumedBlockInfo::isBackEdge(const CFGBlock *From, const CFGBlock *To) { } bool ConsumedBlockInfo::isBackEdgeTarget(const CFGBlock *Block) { - assert(Block != NULL && "Block pointer must not be NULL"); - + assert(Block && "Block pointer must not be NULL"); + // Anything with less than two predecessors can't be the target of a back // edge. if (Block->pred_size() < 2) @@ -1356,7 +1356,7 @@ bool ConsumedAnalyzer::splitState(const CFGBlock *CurrBlock, if (*++SI) BlockInfo.addInfo(*SI, FalseStates.release()); - CurrStates = NULL; + CurrStates = nullptr; return true; } @@ -1385,7 +1385,7 @@ void ConsumedAnalyzer::run(AnalysisDeclContext &AC) { // Visit all of the function's basic blocks. for (const auto *CurrBlock : *SortedGraph) { - if (CurrStates == NULL) + if (!CurrStates) CurrStates = BlockInfo.getInfo(CurrBlock); if (!CurrStates) { @@ -1393,7 +1393,7 @@ void ConsumedAnalyzer::run(AnalysisDeclContext &AC) { } else if (!CurrStates->isReachable()) { delete CurrStates; - CurrStates = NULL; + CurrStates = nullptr; continue; } @@ -1436,8 +1436,8 @@ void ConsumedAnalyzer::run(AnalysisDeclContext &AC) { // TODO: Handle other forms of branching with precision, including while- // and for-loops. (Deferred) if (!splitState(CurrBlock, Visitor)) { - CurrStates->setSource(NULL); - + CurrStates->setSource(nullptr); + if (CurrBlock->succ_size() > 1 || (CurrBlock->succ_size() == 1 && (*CurrBlock->succ_begin())->pred_size() > 1)) { @@ -1446,9 +1446,9 @@ void ConsumedAnalyzer::run(AnalysisDeclContext &AC) { for (CFGBlock::const_succ_iterator SI = CurrBlock->succ_begin(), SE = CurrBlock->succ_end(); SI != SE; ++SI) { - - if (*SI == NULL) continue; - + + if (*SI == nullptr) continue; + if (BlockInfo.isBackEdge(CurrBlock, *SI)) { BlockInfo.borrowInfo(*SI)->intersectAtLoopHead(*SI, CurrBlock, CurrStates, @@ -1463,8 +1463,8 @@ void ConsumedAnalyzer::run(AnalysisDeclContext &AC) { if (!OwnershipTaken) delete CurrStates; - - CurrStates = NULL; + + CurrStates = nullptr; } } diff --git a/lib/Analysis/FormatString.cpp b/lib/Analysis/FormatString.cpp index 43ecc6682e..851b97e5bc 100644 --- a/lib/Analysis/FormatString.cpp +++ b/lib/Analysis/FormatString.cpp @@ -507,7 +507,7 @@ analyze_format_string::LengthModifier::toString() const { case None: return ""; } - return NULL; + return nullptr; } //===----------------------------------------------------------------------===// @@ -539,7 +539,7 @@ const char *ConversionSpecifier::toString() const { case nArg: return "n"; case PercentArg: return "%"; case ScanListArg: return "["; - case InvalidSpecifier: return NULL; + case InvalidSpecifier: return nullptr; // POSIX unicode extensions. case CArg: return "C"; @@ -551,7 +551,7 @@ const char *ConversionSpecifier::toString() const { // GlibC specific specifiers. case PrintErrno: return "m"; } - return NULL; + return nullptr; } Optional diff --git a/lib/Analysis/FormatStringParsing.h b/lib/Analysis/FormatStringParsing.h index 6b25123013..fba318042c 100644 --- a/lib/Analysis/FormatStringParsing.h +++ b/lib/Analysis/FormatStringParsing.h @@ -53,14 +53,14 @@ template class SpecifierResult { bool Stop; public: SpecifierResult(bool stop = false) - : Start(0), Stop(stop) {} + : Start(nullptr), Stop(stop) {} SpecifierResult(const char *start, const T &fs) : FS(fs), Start(start), Stop(false) {} const char *getStart() const { return Start; } bool shouldStop() const { return Stop; } - bool hasValue() const { return Start != 0; } + bool hasValue() const { return Start != nullptr; } const T &getValue() const { assert(hasValue()); return FS; diff --git a/lib/Analysis/LiveVariables.cpp b/lib/Analysis/LiveVariables.cpp index b26d4fb370..3d6fc039fd 100644 --- a/lib/Analysis/LiveVariables.cpp +++ b/lib/Analysis/LiveVariables.cpp @@ -72,7 +72,7 @@ void DataflowWorklist::sortWorklist() { const CFGBlock *DataflowWorklist::dequeue() { if (worklist.empty()) - return 0; + return nullptr; const CFGBlock *b = worklist.pop_back_val(); enqueuedBlocks[b->getBlockID()] = false; return b; @@ -94,10 +94,10 @@ public: LiveVariables::LivenessValues merge(LiveVariables::LivenessValues valsA, LiveVariables::LivenessValues valsB); - - LiveVariables::LivenessValues runOnBlock(const CFGBlock *block, - LiveVariables::LivenessValues val, - LiveVariables::Observer *obs = 0); + + LiveVariables::LivenessValues + runOnBlock(const CFGBlock *block, LiveVariables::LivenessValues val, + LiveVariables::Observer *obs = nullptr); void dumpBlockLiveness(const SourceManager& M); @@ -224,8 +224,8 @@ static const VariableArrayType *FindVA(QualType Ty) { ty = VT->getElementType().getTypePtr(); } - - return 0; + + return nullptr; } static const Stmt *LookThroughStmt(const Stmt *S) { @@ -291,7 +291,7 @@ void TransferFunctions::Visit(Stmt *S) { const DeclStmt *DS = cast(S); if (const VarDecl *VD = dyn_cast(DS->getSingleDecl())) { for (const VariableArrayType* VA = FindVA(VD->getType()); - VA != 0; VA = FindVA(VA->getElementType())) { + VA != nullptr; VA = FindVA(VA->getElementType())) { AddLiveStmt(val.liveStmts, LV.SSetFact, VA->getSizeExpr()); } } @@ -384,8 +384,8 @@ void TransferFunctions::VisitDeclStmt(DeclStmt *DS) { void TransferFunctions::VisitObjCForCollectionStmt(ObjCForCollectionStmt *OS) { // Kill the iteration variable. - DeclRefExpr *DR = 0; - const VarDecl *VD = 0; + DeclRefExpr *DR = nullptr; + const VarDecl *VD = nullptr; Stmt *element = OS->getElement(); if (DeclStmt *DS = dyn_cast(element)) { @@ -493,12 +493,12 @@ LiveVariables::computeLiveness(AnalysisDeclContext &AC, // No CFG? Bail out. CFG *cfg = AC.getCFG(); if (!cfg) - return 0; + return nullptr; // The analysis currently has scalability issues for very large CFGs. // Bail out if it looks too large. if (cfg->getNumBlockIDs() > 300000) - return 0; + return nullptr; LiveVariablesImpl *LV = new LiveVariablesImpl(AC, killAtAssign); diff --git a/lib/Analysis/PostOrderCFGView.cpp b/lib/Analysis/PostOrderCFGView.cpp index cfd66f7aa1..5a3c8182a1 100644 --- a/lib/Analysis/PostOrderCFGView.cpp +++ b/lib/Analysis/PostOrderCFGView.cpp @@ -31,7 +31,7 @@ PostOrderCFGView::PostOrderCFGView(const CFG *cfg) { PostOrderCFGView *PostOrderCFGView::create(AnalysisDeclContext &ctx) { const CFG *cfg = ctx.getCFG(); if (!cfg) - return 0; + return nullptr; return new PostOrderCFGView(cfg); } diff --git a/lib/Analysis/PrintfFormatString.cpp b/lib/Analysis/PrintfFormatString.cpp index f21b407bcb..082a8327a3 100644 --- a/lib/Analysis/PrintfFormatString.cpp +++ b/lib/Analysis/PrintfFormatString.cpp @@ -60,7 +60,7 @@ static PrintfSpecifierResult ParsePrintfSpecifier(FormatStringHandler &H, using namespace clang::analyze_printf; const char *I = Beg; - const char *Start = 0; + const char *Start = nullptr; UpdateOnReturn UpdateBeg(Beg, I); // Look for a '%' character that indicates the start of a format specifier. @@ -124,7 +124,7 @@ static PrintfSpecifierResult ParsePrintfSpecifier(FormatStringHandler &H, // Look for the field width (if any). if (ParseFieldWidth(H, FS, Start, I, E, - FS.usesPositionalArg() ? 0 : &argIndex)) + FS.usesPositionalArg() ? nullptr : &argIndex)) return true; if (I == E) { @@ -142,7 +142,7 @@ static PrintfSpecifierResult ParsePrintfSpecifier(FormatStringHandler &H, } if (ParsePrecision(H, FS, Start, I, E, - FS.usesPositionalArg() ? 0 : &argIndex)) + FS.usesPositionalArg() ? nullptr : &argIndex)) return true; if (I == E) { diff --git a/lib/Analysis/PseudoConstantAnalysis.cpp b/lib/Analysis/PseudoConstantAnalysis.cpp index 314ce7cfd8..3f96ca877f 100644 --- a/lib/Analysis/PseudoConstantAnalysis.cpp +++ b/lib/Analysis/PseudoConstantAnalysis.cpp @@ -70,7 +70,7 @@ const Decl *PseudoConstantAnalysis::getDecl(const Expr *E) { if (const DeclRefExpr *DR = dyn_cast(E)) return DR->getDecl(); else - return 0; + return nullptr; } void PseudoConstantAnalysis::RunAnalysis() { diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp index 8be1af7cef..64be902af6 100644 --- a/lib/Analysis/ReachableCode.cpp +++ b/lib/Analysis/ReachableCode.cpp @@ -402,7 +402,7 @@ const Stmt *DeadCodeScan::findDeadCode(const clang::CFGBlock *Block) { } } - return 0; + return nullptr; } static int SrcCmp(const std::pair *p1, @@ -606,7 +606,7 @@ void Callback::anchor() { } unsigned ScanReachableFromBlock(const CFGBlock *Start, llvm::BitVector &Reachable) { - return scanFromBlock(Start, Reachable, /* SourceManager* */ 0, false); + return scanFromBlock(Start, Reachable, /* SourceManager* */ nullptr, false); } void FindUnreachableCode(AnalysisDeclContext &AC, Preprocessor &PP, diff --git a/lib/Analysis/ScanfFormatString.cpp b/lib/Analysis/ScanfFormatString.cpp index 32d35cde2f..ed28627495 100644 --- a/lib/Analysis/ScanfFormatString.cpp +++ b/lib/Analysis/ScanfFormatString.cpp @@ -82,7 +82,7 @@ static ScanfSpecifierResult ParseScanfSpecifier(FormatStringHandler &H, using namespace clang::analyze_scanf; const char *I = Beg; - const char *Start = 0; + const char *Start = nullptr; UpdateOnReturn UpdateBeg(Beg, I); // Look for a '%' character that indicates the start of a format specifier. diff --git a/lib/Analysis/ThreadSafety.cpp b/lib/Analysis/ThreadSafety.cpp index 58e6070c00..11df61f80f 100644 --- a/lib/Analysis/ThreadSafety.cpp +++ b/lib/Analysis/ThreadSafety.cpp @@ -177,8 +177,8 @@ private: CallingContext* PrevCtx; // The previous context; or 0 if none. CallingContext(const NamedDecl *D) - : AttrDecl(D), SelfArg(0), SelfArrow(false), NumArgs(0), FunArgs(0), - PrevCtx(0) {} + : AttrDecl(D), SelfArg(nullptr), SelfArrow(false), NumArgs(0), + FunArgs(nullptr), PrevCtx(nullptr) {} }; typedef SmallVector NodeVector; @@ -189,7 +189,7 @@ private: NodeVector NodeVec; private: - unsigned make(ExprOp O, unsigned F = 0, const void *D = 0) { + unsigned make(ExprOp O, unsigned F = 0, const void *D = nullptr) { NodeVec.push_back(SExprNode(O, F, D)); return NodeVec.size() - 1; } @@ -236,7 +236,7 @@ private: return D; // Method does not override anything D = *I; // FIXME: this does not work with multiple inheritance. } - return 0; + return nullptr; } unsigned makeMCall(unsigned NumArgs, const CXXMethodDecl *D) { @@ -272,8 +272,8 @@ private: /// NDeref returns the number of Derefence and AddressOf operations /// preceding the Expr; this is used to decide whether to pretty-print /// SExprs with . or ->. - unsigned buildSExpr(const Expr *Exp, CallingContext* CallCtx, - int* NDeref = 0) { + unsigned buildSExpr(const Expr *Exp, CallingContext *CallCtx, + int *NDeref = nullptr) { if (!Exp) return 0; @@ -370,7 +370,7 @@ private: } } unsigned NumCallArgs = CE->getNumArgs(); - unsigned Root = makeCall(NumCallArgs, 0); + unsigned Root = makeCall(NumCallArgs, nullptr); unsigned Sz = buildSExpr(CE->getCallee(), CallCtx); const Expr* const* CallArgs = CE->getArgs(); for (unsigned i = 0; i < NumCallArgs; ++i) { @@ -463,7 +463,7 @@ private: /// occurs. /// \param D The declaration to which the lock/unlock attribute is attached. void buildSExprFromExpr(const Expr *MutexExp, const Expr *DeclExp, - const NamedDecl *D, VarDecl *SelfDecl = 0) { + const NamedDecl *D, VarDecl *SelfDecl = nullptr) { CallingContext CallCtx(D); if (MutexExp) { @@ -480,8 +480,8 @@ private: } // If we are processing a raw attribute expression, with no substitutions. - if (DeclExp == 0) { - buildSExpr(MutexExp, 0); + if (!DeclExp) { + buildSExpr(MutexExp, nullptr); return; } @@ -501,7 +501,7 @@ private: CallCtx.FunArgs = CE->getArgs(); } else if (const CXXConstructExpr *CE = dyn_cast(DeclExp)) { - CallCtx.SelfArg = 0; // Will be set below + CallCtx.SelfArg = nullptr; // Will be set below CallCtx.NumArgs = CE->getNumArgs(); CallCtx.FunArgs = CE->getArgs(); } else if (D && isa(D)) { @@ -517,16 +517,16 @@ private: CallCtx.SelfArg = &SelfDRE; // If the attribute has no arguments, then assume the argument is "this". - if (MutexExp == 0) - buildSExpr(CallCtx.SelfArg, 0); + if (!MutexExp) + buildSExpr(CallCtx.SelfArg, nullptr); else // For most attributes. buildSExpr(MutexExp, &CallCtx); return; } // If the attribute has no arguments, then assume the argument is "this". - if (MutexExp == 0) - buildSExpr(CallCtx.SelfArg, 0); + if (!MutexExp) + buildSExpr(CallCtx.SelfArg, nullptr); else // For most attributes. buildSExpr(MutexExp, &CallCtx); } @@ -544,8 +544,8 @@ public: /// occurs. /// \param D The declaration to which the lock/unlock attribute is attached. /// Caller must check isValid() after construction. - SExpr(const Expr* MutexExp, const Expr *DeclExp, const NamedDecl* D, - VarDecl *SelfDecl=0) { + SExpr(const Expr *MutexExp, const Expr *DeclExp, const NamedDecl *D, + VarDecl *SelfDecl = nullptr) { buildSExprFromExpr(MutexExp, DeclExp, D, SelfDecl); } @@ -962,7 +962,7 @@ public: // Create reference to previous definition VarDefinition(const NamedDecl *D, unsigned R, Context C) - : Dec(D), Exp(0), Ref(R), Ctx(C) + : Dec(D), Exp(nullptr), Ref(R), Ctx(C) { } }; @@ -975,14 +975,14 @@ private: public: LocalVariableMap() { // index 0 is a placeholder for undefined variables (aka phi-nodes). - VarDefinitions.push_back(VarDefinition(0, 0u, getEmptyContext())); + VarDefinitions.push_back(VarDefinition(nullptr, 0u, getEmptyContext())); } /// Look up a definition, within the given context. const VarDefinition* lookup(const NamedDecl *D, Context Ctx) { const unsigned *i = Ctx.lookup(D); if (!i) - return 0; + return nullptr; assert(*i < VarDefinitions.size()); return &VarDefinitions[*i]; } @@ -993,7 +993,7 @@ public: const Expr* lookupExpr(const NamedDecl *D, Context &Ctx) { const unsigned *P = Ctx.lookup(D); if (!P) - return 0; + return nullptr; unsigned i = *P; while (i > 0) { @@ -1003,7 +1003,7 @@ public: } i = VarDefinitions[i].Ref; } - return 0; + return nullptr; } Context getEmptyContext() { return ContextFactory.getEmptyMap(); } @@ -1296,7 +1296,7 @@ void LocalVariableMap::traverseCFG(CFG *CFGraph, for (CFGBlock::const_pred_iterator PI = CurrBlock->pred_begin(), PE = CurrBlock->pred_end(); PI != PE; ++PI) { // if *PI -> CurrBlock is a back edge, so skip it - if (*PI == 0 || !VisitedBlocks.alreadySet(*PI)) { + if (*PI == nullptr || !VisitedBlocks.alreadySet(*PI)) { HasBackEdges = true; continue; } @@ -1322,7 +1322,7 @@ void LocalVariableMap::traverseCFG(CFG *CFGraph, createReferenceContext(CurrBlockInfo->EntryContext); // Create a starting context index for the current block - saveContext(0, CurrBlockInfo->EntryContext); + saveContext(nullptr, CurrBlockInfo->EntryContext); CurrBlockInfo->EntryIndex = getContextIndex(); // Visit all the statements in the basic block. @@ -1345,7 +1345,7 @@ void LocalVariableMap::traverseCFG(CFG *CFGraph, for (CFGBlock::const_succ_iterator SI = CurrBlock->succ_begin(), SE = CurrBlock->succ_end(); SI != SE; ++SI) { // if CurrBlock -> *SI is *not* a back edge - if (*SI == 0 || !VisitedBlocks.alreadySet(*SI)) + if (*SI == nullptr || !VisitedBlocks.alreadySet(*SI)) continue; CFGBlock *FirstLoopBlock = *SI; @@ -1357,7 +1357,7 @@ void LocalVariableMap::traverseCFG(CFG *CFGraph, // Put an extra entry at the end of the indexed context array unsigned exitID = CFGraph->getExit().getBlockID(); - saveContext(0, BlockInfo[exitID].ExitContext); + saveContext(nullptr, BlockInfo[exitID].ExitContext); } /// Find the appropriate source locations to use when producing diagnostics for @@ -1423,7 +1423,7 @@ public: template void getMutexIDs(MutexIDList &Mtxs, AttrType *Attr, Expr *Exp, - const NamedDecl *D, VarDecl *SelfDecl=0); + const NamedDecl *D, VarDecl *SelfDecl = nullptr); template void getMutexIDs(MutexIDList &Mtxs, AttrType *Attr, Expr *Exp, @@ -1603,9 +1603,10 @@ void ThreadSafetyAnalyzer::getMutexIDs(MutexIDList &Mtxs, AttrType *Attr, VarDecl *SelfDecl) { if (Attr->args_size() == 0) { // The mutex held is the "this" object. - SExpr Mu(0, Exp, D, SelfDecl); + SExpr Mu(nullptr, Exp, D, SelfDecl); if (!Mu.isValid()) - SExpr::warnInvalidLock(Handler, 0, Exp, D, ClassifyDiagnostic(Attr)); + SExpr::warnInvalidLock(Handler, nullptr, Exp, D, + ClassifyDiagnostic(Attr)); else Mtxs.push_back_nodup(Mu); return; @@ -1675,7 +1676,7 @@ const CallExpr* ThreadSafetyAnalyzer::getTrylockCallExpr(const Stmt *Cond, LocalVarContext C, bool &Negate) { if (!Cond) - return 0; + return nullptr; if (const CallExpr *CallExp = dyn_cast(Cond)) { return CallExp; @@ -1698,7 +1699,7 @@ const CallExpr* ThreadSafetyAnalyzer::getTrylockCallExpr(const Stmt *Cond, Negate = !Negate; return getTrylockCallExpr(UOP->getSubExpr(), C, Negate); } - return 0; + return nullptr; } else if (const BinaryOperator *BOP = dyn_cast(Cond)) { if (BOP->getOpcode() == BO_EQ || BOP->getOpcode() == BO_NE) { @@ -1715,7 +1716,7 @@ const CallExpr* ThreadSafetyAnalyzer::getTrylockCallExpr(const Stmt *Cond, if (!TCond) Negate = !Negate; return getTrylockCallExpr(BOP->getRHS(), C, Negate); } - return 0; + return nullptr; } if (BOP->getOpcode() == BO_LAnd) { // LHS must have been evaluated in a different block. @@ -1724,9 +1725,9 @@ const CallExpr* ThreadSafetyAnalyzer::getTrylockCallExpr(const Stmt *Cond, if (BOP->getOpcode() == BO_LOr) { return getTrylockCallExpr(BOP->getRHS(), C, Negate); } - return 0; + return nullptr; } - return 0; + return nullptr; } @@ -1817,7 +1818,7 @@ class BuildLockset : public StmtVisitor { void checkAccess(const Expr *Exp, AccessKind AK); void checkPtAccess(const Expr *Exp, AccessKind AK); - void handleCall(Expr *Exp, const NamedDecl *D, VarDecl *VD = 0); + void handleCall(Expr *Exp, const NamedDecl *D, VarDecl *VD = nullptr); public: BuildLockset(ThreadSafetyAnalyzer *Anlzr, CFGBlockInfo &Info) @@ -2084,7 +2085,7 @@ void BuildLockset::handleCall(Expr *Exp, const NamedDecl *D, VarDecl *VD) { if (isScopedVar) { SourceLocation MLoc = VD->getLocation(); DeclRefExpr DRE(VD, false, VD->getType(), VK_LValue, VD->getLocation()); - SExpr SMutex(&DRE, 0, 0); + SExpr SMutex(&DRE, nullptr, nullptr); for (const auto &M : ExclusiveLocksToAdd) Analyzer->addLock(FSet, SMutex, LockData(MLoc, LK_Exclusive, M), @@ -2399,7 +2400,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) { Loc = Attr->getLocation(); if (const auto *A = dyn_cast(Attr)) { getMutexIDs(A->isShared() ? SharedLocksToAdd : ExclusiveLocksToAdd, A, - 0, D); + nullptr, D); CapDiagKind = ClassifyDiagnostic(A); } else if (const auto *A = dyn_cast(Attr)) { // UNLOCK_FUNCTION() is used to hide the underlying lock implementation. @@ -2573,7 +2574,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) { SE = CurrBlock->succ_end(); SI != SE; ++SI) { // if CurrBlock -> *SI is *not* a back edge - if (*SI == 0 || !VisitedBlocks.alreadySet(*SI)) + if (*SI == nullptr || !VisitedBlocks.alreadySet(*SI)) continue; CFGBlock *FirstLoopBlock = *SI; diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 29c17c3765..4b8a59c398 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -236,7 +236,7 @@ void DataflowWorklist::enqueueSuccessors(const clang::CFGBlock *block) { } const CFGBlock *DataflowWorklist::dequeue() { - const CFGBlock *B = 0; + const CFGBlock *B = nullptr; // First dequeue from the worklist. This can represent // updates along backedges that we want propagated as quickly as possible. @@ -250,7 +250,7 @@ const CFGBlock *DataflowWorklist::dequeue() { ++PO_I; } else { - return 0; + return nullptr; } assert(enqueuedBlocks[B->getBlockID()] == true); @@ -295,7 +295,7 @@ static FindVarResult findVar(const Expr *E, const DeclContext *DC) { if (const VarDecl *VD = dyn_cast(DRE->getDecl())) if (isTrackedVar(VD, DC)) return FindVarResult(VD, DRE); - return FindVarResult(0, 0); + return FindVarResult(nullptr, nullptr); } /// \brief Classify each DeclRefExpr as an initialization or a use. Any @@ -353,7 +353,7 @@ static const DeclRefExpr *getSelfInitExpr(VarDecl *VD) { if (DRE && DRE->getDecl() == VD) return DRE; } - return 0; + return nullptr; } void ClassifyRefs::classify(const Expr *E, Class C) { @@ -542,7 +542,7 @@ public: // This block initializes the variable. continue; if (AtPredExit == MayUninitialized && - vals.getValue(B, 0, vd) == Uninitialized) { + vals.getValue(B, nullptr, vd) == Uninitialized) { // This block declares the variable (uninitialized), and is reachable // from a block that initializes the variable. We can't guarantee to // give an earlier location for the diagnostic (and it appears that