There is a difference between a Pointer and a "Pointer to the first element of an array".
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
There is a difference between a Pointer and a "Pointer to the first element of an array".
I'm pretty confused because this statement is false per the language standard (http://eel.is/c++draft/expr.sub#2). Basically, array subscripting works through pointer arithmetic, so &array[0] and array (decayed to a pointer) have the same value. Why do we need to offset to get to the first element in the interpreter?
That's just an implementation detail in the Pointer class. For primitive arrays, we need the sizeof(InitMap*) applied, which happens via atIndex(). Otherwise, deref() will look at the first few bytes of the InitMap* pointer.
I've added some documentation about this in https://reviews.llvm.org/D135750 (and the MetadataSize added to Descriptor there could be used to clean this up I think).
clang/lib/AST/Interp/Interp.h | ||
---|---|---|
966–967 ↗ | (On Diff #472007) | So why don't we need to do this dance for Store/StorePop? |
clang/lib/AST/Interp/Interp.h | ||
---|---|---|
966–967 ↗ | (On Diff #472007) | We do, I just realized. It might make more sense to do this in Pointer::deref() directly, so 'deref()`'ing an array always returns the first element. |