[llvm-commits] CVS: llvm/lib/CWriter/Writer.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Mon Jun 23 15:02:03 PDT 2003
Changes in directory llvm/lib/CWriter:
Writer.cpp updated: 1.97 -> 1.98
---
Log message:
Fix 2003-06-23-PromotedExprs.llx -- if we are adding two bytes we better
explicitly cast the result to be a byte, or C will gleefully promote it
to int.
---
Diffs of the changes:
Index: llvm/lib/CWriter/Writer.cpp
diff -u llvm/lib/CWriter/Writer.cpp:1.97 llvm/lib/CWriter/Writer.cpp:1.98
--- llvm/lib/CWriter/Writer.cpp:1.97 Tue Jun 17 18:55:31 2003
+++ llvm/lib/CWriter/Writer.cpp Mon Jun 23 15:00:51 2003
@@ -1029,6 +1029,16 @@
void CWriter::visitBinaryOperator(Instruction &I) {
// binary instructions, shift instructions, setCond instructions.
assert(!isa<PointerType>(I.getType()));
+
+ // We must cast the results of binary operations which might be promoted.
+ bool needsCast = false;
+ if ((I.getType() == Type::UByteTy) || (I.getType() == Type::SByteTy)
+ || (I.getType() == Type::UShortTy) || (I.getType() == Type::ShortTy)) {
+ needsCast = true;
+ Out << "((";
+ printType(Out, I.getType(), "", false, false);
+ Out << ")(";
+ }
writeOperand(I.getOperand(0));
@@ -1053,6 +1063,10 @@
}
writeOperand(I.getOperand(1));
+
+ if (needsCast) {
+ Out << "))";
+ }
}
void CWriter::visitCastInst(CastInst &I) {
More information about the llvm-commits
mailing list