From: Ted Kremenek Date: Wed, 27 Feb 2008 20:43:44 +0000 (+0000) Subject: End paths when calling a function marked "noreturn." X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=affb2159712b2373a18a89ed205c1a309d3aec12;p=clang End paths when calling a function marked "noreturn." git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47690 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/GRExprEngine.cpp b/Analysis/GRExprEngine.cpp index f227160bfb..45dbac7045 100644 --- a/Analysis/GRExprEngine.cpp +++ b/Analysis/GRExprEngine.cpp @@ -550,6 +550,21 @@ void GRExprEngine::VisitCall(CallExpr* CE, NodeTy* Pred, else St = EvalCall(CE, cast(L), (*DI)->getState()); + // Check for the "noreturn" attribute. + + if (isa(L)) + if (cast(L).getDecl()->getAttr()) { + + NodeTy* N = Builder->generateNode(CE, St, *DI); + + if (N) { + N->markAsSink(); + NoReturnCalls.insert(N); + } + + continue; + } + Nodify(Dst, CE, *DI, St); } } diff --git a/include/clang/Analysis/PathSensitive/GRExprEngine.h b/include/clang/Analysis/PathSensitive/GRExprEngine.h index 13abf53cb3..6b96ccf201 100644 --- a/include/clang/Analysis/PathSensitive/GRExprEngine.h +++ b/include/clang/Analysis/PathSensitive/GRExprEngine.h @@ -87,20 +87,25 @@ protected: /// CurrentStmt - The current block-level statement. Stmt* CurrentStmt; + + typedef llvm::SmallPtrSet UninitBranchesTy; + typedef llvm::SmallPtrSet UninitStoresTy; + typedef llvm::SmallPtrSet BadDerefTy; + typedef llvm::SmallPtrSet BadDividesTy; + typedef llvm::SmallPtrSet NoReturnCallsTy; /// UninitBranches - Nodes in the ExplodedGraph that result from /// taking a branch based on an uninitialized value. - typedef llvm::SmallPtrSet UninitBranchesTy; UninitBranchesTy UninitBranches; - - typedef llvm::SmallPtrSet UninitStoresTy; - typedef llvm::SmallPtrSet BadDerefTy; - typedef llvm::SmallPtrSet BadDividesTy; /// UninitStores - Sinks in the ExplodedGraph that result from /// making a store to an uninitialized lvalue. UninitStoresTy UninitStores; + /// NoReturnCalls - Sinks in the ExplodedGraph that result from + // calling a function with the attribute "noreturn". + NoReturnCallsTy NoReturnCalls; + /// ImplicitNullDeref - Nodes in the ExplodedGraph that result from /// taking a dereference on a symbolic pointer that MAY be NULL. BadDerefTy ImplicitNullDeref; @@ -176,6 +181,10 @@ public: return N->isSink() && BadDivides.count(const_cast(N)) != 0; } + bool isNoReturnCall(const NodeTy* N) const { + return N->isSink() && NoReturnCalls.count(const_cast(N)) != 0; + } + typedef BadDerefTy::iterator null_deref_iterator; null_deref_iterator null_derefs_begin() { return ExplicitNullDeref.begin(); } null_deref_iterator null_derefs_end() { return ExplicitNullDeref.end(); }