[PATCH] D63538: [analyzer][CFG] Return the correct terminator condition

Kristóf Umann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 19 02:46:41 PDT 2019


Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, a_sidorin, baloghadamsoftware, rnkovacs, dcoughlin.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, Charusso, gamesh411, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, szepet, whisperity.

For the following terminator statement:

  if (A && B && C && D)

The built CFG is the following:

  [B5 (ENTRY)]
    Succs (1): B4
  
  [B1]
    1: 10
    2: j
    3: [B1.2] (ImplicitCastExpr, LValueToRValue, int)
    4: [B1.1] / [B1.3]
    5: int x = 10 / j;
    Preds (1): B2
    Succs (1): B0
  
  [B2]
    1: C
    2: [B2.1] (ImplicitCastExpr, LValueToRValue, _Bool)
    T: if [B4.4] && [B3.2] && [B2.2]
    Preds (1): B3
    Succs (2): B1 B0
  
  [B3]
    1: B
    2: [B3.1] (ImplicitCastExpr, LValueToRValue, _Bool)
    T: [B4.4] && [B3.2] && ...
    Preds (1): B4
    Succs (2): B2 B0
  
  [B4]
    1: 0
    2: int j = 0;
    3: A
    4: [B4.3] (ImplicitCastExpr, LValueToRValue, _Bool)
    T: [B4.4] && ...
    Preds (1): B5
    Succs (2): B3 B0
  
  [B0 (EXIT)]
    Preds (4): B1 B2 B3 B4

However, even though the path of execution in B2 <https://reviews.llvm.org/B2> only depends on C's value, `CFGBlock::getCondition()` would return the entire condition (`A && B && C`). For B3 <https://reviews.llvm.org/B3>, it would return `A && B`. I changed this the actual condition.

The tests show an addition of an extra arrow for `ObjCForCollectionStmt`, all of them similar to this:
F9306419: image.png <https://reviews.llvm.org/F9306419>
(the first arrow the addition)


Repository:
  rC Clang

https://reviews.llvm.org/D63538

Files:
  clang/include/clang/Analysis/CFG.h
  clang/lib/Analysis/CFG.cpp
  clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
  clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63538.205517.patch
Type: text/x-patch
Size: 23033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190619/0059b0c0/attachment-0001.bin>


More information about the cfe-commits mailing list