MSan cannot detect the uninitialized memory access in the example, because the entire main function is marked by IPSCCP as unreachable (since x==y is a branch on undef, both branches are removed), long before the MSan pass has a chance to instrument the code.
Note that when the example is compiled at -O1 without MSan, the program has no output whatsoever.
Reproducer
Since late June 2022, this example is no longer caught by MSan with
clang -O1 -fsanitize=memory
:edit: the example can be further simplified by removing the variable
y
, and simply comparingx == 0
Root Cause
This is due to
MSan cannot detect the uninitialized memory access in the example, because the entire main function is marked by IPSCCP as unreachable (since
x==y
is a branch on undef, both branches are removed), long before the MSan pass has a chance to instrument the code.Note that when the example is compiled at -O1 without MSan, the program has no output whatsoever.
IR Dump
Immediately prior to IPSCCP:
After IPSCCP (clang before 1f88d804083a8a1b68df1e6677920e38ab2a6b40):
After IPSCCP (clang at/after 1f88d804083a8a1b68df1e6677920e38ab2a6b40):