ByVal arguments are passed on stack. Make sure to allocate a slot using size and...
authorEvan Cheng <evan.cheng@apple.com>
Sat, 12 Jan 2008 01:07:41 +0000 (01:07 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sat, 12 Jan 2008 01:07:41 +0000 (01:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45897 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/CallingConvEmitter.cpp

index f7c2eda5e866d02f77d8176567b645b2e37ab9f6..c81c80f3fab68b198c5c95d99ad83200182f0b39 100644 (file)
@@ -115,19 +115,32 @@ void CallingConvEmitter::EmitAction(Record *Action,
       int Size = Action->getValueAsInt("Size");
       int Align = Action->getValueAsInt("Align");
 
-      O << IndentStr << "unsigned Offset" << ++Counter
-        << " = State.AllocateStack(";
+      O << IndentStr << "unsigned Size = ";
       if (Size)
-        O << Size << ", ";
+        O << Size;
       else
-        O << "\n" << IndentStr << "  State.getTarget().getTargetData()"
-          "->getABITypeSize(MVT::getTypeForValueType(LocVT)), ";
+        O << "State.getTarget().getTargetData()"
+          "->getABITypeSize(MVT::getTypeForValueType(LocVT))";
+      O << ";\n"
+        << IndentStr << "unsigned Align = ";
       if (Align)
         O << Align;
       else
-        O << "\n" << IndentStr << "  State.getTarget().getTargetData()"
+        O << "State.getTarget().getTargetData()"
           "->getABITypeAlignment(MVT::getTypeForValueType(LocVT))";
-      O << ");\n" << IndentStr
+      O << ";\n";
+      O << IndentStr << "if (ArgFlags & ISD::ParamFlags::ByVal) {\n";
+      O << IndentStr << "  " <<
+        "Size = (ArgFlags & ISD::ParamFlags::ByValSize) >> "
+        "ISD::ParamFlags::ByValSizeOffs;\n";
+      O << IndentStr << "  " <<
+        "unsigned ParamAlign = 1 << ((ArgFlags & ISD::ParamFlags::ByValAlign) "
+        ">> ISD::ParamFlags::ByValAlignOffs);\n";
+      O << IndentStr << "  Align = std::max(Align, ParamAlign);\n"
+        << IndentStr << "}\n";
+      O << IndentStr << "unsigned Offset" << ++Counter
+        << " = State.AllocateStack(Size, Align);\n";
+      O << IndentStr
         << "State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset"
         << Counter << ", LocVT, LocInfo));\n";
       O << IndentStr << "return false;\n";