Skip to content

Commit ca1b124

Browse files
nikomatsakisbrson
authored andcommitted
force i1 booleans to i8 when comparing
Work around LLVM bug. cc rust-lang#36856
1 parent f223537 commit ca1b124

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/librustc_trans/base.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,16 @@ pub fn compare_scalar_types<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
320320
_ => bug!("compare_scalar_types: must be a comparison operator"),
321321
}
322322
}
323-
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyBool | ty::TyUint(_) | ty::TyChar => {
323+
ty::TyBool => {
324+
// FIXME(#36856) -- using `from_immediate` forces these booleans into `i8`,
325+
// which works around some LLVM bugs
326+
ICmp(bcx,
327+
bin_op_to_icmp_predicate(op, false),
328+
from_immediate(bcx, lhs),
329+
from_immediate(bcx, rhs),
330+
debug_loc)
331+
}
332+
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyUint(_) | ty::TyChar => {
324333
ICmp(bcx,
325334
bin_op_to_icmp_predicate(op, false),
326335
lhs,

src/test/run-pass/issue-36856.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for #36856.
12+
13+
// compile-flags:-g
14+
15+
fn g() -> bool {
16+
false
17+
}
18+
19+
pub fn main() {
20+
let a = !g();
21+
if a != !g() {
22+
panic!();
23+
}
24+
}

0 commit comments

Comments
 (0)