Rollup merge of #80562 - nagisa:nagisa/bools-are-unsigned, r=eddyb

Consider Scalar to be a bool only if its unsigned

This seems right, given that conceptually bools are unsigned, but the
implications of this change may have more action at distance that I'm
not sure how to exhaustively consider.

For instance there are a number of cases where code attaches range
metadata if `scalar.is_bool()` holds. Supposedly it would no longer be
attached to the `repr(i8)` enums? Though I'm not sure why booleans are
being special-cased here in the first place...

Fixes #80556

cc `@eddyb`
This commit is contained in:
Yuki Okushi 2021-01-30 13:36:41 +09:00 committed by GitHub
commit a5c12ea75f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -103,7 +103,12 @@ impl ArgAttributes {
}
pub fn ext(&mut self, ext: ArgExtension) -> &mut Self {
assert!(self.arg_ext == ArgExtension::None || self.arg_ext == ext);
assert!(
self.arg_ext == ArgExtension::None || self.arg_ext == ext,
"cannot set {:?} when {:?} is already set",
ext,
self.arg_ext
);
self.arg_ext = ext;
self
}

View File

@ -682,7 +682,7 @@ pub struct Scalar {
impl Scalar {
pub fn is_bool(&self) -> bool {
if let Int(I8, _) = self.value { self.valid_range == (0..=1) } else { false }
matches!(self.value, Int(I8, false)) && self.valid_range == (0..=1)
}
/// Returns the valid range as a `x..y` range.

View File

@ -0,0 +1,13 @@
#![crate_type="lib"]
#[repr(i8)]
pub enum Type {
Type1 = 0,
Type2 = 1
}
// CHECK: define signext i8 @test()
#[no_mangle]
pub extern "C" fn test() -> Type {
Type::Type1
}