[clang] [analyzer] Do list initialization for CXXNewExpr with initializer list arg (PR #127702)

Michael Flanders via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 28 07:52:17 PST 2025


================
@@ -254,6 +254,224 @@ void foo() {
 }
 } // namespace CXX17_aggregate_construction
 
+namespace newexpr_init_list_initialization {
----------------
Flandini wrote:

They currently take different code paths and have different results in CSA. I think ideally they would use the same code.

The issue this PR is for doesn't properly initialize in this case:
```
struct S {
  int foo;
  int bar;
};

void f() {
  S *s = new S{
      .foo = 13,
      .bar = 1,
  };
  int retval = s->bar;
  delete s;
}
```

But if you change remove this new expression and list initialize some `S` with automatic storage duration, this works as expected.

I plan to change the two to use the same binding code, but I think there would still be some differences in the code in expr engine.

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


More information about the cfe-commits mailing list