diff options
| author | Vikram S. Adve <vadve@cs.uiuc.edu> | 2002-08-24 14:44:23 +0000 |
|---|---|---|
| committer | Vikram S. Adve <vadve@cs.uiuc.edu> | 2002-08-24 14:44:23 +0000 |
| commit | bc27523001e765e6e82719a7ba82b4f74e87e98d (patch) | |
| tree | 8230f75ed237859e1ff31d16140734db31872968 /llvm/lib | |
| parent | 65217ff294f60fbcc0f22fbdfe432167dc94110b (diff) | |
| download | bcm5719-llvm-bc27523001e765e6e82719a7ba82b4f74e87e98d.tar.gz bcm5719-llvm-bc27523001e765e6e82719a7ba82b4f74e87e98d.zip | |
Sign-extend array index expressions to work correctly on non-32 bit machines.
llvm-svn: 3496
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CWriter/Writer.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/CWriter/Writer.cpp b/llvm/lib/CWriter/Writer.cpp index e33622f71f3..f4fb7a24585 100644 --- a/llvm/lib/CWriter/Writer.cpp +++ b/llvm/lib/CWriter/Writer.cpp @@ -210,7 +210,8 @@ ostream &CWriter::printType(const Type *Ty, const string &NameSoFar, case Type::PointerTyID: { const PointerType *PTy = cast<PointerType>(Ty); - return printType(PTy->getElementType(), "(*" + NameSoFar + ")"); + std::string ptrName = NameSoFar.length()? "(*"+NameSoFar+")" : string("*"); + return printType(PTy->getElementType(), ptrName); } case Type::ArrayTyID: { @@ -844,16 +845,20 @@ void CWriter::printIndexingExpression(Value *Ptr, User::op_iterator I, Out << (HasImplicitAddress ? "." : "->"); Out << "field" << cast<ConstantUInt>(*(I+1))->getValue(); I += 2; - } else { // Performing array indexing. Just skip the 0 + } else { // First array index of 0: Just skip it ++I; } } for (; I != E; ++I) if ((*I)->getType() == Type::UIntTy) { - Out << "["; + Out << "[((int) ("; // sign-extend from 32 (to 64) bits writeOperand(*I); - Out << "]"; + Out << " * sizeof("; + printType(cast<PointerType>(Ptr->getType())->getElementType()); + Out << "))) / sizeof("; + printType(cast<PointerType>(Ptr->getType())->getElementType()); + Out << ")]"; } else { Out << ".field" << cast<ConstantUInt>(*I)->getValue(); } |

