This fixes PR1083 and test/Regression/CFrontend/2007-01-06-KNR-Proto.c

Index: llvm-convert.cpp
===================================================================
--- llvm-convert.cpp    (revision 122081)
+++ llvm-convert.cpp    (working copy)
@@ -209,14 +209,20 @@
     void HandleScalarArgument(const llvm::Type *LLVMTy, tree type) {
       Value *ArgVal = AI;
       if (ArgVal->getType() != LLVMTy) {
-        // If this is just a mismatch between integer types, this could be 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() &&
-               "Lowerings don't match?");
-        bool isSigned = type == 0 ? true : !TYPE_UNSIGNED(type);
-        ArgVal = CastInst::createIntegerCast(ArgVal, LLVMTy, isSigned,
-                                             NameStack.back(), CurBB);
+        if (isa<PointerType>(ArgVal->getType()) && isa<PointerType>(LLVMTy)) {
+          // 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 this is just a mismatch between integer types, this could be 
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() &&
+                 "Lowerings don't match?");
+          bool isSigned = type == 0 ? true : !TYPE_UNSIGNED(type);
+          ArgVal = CastInst::createIntegerCast(ArgVal, LLVMTy, isSigned,
+                                               NameStack.back(), CurBB);
+        }
       }
       assert(!LocStack.empty());
       Value *Loc = LocStack.back();

-Chris
_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to