<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62579>62579</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
UBSAN does not catch dereferencing nullptr to empty struct when passing by value
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang,
compiler-rt:ubsan
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
joker-eph
</td>
</tr>
</table>
<pre>
```
struct E {};
void foo(E p) {}
void bar(const E &p) {}
int main() {
E *p = nullptr;
foo(*p);
bar(*p);
}
```
Here the call to `foo(*p)` won't trigger UBSAN, but the call to `bar(*p)` will.
I think the reason is that on Itanium ABI the parameter `p` is eliminated when passed by value, but can't be when passed by reference.
Both are UB though, and UBSAN should emit the checks for foo as well.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxkU81uszoQfRqzGSVyhp-EBYvkS6Pbzd1c9QEMTLBbYyN7aNW3vzIk_cknIRDjM-fMObZVjGZwRI0oT6I8Z2pm7UPz6t8obGjSWev7z0ZU8vbIs5DHyGHuGJ5A7E9ifxb5aa2_e9PD1XuBhyeYBNZ3wPdqq4LAQ-ddXPqx-gtmHMOojBN4uC8tdVjwxwlEfgY3Wztx-FKGm2wCCKx_1FfBx_qX2oOz9f0PBQLWBJ2yFtiDqORv_krCh3cC9wwczDBQgJfTf8d_Bf6BdubH5t9DpGZj7RZWtWdgbdzb0hNIRe_ARGCtGLyDZ1bOzCMcT88LYlJBjcQUEu-UuEwEsmY0TjH18KHJwaRipB7aT3hXdqb7VJ1aR27pERboSoFcR9t1ppNnDSoQvJyAtZ8HnTiU61ebELWfbQ80mptXTd1bhKsPaSNARfgga7c_Q836Ju_rvFYZNbvqkOe53FVFphu6VmVHxSFHkhVigVL11aHqe1nvdv2-zEyDEnNZyhLzAotiW9e74lCUpZL1vsKWRCFpVMZurX0ftz4MmYlxpqbCcl9nVrVk43LAETur3CAQBf5Jf36cjKWwCSzy49zGFBCmexCaxLVp5yGKQloTOX6zs2FLzZpE7ymC8ylc7jT0dI_SuOF-TNMpoHHiT7jdnK_0E-i-S9kcbKOZpyjyo8CLwMtgWM_ttvOjwEuSv302U_Cv1LHAy-I0CrwsZv8PAAD__1PuJk8">