summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CWriter/Writer.cpp
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2003-06-23 20:00:51 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2003-06-23 20:00:51 +0000
commit04bdfe624c361c36c10cc125ed2de2a0cf6b964a (patch)
treedf88a1a0518ac330d3c9ae5f8df8a1915906f8fc /llvm/lib/CWriter/Writer.cpp
parent226563f7b93a8ed5ce1708d02addf25e456dbd6e (diff)
downloadbcm5719-llvm-04bdfe624c361c36c10cc125ed2de2a0cf6b964a.tar.gz
bcm5719-llvm-04bdfe624c361c36c10cc125ed2de2a0cf6b964a.zip
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. llvm-svn: 6869
Diffstat (limited to 'llvm/lib/CWriter/Writer.cpp')
-rw-r--r--llvm/lib/CWriter/Writer.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/CWriter/Writer.cpp b/llvm/lib/CWriter/Writer.cpp
index ce44f3ce308..9e10d5bc782 100644
--- a/llvm/lib/CWriter/Writer.cpp
+++ b/llvm/lib/CWriter/Writer.cpp
@@ -1029,6 +1029,16 @@ void CWriter::visitPHINode(PHINode &I) {
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 @@ void CWriter::visitBinaryOperator(Instruction &I) {
}
writeOperand(I.getOperand(1));
+
+ if (needsCast) {
+ Out << "))";
+ }
}
void CWriter::visitCastInst(CastInst &I) {
OpenPOWER on IntegriCloud