[clang] [Clang]Preserve array information when reconstructing LValues (#223064) (PR #230599)

Chen Miao via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 24 10:34:40 PDT 2026


================
@@ -209,10 +208,6 @@ namespace {
         ArraySize = 0;
         MostDerivedLength = I + 1;
         IsArray = false;
-      } else {
-        // Path[I] describes a base class.
----------------
ChenMiaoi wrote:

Could we retain the else branch with a comment explaining why base-class path entries must preserve the most-derived object's array information?

For example, whether the pointer refers to the A base subobject of `b[0]`, `b.item[0]` or `b[0].item[0]`, the most-derived object is still an array element:

``` txt
b → [0] → A
b → item → [0] → A
b → [0] → item → [0] → A
```

Entering the base subobject does not change that, so its most-derived object's array information should be preserved.

Removing the assignments also affects some cases. For example, this valid code currently compiles:

``` cc
struct A { int n; };
struct B : A {} b[2];

constexpr int f() {
  A *p = b;
  return p - p;
}

static_assert(f() == 0);
```

Could you also check whether removing the code in this branch causes issues in any other cases?



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


More information about the cfe-commits mailing list