<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63471>63471</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            -ftrivial-auto-var-init=zero issues with pointers to data members
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          dangelog
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVV9v4zYM_zTKCxHDkRMnechD2zS7Ahs27O69oGXa1k6WDIlOr_fpB9ppc-263YDAgcT__P1IYUq29UQHtblVm-MCR-5CPNToW3KhXVShfj48gEGv9Jahsb4GNGaMyAR1MGNPnpFt8NCECE8dMqgyXzYc7dmiW-LIYXnGuLTesiqO3ykGVe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