[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 25 12:08:21 PDT 2022
shafik added inline comments.
================
Comment at: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp:27
+ return ((int)e1 != -1) & ((int)e2 != -1) &
+ // CHECK: error: load of value <unknown>, which is not a valid value for type 'enum EBool'
+ ((int)e3 != -1) & ((int)e4 == 1) &
----------------
aaron.ballman wrote:
> erichkeane wrote:
> > What does THIS come from? What value is unknown? Shouldn't the -1 be fine?
> +1, I'm surprised by the `<unknown>` there, but also... neither `e1` nor `e2` are of type `enum EBool`!
So it looks like clang knows that the only valid values for a bool enum is 0 or 1 and it will mask the value accordingly see godbolt for example using `argc` : https://godbolt.org/z/ceb9hPno9
So that would explain why the original test used a `unsigned char*` in order to prompt the diagnostic.
Looking into the ubsan diagnostic it looks like it treats bool as an unknown value, separate from integer and float. It is not clear to me why it does this but fixing that feels outside the scope of this change since this was part of the original test.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130301/new/
https://reviews.llvm.org/D130301
More information about the cfe-commits
mailing list