For PR1099:
authorReid Spencer <rspencer@reidspencer.com>
Tue, 9 Jan 2007 06:38:06 +0000 (06:38 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 9 Jan 2007 06:38:06 +0000 (06:38 +0000)
Partial fix for this PR. Default function parameters to signed integer, just
like everything else in CBE. The bug was caused by incorrectly introducing
parameter attributes feature by choosing "signed" parameter if the
SExtAttribute was specified. Howeer, if no attribute is specified, this
causes it to become unsigned which is incorrect. Reversing the logic so
that signedness is detected by "not ZExtAttribute" set fixes the issue.

This fixes 197.parser but there is more to do. Any comparison and possibly
other operators involving arguments may need to correctly cast the parameter
before its use, depending on the sign of the operator.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33034 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp

index ff87be775849197896511dd1d94061e75fc9fd32..8156e88d6716f79d9a6146a8042ba9680e563257 100644 (file)
@@ -348,7 +348,7 @@ void CWriter::printStructReturnPointerFunctionType(std::ostream &Out,
     if (PrintedType)
       FunctionInnards << ", ";
     printType(FunctionInnards, *I, 
-        /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
+        /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), "");
     PrintedType = true;
   }
   if (FTy->isVarArg()) {
@@ -360,7 +360,7 @@ void CWriter::printStructReturnPointerFunctionType(std::ostream &Out,
   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 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
       if (I != FTy->param_begin())
         FunctionInnards << ", ";
       printType(FunctionInnards, *I, 
-          /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
+         /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), "");
       ++Idx;
     }
     if (FTy->isVarArg()) {
@@ -429,7 +429,7 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
     FunctionInnards << ')';
     std::string tstr = FunctionInnards.str();
     printType(Out, FTy->getReturnType(), 
-        /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
+        /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::ZExtAttribute), tstr);
     return Out;
   }
   case Type::StructTyID: {
@@ -1775,7 +1775,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
         else
           ArgName = "";
         printType(FunctionInnards, I->getType(), 
-            /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute), 
+            /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute), 
             ArgName);
         PrintedArg = true;
         ++Idx;
@@ -1796,7 +1796,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
     for (; I != E; ++I) {
       if (PrintedArg) FunctionInnards << ", ";
       printType(FunctionInnards, *I,
-               /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute));
+             /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute));
       PrintedArg = true;
       ++Idx;
     }
@@ -1823,7 +1823,8 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
   }
     
   // Print out the return type and the signature built above.
-  printType(Out, RetTy, FT->paramHasAttr(0, FunctionType::SExtAttribute),
+  printType(Out, RetTy, 
+            /*isSigned=*/!FT->paramHasAttr(0, FunctionType::ZExtAttribute), 
             FunctionInnards.str());
 }
 
@@ -2516,7 +2517,7 @@ void CWriter::visitCallInst(CallInst &I) {
         (*AI)->getType() != FTy->getParamType(ArgNo)) {
       Out << '(';
       printType(Out, FTy->getParamType(ArgNo), 
-              /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute));
+            /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute));
       Out << ')';
     }
     writeOperand(*AI);
index ff87be775849197896511dd1d94061e75fc9fd32..8156e88d6716f79d9a6146a8042ba9680e563257 100644 (file)
@@ -348,7 +348,7 @@ void CWriter::printStructReturnPointerFunctionType(std::ostream &Out,
     if (PrintedType)
       FunctionInnards << ", ";
     printType(FunctionInnards, *I, 
-        /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
+        /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), "");
     PrintedType = true;
   }
   if (FTy->isVarArg()) {
@@ -360,7 +360,7 @@ void CWriter::printStructReturnPointerFunctionType(std::ostream &Out,
   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 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
       if (I != FTy->param_begin())
         FunctionInnards << ", ";
       printType(FunctionInnards, *I, 
-          /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute), "");
+         /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute), "");
       ++Idx;
     }
     if (FTy->isVarArg()) {
@@ -429,7 +429,7 @@ std::ostream &CWriter::printType(std::ostream &Out, const Type *Ty,
     FunctionInnards << ')';
     std::string tstr = FunctionInnards.str();
     printType(Out, FTy->getReturnType(), 
-        /*isSigned=*/FTy->paramHasAttr(0, FunctionType::SExtAttribute), tstr);
+        /*isSigned=*/!FTy->paramHasAttr(0, FunctionType::ZExtAttribute), tstr);
     return Out;
   }
   case Type::StructTyID: {
@@ -1775,7 +1775,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
         else
           ArgName = "";
         printType(FunctionInnards, I->getType(), 
-            /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute), 
+            /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute), 
             ArgName);
         PrintedArg = true;
         ++Idx;
@@ -1796,7 +1796,7 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
     for (; I != E; ++I) {
       if (PrintedArg) FunctionInnards << ", ";
       printType(FunctionInnards, *I,
-               /*isSigned=*/FT->paramHasAttr(Idx, FunctionType::SExtAttribute));
+             /*isSigned=*/!FT->paramHasAttr(Idx, FunctionType::ZExtAttribute));
       PrintedArg = true;
       ++Idx;
     }
@@ -1823,7 +1823,8 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
   }
     
   // Print out the return type and the signature built above.
-  printType(Out, RetTy, FT->paramHasAttr(0, FunctionType::SExtAttribute),
+  printType(Out, RetTy, 
+            /*isSigned=*/!FT->paramHasAttr(0, FunctionType::ZExtAttribute), 
             FunctionInnards.str());
 }
 
@@ -2516,7 +2517,7 @@ void CWriter::visitCallInst(CallInst &I) {
         (*AI)->getType() != FTy->getParamType(ArgNo)) {
       Out << '(';
       printType(Out, FTy->getParamType(ArgNo), 
-              /*isSigned=*/FTy->paramHasAttr(Idx, FunctionType::SExtAttribute));
+            /*isSigned=*/!FTy->paramHasAttr(Idx, FunctionType::ZExtAttribute));
       Out << ')';
     }
     writeOperand(*AI);