Issue 204217
Summary [MSan] False positive on the padding bits of a non-byte-aligned _BitInt
Labels
Assignees
Reporter xroche
    ## Summary

`_BitInt(N)` is a C/C++ feature for an integer of an exact bit width. When the width is not a multiple of 8 (for example `_BitInt(65)`), the value is stored in a larger block of memory, and the leftover bits are padding that nothing reads. MemorySanitizer (MSan), the tool that catches reads of uninitialized memory, treats those padding bits as uninitialized and reports an error, even though the program only uses the real value bits. Widths that are a multiple of 8 (like `_BitInt(64)`) have no padding and stay clean.

## Reproducer

https://godbolt.org/z/j55MhE5Mc

```cpp
__attribute__((noinline)) static signed _BitInt(65) absbi(signed _BitInt(65) x) {
  return x < 0 ? -x : x;
}
int main() {
  signed _BitInt(65) v = 42;   // fills the 65 value bits; the padding bits stay unset
  return absbi(v) == 42 ? 0 : 1;
}
```

Compiled with `-fsanitize=memory`, this reports `use-of-uninitialized-value` inside `absbi`. Passing the value into a function copies the padding bits along with it, and MSan flags the copy.

## Impact

libc++ tests that use these odd widths (for `std::abs`, `numeric_limits`, and similar) have to skip them under MSan to avoid the false alarm.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to