Fix attribute handling.
authorDevang Patel <dpatel@apple.com>
Wed, 12 Mar 2008 00:07:03 +0000 (00:07 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 12 Mar 2008 00:07:03 +0000 (00:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48262 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/StructRetPromotion.cpp
test/Transforms/SRETPromotion/2008-03-11-attributes.ll [new file with mode: 0644]

index 686ffdad6be39208a8780c76d0d7bd9649c96144..c6b561dfd31c01a0e0f0eec73085107e7b070211 100644 (file)
@@ -210,17 +210,17 @@ Function *SRETPromotion::cloneFunctionBody(Function *F,
   // Skip first argument.
   Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
   ++I;
-  unsigned ParamIndex = 1; // 0th parameter attribute is reserved for return type.
+  // 0th parameter attribute is reserved for return type.
+  // 1th parameter attribute is for first 1st sret argument.
+  unsigned ParamIndex = 2; 
   while (I != E) {
     Params.push_back(I->getType());
-    ParameterAttributes Attrs = ParamAttr::None;
     if (PAL) {
-      Attrs = PAL->getParamAttrs(ParamIndex);
-      if (ParamIndex == 1) // Skip sret attribute
-        Attrs = Attrs ^ ParamAttr::StructRet;
+      ParameterAttributes Attrs = PAL->getParamAttrs(ParamIndex);
+      if (Attrs != ParamAttr::None)
+        ParamAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex - 1,
+                                                         Attrs));
     }
-    if (Attrs != ParamAttr::None)
-      ParamAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex, Attrs));
     ++I;
     ++ParamIndex;
   }
@@ -269,17 +269,17 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) {
     CallSite::arg_iterator AI = CS.arg_begin(), AE = CS.arg_end();
     Value *FirstCArg = *AI;
     ++AI;
-    unsigned ParamIndex = 1; // 0th parameter attribute is reserved for return type.
+    // 0th parameter attribute is reserved for return type.
+    // 1th parameter attribute is for first 1st sret argument.
+    unsigned ParamIndex = 2; 
     while (AI != AE) {
       Args.push_back(*AI); 
-      ParameterAttributes Attrs = ParamAttr::None;
       if (PAL) {
-        Attrs = PAL->getParamAttrs(ParamIndex);
-        if (ParamIndex == 1) // Skip sret attribute
-          Attrs = Attrs ^ ParamAttr::StructRet;
+        ParameterAttributes Attrs = PAL->getParamAttrs(ParamIndex);
+        if (Attrs != ParamAttr::None)
+          ArgAttrsVec.push_back(ParamAttrsWithIndex::get(ParamIndex - 1, 
+                                                         Attrs));
       }
-      if (Attrs != ParamAttr::None)
-        ArgAttrsVec.push_back(ParamAttrsWithIndex::get(Args.size(), Attrs));
       ++ParamIndex;
       ++AI;
     }
diff --git a/test/Transforms/SRETPromotion/2008-03-11-attributes.ll b/test/Transforms/SRETPromotion/2008-03-11-attributes.ll
new file mode 100644 (file)
index 0000000..81a1476
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | opt -sretpromotion -disable-output
+       %struct.ObjPoint = type { double, double, double, double, double, double }
+
+define void @RotatePoint(%struct.ObjPoint* sret  %agg.result, %struct.ObjPoint* byval  %a, double %rx, double %ry, double %rz) nounwind  {
+entry:
+       unreachable
+}