Fix a bug in the bc reader/writer: we were not correctly encoding varargs
authorChris Lattner <sabre@nondot.org>
Fri, 26 May 2006 18:42:34 +0000 (18:42 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 26 May 2006 18:42:34 +0000 (18:42 +0000)
nonccc calls (we were dropping the CC and tail flag).  This broke several
FORTRAN programs.

Testcase here: Regression/Assembler/2006-05-26-VarargsCallEncode.ll

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

lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Writer/Writer.cpp

index 36b2ecb37fdcc04ba51e9197d7cda9ee5d2ccfef..d441e7504b7a2f928e60a70d6c1d8ab4047db345 100644 (file)
@@ -830,7 +830,15 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
 
     if (Opcode == 61 || Opcode == 59)
       isTailCall = true;
-
+    
+    if (Opcode == 58) {
+      isTailCall = Oprnds.back() & 1;
+      CallingConv = Oprnds.back() >> 1;
+      Oprnds.pop_back();
+    } else if (Opcode == 59 || Opcode == 60) {
+      CallingConv = CallingConv::Fast;
+    }
+    
     // Check to make sure we have a pointer to function type
     const PointerType *PTy = dyn_cast<PointerType>(F->getType());
     if (PTy == 0) error("Call to non function pointer value!");
@@ -841,13 +849,6 @@ void BytecodeReader::ParseInstruction(std::vector<unsigned> &Oprnds,
     if (!FTy->isVarArg()) {
       FunctionType::param_iterator It = FTy->param_begin();
 
-      if (Opcode == 58) {
-        isTailCall = Oprnds.back() & 1;
-        CallingConv = Oprnds.back() >> 1;
-        Oprnds.pop_back();
-      } else if (Opcode == 59 || Opcode == 60)
-        CallingConv = CallingConv::Fast;
-
       for (unsigned i = 1, e = Oprnds.size(); i != e; ++i) {
         if (It == FTy->param_end())
           error("Invalid call instruction!");
index 4ec6b2a41e85a56a08215719e4d3ae1053413ee8..83e8a57acfe0176f8f24ee4ba1dea99d539bab2a 100644 (file)
@@ -527,7 +527,8 @@ void BytecodeWriter::outputInstrVarArgsCall(const Instruction *I,
     // variable argument.
     NumFixedOperands = 3+NumParams;
   }
-  output_vbr(2 * I->getNumOperands()-NumFixedOperands);
+  output_vbr(2 * I->getNumOperands()-NumFixedOperands +
+             unsigned(Opcode == 56 || Opcode == 58));
 
   // The type for the function has already been emitted in the type field of the
   // instruction.  Just emit the slot # now.
@@ -548,6 +549,14 @@ void BytecodeWriter::outputInstrVarArgsCall(const Instruction *I,
     assert(Slot >= 0 && "No slot number for value!?!?");
     output_vbr((unsigned)Slot);
   }
+  
+  // If this is the escape sequence for call, emit the tailcall/cc info.
+  if (Opcode == 58) {
+    const CallInst *CI = cast<CallInst>(I);
+    output_vbr((CI->getCallingConv() << 1) | unsigned(CI->isTailCall()));
+  } else if (Opcode == 56) {    // Invoke escape sequence.
+    output_vbr(cast<InvokeInst>(I)->getCallingConv());
+  }
 }