r283554 - [analyzer] Don't merge different return nodes in ExplodedGraph

Galina Kistanova via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 7 11:29:40 PDT 2016


Hi Daniel,

This revision introduced warnings on one our of builders:
http://lab.llvm.org:8011/builders/clang-3stage-ubuntu/builds/4719

The warnings:

/home/buildbot/Buildbot/Slave1a/clang-3stage-ubuntu/llvm.src/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:316:59:
warning: suggest parentheses around assignment used as truth value
[-Wparentheses]
/home/buildbot/Buildbot/Slave1a/clang-3stage-ubuntu/llvm.src/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:316:16:
warning: using the result of an assignment as a condition without
parentheses [-Wparentheses]
1 warning generated.
/home/buildbot/Buildbot/Slave1a/clang-3stage-ubuntu/llvm.src/tools/clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:316:16:
warning: using the result of an assignment as a condition without
parentheses [-Wparentheses]
1 warning generated.

Please have a look?

Thanks

Galina



On Fri, Oct 7, 2016 at 7:21 AM, Daniel Marjamaki via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: danielmarjamaki
> Date: Fri Oct  7 09:21:08 2016
> New Revision: 283554
>
> URL: http://llvm.org/viewvc/llvm-project?rev=283554&view=rev
> Log:
> [analyzer] Don't merge different return nodes in ExplodedGraph
>
> Returns when calling an inline function should not be merged in the
> ExplodedGraph unless they are same.
>
> Differential Revision: https://reviews.llvm.org/D25326
>
> Modified:
>     cfe/trunk/include/clang/Analysis/ProgramPoint.h
>     cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
>     cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
>     cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
>     cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp
>     cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
>     cfe/trunk/test/Analysis/inlining/InlineObjCClassMethod.m
>     cfe/trunk/test/Analysis/unreachable-code-path.c
>
> Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Analysis/ProgramPoint.h?rev=283554&r1=283553&r2=283554&view=diff
> ============================================================
> ==================
> --- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
> +++ cfe/trunk/include/clang/Analysis/ProgramPoint.h Fri Oct  7 09:21:08
> 2016
> @@ -622,8 +622,8 @@ private:
>  class CallExitBegin : public ProgramPoint {
>  public:
>    // CallExitBegin uses the callee's location context.
> -  CallExitBegin(const StackFrameContext *L)
> -    : ProgramPoint(nullptr, CallExitBeginKind, L, nullptr) {}
> +  CallExitBegin(const StackFrameContext *L, const ReturnStmt *RS)
> +    : ProgramPoint(RS, CallExitBeginKind, L, nullptr) { }
>
>  private:
>    friend class ProgramPoint;
>
> Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/
> PathSensitive/CoreEngine.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h?
> rev=283554&r1=283553&r2=283554&view=diff
> ============================================================
> ==================
> --- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
> (original)
> +++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
> Fri Oct  7 09:21:08 2016
> @@ -109,7 +109,8 @@ private:
>    CoreEngine(const CoreEngine &) = delete;
>    void operator=(const CoreEngine &) = delete;
>
> -  ExplodedNode *generateCallExitBeginNode(ExplodedNode *N);
> +  ExplodedNode *generateCallExitBeginNode(ExplodedNode *N,
> +                                          const ReturnStmt *RS);
>
>  public:
>    /// Construct a CoreEngine object to analyze the provided CFG.
> @@ -172,7 +173,7 @@ public:
>
>    /// \brief enqueue the nodes corresponding to the end of function onto
> the
>    /// end of path / work list.
> -  void enqueueEndOfFunction(ExplodedNodeSet &Set);
> +  void enqueueEndOfFunction(ExplodedNodeSet &Set, const ReturnStmt *RS);
>
>    /// \brief Enqueue a single node created as a result of statement
> processing.
>    void enqueueStmtNode(ExplodedNode *N, const CFGBlock *Block, unsigned
> Idx);
>
> Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/
> PathSensitive/ExprEngine.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h?
> rev=283554&r1=283553&r2=283554&view=diff
> ============================================================
> ==================
> --- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
> (original)
> +++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
> Fri Oct  7 09:21:08 2016
> @@ -262,7 +262,8 @@ public:
>    /// Called by CoreEngine.  Used to notify checkers that processing a
>    /// function has ended. Called for both inlined and and top-level
> functions.
>    void processEndOfFunction(NodeBuilderContext& BC,
> -                            ExplodedNode *Pred) override;
> +                            ExplodedNode *Pred,
> +                            const ReturnStmt *RS=nullptr) override;
>
>    /// Remove dead bindings/symbols before exiting a function.
>    void removeDeadOnEndOfFunction(NodeBuilderContext& BC,
>
> Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/
> PathSensitive/SubEngine.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h?rev=
> 283554&r1=283553&r2=283554&view=diff
> ============================================================
> ==================
> --- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
> (original)
> +++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
> Fri Oct  7 09:21:08 2016
> @@ -109,7 +109,8 @@ public:
>    /// Called by CoreEngine.  Used to notify checkers that processing a
>    /// function has ended. Called for both inlined and and top-level
> functions.
>    virtual void processEndOfFunction(NodeBuilderContext& BC,
> -                                    ExplodedNode *Pred) = 0;
> +                                    ExplodedNode *Pred,
> +                                    const ReturnStmt *RS = nullptr) = 0;
>
>    // Generate the entry node of the callee.
>    virtual void processCallEnter(NodeBuilderContext& BC, CallEnter CE,
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> StaticAnalyzer/Core/CoreEngine.cpp?rev=283554&r1=
> 283553&r2=283554&view=diff
> ============================================================
> ==================
> --- cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp Fri Oct  7 09:21:08
> 2016
> @@ -309,8 +309,19 @@ void CoreEngine::HandleBlockEdge(const B
>      assert (L.getLocationContext()->getCFG()->getExit().size() == 0
>              && "EXIT block cannot contain Stmts.");
>
> +    // Get return statement..
> +    const ReturnStmt *RS = nullptr;
> +    if (!L.getSrc()->empty()) {
> +      if (Optional<CFGStmt> LastStmt = L.getSrc()->back().getAs<CFGStmt>())
> {
> +        if (RS = dyn_cast<ReturnStmt>(LastStmt->getStmt())) {
> +          if (!RS->getRetValue())
> +            RS = nullptr;
> +        }
> +      }
> +    }
> +
>      // Process the final state transition.
> -    SubEng.processEndOfFunction(BuilderCtx, Pred);
> +    SubEng.processEndOfFunction(BuilderCtx, Pred, RS);
>
>      // This path is done. Don't enqueue any more nodes.
>      return;
> @@ -589,13 +600,14 @@ void CoreEngine::enqueueStmtNode(Explode
>      WList->enqueue(Succ, Block, Idx+1);
>  }
>
> -ExplodedNode *CoreEngine::generateCallExitBeginNode(ExplodedNode *N) {
> +ExplodedNode *CoreEngine::generateCallExitBeginNode(ExplodedNode *N,
> +                                                    const ReturnStmt *RS)
> {
>    // Create a CallExitBegin node and enqueue it.
>    const StackFrameContext *LocCtx
>                           = cast<StackFrameContext>(N->
> getLocationContext());
>
>    // Use the callee location context.
> -  CallExitBegin Loc(LocCtx);
> +  CallExitBegin Loc(LocCtx, RS);
>
>    bool isNew;
>    ExplodedNode *Node = G.getNode(Loc, N->getState(), false, &isNew);
> @@ -619,12 +631,12 @@ void CoreEngine::enqueue(ExplodedNodeSet
>    }
>  }
>
> -void CoreEngine::enqueueEndOfFunction(ExplodedNodeSet &Set) {
> +void CoreEngine::enqueueEndOfFunction(ExplodedNodeSet &Set, const
> ReturnStmt *RS) {
>    for (ExplodedNodeSet::iterator I = Set.begin(), E = Set.end(); I != E;
> ++I) {
>      ExplodedNode *N = *I;
>      // If we are in an inlined call, generate CallExitBegin node.
>      if (N->getLocationContext()->getParent()) {
> -      N = generateCallExitBeginNode(N);
> +      N = generateCallExitBeginNode(N, RS);
>        if (N)
>          WList->enqueue(N);
>      } else {
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> StaticAnalyzer/Core/ExprEngine.cpp?rev=283554&r1=
> 283553&r2=283554&view=diff
> ============================================================
> ==================
> --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Fri Oct  7 09:21:08
> 2016
> @@ -1766,7 +1766,8 @@ void ExprEngine::processBeginOfFunction(
>  /// ProcessEndPath - Called by CoreEngine.  Used to generate end-of-path
>  ///  nodes when the control reaches the end of a function.
>  void ExprEngine::processEndOfFunction(NodeBuilderContext& BC,
> -                                      ExplodedNode *Pred) {
> +                                      ExplodedNode *Pred,
> +                                      const ReturnStmt *RS) {
>    // FIXME: Assert that stackFrameDoesNotContainInitia
> lizedTemporaries(*Pred)).
>    // We currently cannot enable this assert, as lifetime extended
> temporaries
>    // are not modelled correctly.
> @@ -1788,7 +1789,7 @@ void ExprEngine::processEndOfFunction(No
>      getCheckerManager().runCheckersForEndFunction(BC, Dst, Pred, *this);
>    }
>
> -  Engine.enqueueEndOfFunction(Dst);
> +  Engine.enqueueEndOfFunction(Dst, RS);
>  }
>
>  /// ProcessSwitch - Called by CoreEngine.  Used to generate successor
>
> Modified: cfe/trunk/test/Analysis/inlining/InlineObjCClassMethod.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/
> InlineObjCClassMethod.m?rev=283554&r1=283553&r2=283554&view=diff
> ============================================================
> ==================
> --- cfe/trunk/test/Analysis/inlining/InlineObjCClassMethod.m (original)
> +++ cfe/trunk/test/Analysis/inlining/InlineObjCClassMethod.m Fri Oct  7
> 09:21:08 2016
> @@ -174,12 +174,12 @@ int foo4() {
>  @implementation MyClassSelf
>  + (int)testClassMethodByKnownVarDecl {
>    int y = [MyParentSelf testSelf];
> -  return 5/y; // Should warn here.
> +  return 5/y; // expected-warning{{Division by zero}}
>  }
>  @end
>  int foo2() {
>    int y = [MyParentSelf testSelf];
> -  return 5/y; // Should warn here.
> +  return 5/y; // expected-warning{{Division by zero}}
>  }
>
>  // TODO: We do not inline 'getNum' in the following case, where the value
> of
>
> Modified: cfe/trunk/test/Analysis/unreachable-code-path.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> Analysis/unreachable-code-path.c?rev=283554&r1=283553&r2=283554&view=diff
> ============================================================
> ==================
> --- cfe/trunk/test/Analysis/unreachable-code-path.c (original)
> +++ cfe/trunk/test/Analysis/unreachable-code-path.c Fri Oct  7 09:21:08
> 2016
> @@ -194,3 +194,15 @@ void test12(int x) {
>      break;
>    }
>  }
> +
> +// Don't merge return nodes in ExplodedGraph unless they are same.
> +extern int table[];
> +static int inlineFunction(const int i) {
> +  if (table[i] != 0)
> +    return 1;
> +  return 0;
> +}
> +void test13(int i) {
> +  int x = inlineFunction(i);
> +  x && x < 10; // no-warning
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161007/53a10fa4/attachment-0001.html>


More information about the cfe-commits mailing list