Addressable constructors needed for borrowed slice data in gccrs
GCC Rust's constant evaluation now handles borrowed slice data correctly by making constructors addressable.
Philip Herron fixed an issue in gccrs where constructors used for borrowed slice data were not properly addressable during constant evaluation.
When compiling constant expressions involving slices, gccrs needs these constructors to be addressable objects, similar to temporary variables, which GCC’s regular compilation optimizes away.
This commit makes these constructor expressions addressable, resolving issues 4867 and 4868 and adding a new test case.
In Details
The gccrs compiler's constant evaluation backend (rust-constexpr.cc) has been updated to handle cases where constructors are used for borrowed slice data. In constant evaluation, the compiler expects such data pointers (originating from constructor expressions, e.g., for slices) to refer to addressable objects, akin to temporaries. While standard GCC compilation might optimize away the need for explicit temporaries here, constant evaluation requires them. This commit ensures these constructor expressions are made addressable, fixing related issues (4867, 4868) and adding a test.
- constant evaluation
- The process by which the compiler computes the value of expressions at compile time, rather than at runtime. This is typically done for
constvariables and expressions in languages like Rust. - slice
- A dynamically-sized view into a contiguous sequence of elements in Rust. Slices are represented by a pointer to the data and a length.
- constructor expression
- An expression that creates and initializes an object. In C++, this refers to calling a constructor; in Rust, it could refer to struct initialization or creating types via functions.
- addressable
- In the context of memory, an 'addressable' object is one that has a specific memory address that can be taken (e.g., via the '&' operator in C++ or '&' in Rust). This is often required for pointers and references.