[all-commits] [llvm/llvm-project] c3dd2f: [analyzer] Model lifetime of a variable declared i...

tomasz-kaminski-sonarsource via All-commits all-commits at lists.llvm.org
Wed Jul 19 00:06:16 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c3dd2f35b876f9af39c01de49941a3920fd59a33
      https://github.com/llvm/llvm-project/commit/c3dd2f35b876f9af39c01de49941a3920fd59a33
  Author: tomasz-kaminski-sonarsource <79814193+tomasz-kaminski-sonarsource at users.noreply.github.com>
  Date:   2023-07-19 (Wed, 19 Jul 2023)

  Changed paths:
    M clang/lib/Analysis/CFG.cpp
    M clang/test/Analysis/auto-obj-dtors-cfg-output.cpp
    M clang/test/Analysis/lifetime-cfg-output.cpp
    M clang/test/Analysis/scopes-cfg-output.cpp

  Log Message:
  -----------
  [analyzer] Model lifetime of a variable declared in for condition in CFG correctly

Per [stmt.for] p1 (https://eel.is/c++draft/stmt.for#1) the following
`for` and `while` statements are equivalent
```
for (; A c = b; b.c) {
  A d;
}

while (A c = b) {
  A d;
  b.c;
}
```
As a consequence, the variable declared for the condition expression
should be destroyed after the increment expression.

This fixed the handling of the object lifetime `continue`, and now
destructors, scope and lifetime elements are present for continue
path in following code:
```
for (; A c = b; b.c) {
  if (cond)
     continue;
  A d;
}
```

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D155547




More information about the All-commits mailing list