Skip to content

Commit 915a04e

Browse files
committed
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
1 parent b122908 commit 915a04e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

compiler/rustc_target/src/abi/call/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ impl ArgAttributes {
103103
}
104104

105105
pub fn ext(&mut self, ext: ArgExtension) -> &mut Self {
106-
assert!(self.arg_ext == ArgExtension::None || self.arg_ext == ext);
106+
assert!(
107+
self.arg_ext == ArgExtension::None || self.arg_ext == ext,
108+
"cannot set {:?} when {:?} is already set",
109+
ext,
110+
self.arg_ext
111+
);
107112
self.arg_ext = ext;
108113
self
109114
}

compiler/rustc_target/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ pub struct Scalar {
682682

683683
impl Scalar {
684684
pub fn is_bool(&self) -> bool {
685-
if let Int(I8, _) = self.value { self.valid_range == (0..=1) } else { false }
685+
matches!(self.value, Int(I8, false)) && self.valid_range == (0..=1)
686686
}
687687

688688
/// Returns the valid range as a `x..y` range.

src/test/codegen/abi-repr-ext.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![crate_type="lib"]
2+
3+
#[repr(i8)]
4+
pub enum Type {
5+
Type1 = 0,
6+
Type2 = 1
7+
}
8+
9+
// CHECK: define signext i8 @test()
10+
#[no_mangle]
11+
pub extern "C" fn test() -> Type {
12+
Type::Type1
13+
}

0 commit comments

Comments
 (0)