[clang] [clang][dataflow] When analyzing ctors, don't initialize fields of `*this` with values. (PR #84164)

via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 7 05:06:18 PST 2024


================
@@ -414,8 +414,15 @@ void Environment::initialize() {
       }
     } else if (MethodDecl->isImplicitObjectMemberFunction()) {
       QualType ThisPointeeType = MethodDecl->getFunctionObjectParameterType();
-      setThisPointeeStorageLocation(
-          cast<RecordStorageLocation>(createObject(ThisPointeeType)));
+      auto &ThisLoc =
+          cast<RecordStorageLocation>(createStorageLocation(ThisPointeeType));
+      setThisPointeeStorageLocation(ThisLoc);
+      refreshRecordValue(ThisLoc, *this);
+      // Initialize fields of `*this` with values, but only if we're not
+      // analyzing a constructor; after all, it's the constructor's job to do
----------------
martinboehme wrote:

Do you mean something like this?

```cxx
struct S {
    S() {}
    int i = 1;
};
```

If so, the answer is yes:

```
  |-CXXConstructorDecl <line:2:5, col:10> col:5 S 'void ()' implicit-inline
  | |-CXXCtorInitializer Field 0xc1eeb90 'i' 'int'
  | | `-CXXDefaultInitExpr <col:5> 'int' has rewritten init
  | |   `-IntegerLiteral <line:3:13> 'int' 1
  | `-CompoundStmt <line:2:9, col:10>
```

https://godbolt.org/z/oYP66fMjT

https://github.com/llvm/llvm-project/pull/84164


More information about the cfe-commits mailing list