[PATCH] D158069: [clang][Interp] Fix getIndex() for composite array elements
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 20 01:31:19 PDT 2023
tbaeder added inline comments.
================
Comment at: clang/lib/AST/Interp/Context.h:88
+ /// Returns the program. This is only needed for unittests.
+ Program &getProgram() const { return *P.get(); }
+
----------------
cor3ntin wrote:
> This should return a const ref
Things like `getGlobal()` aren't const so that doesn't work.
================
Comment at: clang/lib/AST/Interp/Pointer.h:342
+
+ // narrow()ed element in a composite array.
+ if (Base > 0 && Base == Offset)
----------------
cor3ntin wrote:
> Can you be a bit more verbose here? I can't figure out what is happening from the comment!
For primitive arrays, the elements don't have inline descriptors:
```
Offset
│
▼
┌────────┬───┬───┬───┬───┬───┬─────┐
│InitMap │ 1 │ 2 │ 3 │ 4 │ 5 │ ... │
└────────┴───┴───┴───┴───┴───┴─────┘
▲
│
Base
```
If the array elements are composite elements themselves however, we can have a pointer that refers to the array element:
```
Offset
│
▼
┌──────────┬───┬──────────┬───┐
│InlineDesc│'a'│InlineDesc│'b'│
└──────────┴───┴──────────┴───┘
▲
│
Base
```
(so things like `isArrayElement()` return `true`) as well as a pointer that _only_ refers to the composite element (after a call to `narrow()`:
```
Offset
│
▼
┌──────────┬───┬──────────┬───┐
│InlineDesc│'a'│InlineDesc│'b'│
└──────────┴───┴──────────┴───┘
▲
│
Base
```
For the latter, the expected value of `getIndex()` is `0`, since it is (as far as the pointer knows) _not_ an array element.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158069/new/
https://reviews.llvm.org/D158069
More information about the cfe-commits
mailing list