Skip to content

Commit cf6c3d9

Browse files
committed
librustc: Attempt to put out burning tree by fixing translation of unary negation in boolean constants. rs=burningtree
1 parent b34f871 commit cf6c3d9

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

src/librustc/lib/llvm.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,19 @@ pub extern mod llvm {
445445
Count: c_uint,
446446
Packed: Bool) -> ValueRef;
447447

448-
pub unsafe fn LLVMConstString(Str: *c_char, Length: c_uint,
449-
DontNullTerminate: Bool) -> ValueRef;
450-
pub unsafe fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef,
451-
Length: c_uint) -> ValueRef;
448+
pub unsafe fn LLVMConstString(Str: *c_char,
449+
Length: c_uint,
450+
DontNullTerminate: Bool)
451+
-> ValueRef;
452+
pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
453+
ConstantVals: *ValueRef,
454+
Length: c_uint)
455+
-> ValueRef;
452456
pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
453-
Count: c_uint, Packed: Bool) -> ValueRef;
457+
Count: c_uint,
458+
Packed: Bool) -> ValueRef;
454459
pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
455-
Size: c_uint) -> ValueRef;
460+
Size: c_uint) -> ValueRef;
456461

457462
/* Constant expressions */
458463
pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
@@ -463,8 +468,8 @@ pub extern mod llvm {
463468
pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
464469
pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
465470
pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef,
466-
RHSConstant: ValueRef)
467-
-> ValueRef;
471+
RHSConstant: ValueRef)
472+
-> ValueRef;
468473
pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef,
469474
RHSConstant: ValueRef)
470475
-> ValueRef;
@@ -475,14 +480,14 @@ pub extern mod llvm {
475480
RHSConstant: ValueRef)
476481
-> ValueRef;
477482
pub unsafe fn LLVMConstSub(LHSConstant: ValueRef,
478-
RHSConstant: ValueRef)
479-
-> ValueRef;
483+
RHSConstant: ValueRef)
484+
-> ValueRef;
480485
pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef,
481-
RHSConstant: ValueRef)
482-
-> ValueRef;
486+
RHSConstant: ValueRef)
487+
-> ValueRef;
483488
pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef,
484-
RHSConstant: ValueRef)
485-
-> ValueRef;
489+
RHSConstant: ValueRef)
490+
-> ValueRef;
486491
pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef,
487492
RHSConstant: ValueRef)
488493
-> ValueRef;

src/librustc/middle/trans/consts.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,18 @@ pub fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
204204
ast::box(_) |
205205
ast::uniq(_) |
206206
ast::deref => const_deref(cx, te),
207-
ast::not => llvm::LLVMConstNot(te),
207+
ast::not => {
208+
match ty::get(ty).sty {
209+
ty::ty_bool => {
210+
// Somewhat questionable, but I believe this is
211+
// correct.
212+
let te = llvm::LLVMConstTrunc(te, T_i1());
213+
let te = llvm::LLVMConstNot(te);
214+
llvm::LLVMConstZExt(te, T_bool())
215+
}
216+
_ => llvm::LLVMConstNot(te),
217+
}
218+
}
208219
ast::neg => {
209220
if is_float { llvm::LLVMConstFNeg(te) }
210221
else { llvm::LLVMConstNeg(te) }

0 commit comments

Comments
 (0)