[LLVMbugs] [Bug 94] llvm-g++ tries to add bools; gccas complains
bugzilla-daemon at zion.cs.uiuc.edu
bugzilla-daemon at zion.cs.uiuc.edu
Thu Nov 6 10:32:04 PST 2003
http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=94
sabre at nondot.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Keywords| |compile-fail
Resolution| |FIXED
Target Milestone|--- |1.1
------- Additional Comments From sabre at nondot.org 2003-11-06 12:32 -------
I have no idea how this is happening on OSX: booleans should be promoted to
integers for operations like addition.
That said, here's the fix (slightly revised from Brian's patch):
$ diff -u llvm-representation.h~ llvm-representation.h
--- llvm-representation.h~ 2003-10-27 11:34:07.000000000 -0600
+++ llvm-representation.h 2003-11-06 10:10:08.000000000 -0600
@@ -387,6 +387,7 @@
#define llvm_type_is_primitive(TY) (TY->ID < FunctionTyID)
#define llvm_type_is_fp(TY) (((TY)->ID == FloatTyID) || ((TY)->ID==DoubleTyID))
#define llvm_type_is_integral(TY) ((TY)->ID >= BoolTyID && (TY)->ID <= LongTyID)
+#define llvm_type_is_integer(TY) ((TY)->ID > BoolTyID && (TY)->ID <= LongTyID)
#define llvm_type_is_scalar(TY) \
((TY)->ID == PointerTyID || \
(llvm_type_is_primitive(TY) && (TY)->ID != VoidTyID))
$ diff -u llvm-representation.c~ llvm-representation.c
--- llvm-representation.c~ 2003-11-04 23:46:44.000000000 -0600
+++ llvm-representation.c 2003-11-06 10:24:52.000000000 -0600
@@ -536,6 +536,9 @@
if (Opc != O_Shr && Opc != O_Shl)
assert(Op1->Ty == Op2->Ty &&
"Binary operator operands must have compatible types!");
+ if (Opc == O_Add || Opc == O_Sub || Opc == O_Mul || Opc == O_Div ||
+ Opc == O_Rem)
+ assert(Ty != BoolTy && "Cannot perform arith op on boolean!");
return New;
}
$ diff -u llvm-expand.c~ llvm-expand.c
--- llvm-expand.c~ 2003-11-05 10:16:59.000000000 -0600
+++ llvm-expand.c 2003-11-06 10:21:33.000000000 -0600
@@ -5187,7 +5187,7 @@
case EXACT_DIV_EXPR:
case PLUS_EXPR: case MINUS_EXPR: case MULT_EXPR: /* Plus, Sub, Mult */
case TRUNC_DIV_EXPR: case TRUNC_MOD_EXPR: case RDIV_EXPR:/* Division, Rem */
- case BIT_AND_EXPR: case BIT_IOR_EXPR: case BIT_XOR_EXPR: /* Bit operators */
+ case BIT_AND_EXPR: case BIT_IOR_EXPR: case BIT_XOR_EXPR: /* And, Or, Xor */
case TRUTH_AND_EXPR: case TRUTH_OR_EXPR: case TRUTH_XOR_EXPR: /* Bit ops */
case LSHIFT_EXPR: case RSHIFT_EXPR: /* Shifts */
case LT_EXPR: case LE_EXPR: case GT_EXPR: /* Comparisons */
@@ -5212,6 +5212,22 @@
if (V) return V;
}
+ /* If this is a simple arithmetic operator, cast both operands to the result
+ * type.
+ */
+ switch (TREE_CODE(exp)) {
+ case PLUS_EXPR: case MINUS_EXPR: case MULT_EXPR: /* Plus, Sub, Mult */
+ case TRUNC_DIV_EXPR: case TRUNC_MOD_EXPR: case RDIV_EXPR:/* Div, Rem */
+ /* If this is not a logical operator, make sure the operands are not
+ * bools.
+ */
+ assert(DestTy != BoolTy && "Cannot produce a bool for arithetic ops!");
+ case BIT_AND_EXPR: case BIT_IOR_EXPR: case BIT_XOR_EXPR: /* And, Or, Xor */
+ op0 = cast_if_type_not_equal(Fn, op0, DestTy);
+ op1 = cast_if_type_not_equal(Fn, op1, DestTy);
+ default: break;
+ }
+
/* Attempt to unify the types of the left and right operand... */
if (TREE_CODE(TREE_OPERAND(exp, 1)) == INTEGER_CST)
op1 = cast_if_type_not_equal(Fn, op1, op0->Ty);
-Chris
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
More information about the llvm-bugs
mailing list