Issue |
63471
|
Summary |
-ftrivial-auto-var-init=zero issues with pointers to data members
|
Labels |
new issue
|
Assignees |
|
Reporter |
dangelog
|
I can't find accurate documentation for what `-ftrivial-auto-var-init=zero` is *meant* to do; https://clang.llvm.org/docs/ClangCommandLineReference.html simply says
> Initialize trivial automatic stack variables. Defaults to ‘uninitialized’. <arg> must be ‘uninitialized’, ‘zero’ or ‘pattern’.
I assume that means to `memset(0)` their storage. 0 is a bit pattern that works _almost_ universally to set a "safe" default. However, pointers to data members are a problem: on Itanium, a null pointer to data member is represented by `-1u`, and not `0`.
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#data-member-pointers
This means that this snippet hits the assert under -ftrivial-auto-var-init=zero:
```
#include <cassert>
struct S {};
int main() {
int S::*ptr;
assert(ptr == nullptr);
}
```
https://gcc.godbolt.org/z/7sb6GcbPE
IMHO it would be more useful to have `-ftrivial-auto-var-init=zero` to mean "to _value-initialize_ automatic variables", including non-static data members of classes, recursively, before a constructor is eventually run.
Such value-initialization for scalar taypes resolves into zero-initialization (and *not* zero-filling), as per https://eel.is/c++draft/dcl.init#general-9.3 , so the name "=zero" is still somehow appropriate. The difference is that zero-initialization will correctly sets *all* pointers types to null.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs