Issue 179581
Summary MSan: false negative on bitfields
Labels compiler-rt:msan, false-negative
Assignees
Reporter yus3710-fj
    This looks similar to #39856, but it would not be the same.
(FYI: #39856 is not reproducible on my environment now.)

MemorySanitizer does not detect the use of an uninitialized value when `-O2` or higher is specified.

```cpp
typedef struct {unsigned char a:3; unsigned char b:6;} ss;
__attribute__((noinline))
int foo(ss* sp) {
  sp->a=0b101;
  return 0;
}
int main() {
  ss s;
  s.a = 0b101;
  foo(&s);
  if (s.b) return 1;
  return 0;
}
```

```console
$ clang++ -O2 -fsanitize=memory -g test.cc && ./a.out 
$ clang++ -O1 -fsanitize=memory -g test.cc && ./a.out 
==404358==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55a10938daf8 in main /path/to/test.cc:14:1
    #1 0x7f37cd663d8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 4f7b0c955c3d81d7cac1501a2498b69d1d82bfe7)
    #2 0x7f37cd663e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 4f7b0c955c3d81d7cac1501a2498b69d1d82bfe7)
    #3 0x55a1092f1114 in _start (/path/to/a.out+0x6f114)
SUMMARY: MemorySanitizer: use-of-uninitialized-value /path/to/test.cc:14:1 in main
Exiting
```

I can reproduce this on x86 and aarch64.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to