Skip to content

Commit

Permalink
Rollup merge of rust-lang#80562 - nagisa:nagisa/bools-are-unsigned, r…
Browse files Browse the repository at this point in the history
…=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 rust-lang#80556

cc `@eddyb`
  • Loading branch information
JohnTitor committed Jan 30, 2021
2 parents ecd7cb1 + 915a04e commit a5c12ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_target/src/abi/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/test/codegen/abi-repr-ext.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a5c12ea

Please sign in to comment.