Basically the same as before, but I have this:

-  FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv);
+ FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv, false/ *not K&R*/);

instead of this:

-  FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv);
+ FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv, true/ *not K&R*/);

Whoops.

I've verified that the CFE builds from scratch with this patch and that Shootout-C++ now passes.

-Chris

Index: llvm-convert.cpp
===================================================================
--- llvm-convert.cpp    (revision 122094)
+++ llvm-convert.cpp    (working copy)
@@ -213,15 +213,17 @@ namespace {
           // If this is GCC being sloppy about pointer types, insert a bitcast.
           // See PR1083 for an example.
           ArgVal = new BitCastInst(ArgVal, LLVMTy, "tmp", CurBB);
+        } else if (ArgVal->getType() == Type::DoubleTy) {
+          // If this is a K&R float parameter, it got promoted to double. 
Insert
+          // the truncation to float now.
+          ArgVal = new FPTruncInst(ArgVal, LLVMTy, NameStack.back(), CurBB);
         } else {
-          // If this is just a mismatch between integer types, this could be 
due
+          // If this is just a mismatch between integer types, this is due
           // to K&R prototypes, where the forward proto defines the arg as int
           // and the actual impls is a short or char.
-          assert(ArgVal->getType()->isIntegral() && LLVMTy->isIntegral() &&
+          assert(ArgVal->getType() == Type::Int32Ty && LLVMTy->isIntegral() &&
                  "Lowerings don't match?");
-          bool isSigned = type == 0 ? true : !TYPE_UNSIGNED(type);
-          ArgVal = CastInst::createIntegerCast(ArgVal, LLVMTy, isSigned,
-                                               NameStack.back(), CurBB);
+          ArgVal = new TruncInst(ArgVal, LLVMTy, NameStack.back(), CurBB);
         }
       }
       assert(!LocStack.empty());
Index: llvm-types.cpp
===================================================================
--- llvm-types.cpp      (revision 122094)
+++ llvm-types.cpp      (working copy)
@@ -474,10 +474,11 @@ namespace {
     const Type *&RetTy;
     std::vector<const Type*> &ArgTypes;
     unsigned &CallingConv;
+    bool KNRPromotion;
   public:
     FunctionTypeConversion(const Type *&retty, std::vector<const Type*> &AT,
-                           unsigned &CC)
-      : RetTy(retty), ArgTypes(AT), CallingConv(CC) {
+                           unsigned &CC, bool KNR)
+      : RetTy(retty), ArgTypes(AT), CallingConv(CC), KNRPromotion(KNR) {
       CallingConv = CallingConv::C;
     }
     
@@ -512,6 +513,13 @@ namespace {
     }
     
     void HandleScalarArgument(const llvm::Type *LLVMTy, tree type) {
+      if (KNRPromotion) {
+        if (LLVMTy == Type::FloatTy)
+          LLVMTy = Type::DoubleTy;
+        else if (LLVMTy == Type::Int16Ty || LLVMTy == Type::Int8Ty ||
+                 LLVMTy == Type::BoolTy)
+          LLVMTy = Type::Int32Ty;
+      }
       ArgTypes.push_back(LLVMTy);
     }
   };
@@ -528,7 +536,7 @@ ConvertArgListToFnType(tree ReturnType, 
   std::vector<const Type*> ArgTys;
   const Type *RetTy;
   
-  FunctionTypeConversion Client(RetTy, ArgTys, CallingConv);
+  FunctionTypeConversion Client(RetTy, ArgTys, CallingConv, true /*K&R*/);
   TheLLVMABI<FunctionTypeConversion> ABIConverter(Client);
   
   ABIConverter.HandleReturnType(ReturnType);
@@ -542,7 +550,7 @@ const FunctionType *TypeConverter::Conve
   const Type *RetTy = 0;
   std::vector<const Type*> ArgTypes;
   bool isVarArg = false;
-  FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv);
+  FunctionTypeConversion Client(RetTy, ArgTypes, CallingConv, false/*not 
K&R*/);
   TheLLVMABI<FunctionTypeConversion> ABIConverter(Client);
   
   ABIConverter.HandleReturnType(TREE_TYPE(type));
_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to