| Issue |
56017
|
| Summary |
runtime error: load of value 0, which is not a valid value for type 'bool'
|
| Labels |
|
| Assignees |
PiJoules
|
| Reporter |
PiJoules
|
```
union Flag {
constexpr Flag() : empty{} {}
struct {} empty;
bool value;
};
int main() {
static Flag flag;
return flag.value;
}
```
When this is compiled with `-std=c++17 -O3 -fsanitize=undefined`, UBSan reports:
```
/tmp/test.cc:10:17: runtime error: load of value 0, which is not a valid value for type 'bool'
```
which doesn't make sense since 0 is one of the only two values a `bool` can be.
In the IR, `0` is passed directly to the function that generates this message:
```
tail call void @__ubsan_handle_load_invalid_value(ptr nonnull @2, i64 0) #2, !nosanitize !5
```
with `-O0`, the IR is:
```
define dso_local noundef i32 @main() #0 prologue <{ i32, i32 }> <{ i32 846595819, i32 trunc (i64 sub (i64 ptrtoint (ptr @0 to i64), i64 ptrtoint (ptr @main to i64)) to i32) }> {
%1 = alloca i32, align 4
store i32 0, ptr %1, align 4
%2 = load i8, ptr @_ZZ4mainE4flag, align 1
%3 = icmp ule i8 %2, 1, !nosanitize !6
%4 = zext i8 %2 to i64, !nosanitize !6
br i1 %3, label %6, label %5, !prof !7, !nosanitize !6
5: ; preds = %0
call void @__ubsan_handle_load_invalid_value(ptr @2, i64 %4) #2, !nosanitize !6
br label %6, !nosanitize !6
6: ; preds = %5, %0
%7 = trunc i8 %2 to i1
%8 = zext i1 %7 to i32
ret i32 %8
}
```
which passes the actual byte value of the bool (`%4`) to `__ubsan_handle_load_invalid_value` if it fails the check. So somewhere in the optimization pass pipeline, this value is changed to zero which produces this weird message.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs