Changes in directory llvm/lib/Target/CBackend:
Writer.cpp updated: 1.307 -> 1.308 --- Log message: For PR1099: http://llvm.org/PR1099 : Invert the "isSigned" logic in calls to printType and printPrimitiveType. We want variables to be declared unsigned by default so that signless operators like + and - perform the unsigned operation that LLVM expects by default. Parameters with the sext attribute will be declared signed and signed instructions will case operand values to signed regardless of the type of the variable. This passes all tests and fixes PR1099: http://llvm.org/PR1099 . --- Diffs of the changes: (+33 -33) Writer.cpp | 66 ++++++++++++++++++++++++++++++------------------------------- 1 files changed, 33 insertions(+), 33 deletions(-) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.307 llvm/lib/Target/CBackend/Writer.cpp:1.308 --- llvm/lib/Target/CBackend/Writer.cpp:1.307 Tue Jan 9 00:38:06 2007 +++ llvm/lib/Target/CBackend/Writer.cpp Tue Jan 9 11:09:09 2007 @@ -115,7 +115,7 @@ } std::ostream &printType(std::ostream &Out, const Type *Ty, - bool isSigned = true, + bool isSigned = false, const std::string &VariableName = "", bool IgnoreName = false); std::ostream &printPrimitiveType(std::ostream &Out, const Type *Ty, @@ -348,7 +348,7 @@ if (PrintedType) FunctionInnards << ", "; printType(FunctionInnards, *I, - /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), ""); + /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), ""); PrintedType = true; } if (FTy->isVarArg()) { @@ -360,7 +360,7 @@ FunctionInnards << ')'; std::string tstr = FunctionInnards.str(); printType(Out, RetTy, - /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr); + /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr); } std::ostream & @@ -417,7 +417,7 @@ if (I != FTy->param_begin()) FunctionInnards << ", "; printType(FunctionInnards, *I, - /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), ""); + /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), ""); ++Idx; } if (FTy->isVarArg()) { @@ -429,7 +429,7 @@ FunctionInnards << ')'; std::string tstr = FunctionInnards.str(); printType(Out, FTy->getReturnType(), - /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::ZExtAttribute), tstr); + /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr); return Out; } case Type::StructTyID: { @@ -439,7 +439,7 @@ for (StructType::element_iterator I = STy->element_begin(), E = STy->element_end(); I != E; ++I) { Out << " "; - printType(Out, *I, true, "field" + utostr(Idx++)); + printType(Out, *I, false, "field" + utostr(Idx++)); Out << ";\n"; } return Out << '}'; @@ -453,14 +453,14 @@ isa<PackedType>(PTy->getElementType())) ptrName = "(" + ptrName + ")"; - return printType(Out, PTy->getElementType(), true, ptrName); + return printType(Out, PTy->getElementType(), false, ptrName); } case Type::ArrayTyID: { const ArrayType *ATy = cast<ArrayType>(Ty); unsigned NumElements = ATy->getNumElements(); if (NumElements == 0) NumElements = 1; - return printType(Out, ATy->getElementType(), true, + return printType(Out, ATy->getElementType(), false, NameSoFar + "[" + utostr(NumElements) + "]"); } @@ -468,7 +468,7 @@ const PackedType *PTy = cast<PackedType>(Ty); unsigned NumElements = PTy->getNumElements(); if (NumElements == 0) NumElements = 1; - return printType(Out, PTy->getElementType(), true, + return printType(Out, PTy->getElementType(), false, NameSoFar + "[" + utostr(NumElements) + "]"); } @@ -834,7 +834,7 @@ if (ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) { const Type* Ty = CI->getType(); Out << "(("; - printPrimitiveType(Out, Ty, true) << ')'; + printPrimitiveType(Out, Ty, false) << ')'; if (CI->isMinValue(true)) Out << CI->getZExtValue() << 'u'; else @@ -1019,10 +1019,10 @@ } if (NeedsExplicitCast) { Out << "(("; - if (Ty->isPrimitiveType()) + if (Ty->isInteger()) printPrimitiveType(Out, Ty, TypeIsSigned); else - printType(Out, Ty); + printType(Out, Ty); // not integer, sign doesn't matter Out << ")("; } return NeedsExplicitCast; @@ -1222,10 +1222,10 @@ // operand. if (shouldCast) { Out << "(("; - if (OpTy->isPrimitiveType()) + if (OpTy->isInteger()) printPrimitiveType(Out, OpTy, castIsSigned); else - printType(Out, OpTy); + printType(Out, OpTy); // not integer, sign doesn't matter Out << ")"; writeOperand(Operand); Out << ")"; @@ -1457,17 +1457,17 @@ I != E; ++I) { if (I->hasExternalLinkage()) { Out << "extern "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); Out << ";\n"; } else if (I->hasDLLImportLinkage()) { Out << "__declspec(dllimport) "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); Out << ";\n"; } else if (I->hasExternalWeakLinkage()) { Out << "extern "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); Out << " __EXTERNAL_WEAK__ ;\n"; } @@ -1516,7 +1516,7 @@ Out << "static "; else Out << "extern "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); if (I->hasLinkOnceLinkage()) @@ -1546,7 +1546,7 @@ else if (I->hasDLLExportLinkage()) Out << "__declspec(dllexport) "; - printType(Out, I->getType()->getElementType(), true, + printType(Out, I->getType()->getElementType(), false, Mang->getValueName(I)); if (I->hasLinkOnceLinkage()) Out << " __attribute__((common))"; @@ -1685,7 +1685,7 @@ const Type *Ty = cast<Type>(I->second); std::string Name = "l_" + Mang->makeNameProper(I->first); Out << "typedef "; - printType(Out, Ty, true, Name); + printType(Out, Ty, false, Name); Out << ";\n"; } @@ -1724,7 +1724,7 @@ if (StructPrinted.insert(STy).second) { // Print structure type out. std::string Name = TypeNames[STy]; - printType(Out, STy, true, Name, true); + printType(Out, STy, false, Name, true); Out << ";\n\n"; } } @@ -1775,7 +1775,7 @@ else ArgName = ""; printType(FunctionInnards, I->getType(), - /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute), + /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute), ArgName); PrintedArg = true; ++Idx; @@ -1796,7 +1796,7 @@ for (; I != E; ++I) { if (PrintedArg) FunctionInnards << ", "; printType(FunctionInnards, *I, - /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute)); + /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute)); PrintedArg = true; ++Idx; } @@ -1824,7 +1824,7 @@ // Print out the return type and the signature built above. printType(Out, RetTy, - /*isSigned=*/!FT->paramHasAttr(0, FunctionType::ZExtAttribute), + /*isSigned=*/FT->paramHasAttr(0, FunctionType::SExtAttribute), FunctionInnards.str()); } @@ -1846,11 +1846,11 @@ const Type *StructTy = cast<PointerType>(F.arg_begin()->getType())->getElementType(); Out << " "; - printType(Out, StructTy, true, "StructReturn"); + printType(Out, StructTy, false, "StructReturn"); Out << "; /* Struct return temporary */\n"; Out << " "; - printType(Out, F.arg_begin()->getType(), true, + printType(Out, F.arg_begin()->getType(), false, Mang->getValueName(F.arg_begin())); Out << " = &StructReturn;\n"; } @@ -1861,17 +1861,17 @@ for (inst_iterator I = inst_begin(&F), E = inst_end(&F); I != E; ++I) { if (const AllocaInst *AI = isDirectAlloca(&*I)) { Out << " "; - printType(Out, AI->getAllocatedType(), true, Mang->getValueName(AI)); + printType(Out, AI->getAllocatedType(), false, Mang->getValueName(AI)); Out << "; /* Address-exposed local */\n"; PrintedVar = true; } else if (I->getType() != Type::VoidTy && !isInlinableInst(*I)) { Out << " "; - printType(Out, I->getType(), true, Mang->getValueName(&*I)); + printType(Out, I->getType(), false, Mang->getValueName(&*I)); Out << ";\n"; if (isa<PHINode>(*I)) { // Print out PHI node temporaries as well... Out << " "; - printType(Out, I->getType(), true, + printType(Out, I->getType(), false, Mang->getValueName(&*I)+"__PHI_TEMPORARY"); Out << ";\n"; } @@ -2100,7 +2100,7 @@ || (I.getType() == Type::FloatTy)) { needsCast = true; Out << "(("; - printType(Out, I.getType()); + printType(Out, I.getType(), false); Out << ")("; } @@ -2517,7 +2517,7 @@ (*AI)->getType() != FTy->getParamType(ArgNo)) { Out << '('; printType(Out, FTy->getParamType(ArgNo), - /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute)); + /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute)); Out << ')'; } writeOperand(*AI); @@ -2734,7 +2734,7 @@ Out << '*'; if (I.isVolatile()) { Out << "(("; - printType(Out, I.getType(), true, "volatile*"); + printType(Out, I.getType(), false, "volatile*"); Out << ")"; } @@ -2748,7 +2748,7 @@ Out << '*'; if (I.isVolatile()) { Out << "(("; - printType(Out, I.getOperand(0)->getType(), true, " volatile*"); + printType(Out, I.getOperand(0)->getType(), false, " volatile*"); Out << ")"; } writeOperand(I.getPointerOperand()); _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits