Remember the regparm attribute in FunctionType::ExtInfo.
Fixes PR3782.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99940 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 406b820..e232230 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -7037,11 +7037,11 @@
   QualType BlockTy;
   if (!BSI->hasPrototype)
     BlockTy = Context.getFunctionType(RetTy, 0, 0, false, 0, false, false, 0, 0,
-                                  FunctionType::ExtInfo(NoReturn, CC_Default));
+                                FunctionType::ExtInfo(NoReturn, 0, CC_Default));
   else
     BlockTy = Context.getFunctionType(RetTy, ArgTypes.data(), ArgTypes.size(),
                                       BSI->isVariadic, 0, false, false, 0, 0,
-                                   FunctionType::ExtInfo(NoReturn, CC_Default));
+                                FunctionType::ExtInfo(NoReturn, 0, CC_Default));
 
   // FIXME: Check that return/parameter types are complete/non-abstract
   DiagnoseUnusedParameters(BSI->Params.begin(), BSI->Params.end());
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index ce410a7..2c6cc7f 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -1739,6 +1739,30 @@
     return false;
   }
 
+  if (Attr.getKind() == AttributeList::AT_regparm) {
+    // The warning is emitted elsewhere
+    if (Attr.getNumArgs() != 1) {
+      return false;
+    }
+
+    // Delay if this is not a function or pointer to block.
+    if (!Type->isFunctionPointerType()
+        && !Type->isBlockPointerType()
+        && !Type->isFunctionType())
+      return true;
+
+    // Otherwise we can process right away.
+    Expr *NumParamsExpr = static_cast<Expr *>(Attr.getArg(0));
+    llvm::APSInt NumParams(32);
+
+    // The warning is emitted elsewhere
+    if (!NumParamsExpr->isIntegerConstantExpr(NumParams, S.Context))
+      return false;
+
+    Type = S.Context.getRegParmType(Type, NumParams.getZExtValue());
+    return false;
+  }
+
   // Otherwise, a calling convention.
   if (Attr.getNumArgs() != 0) {
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
@@ -1868,6 +1892,7 @@
     case AttributeList::AT_cdecl:
     case AttributeList::AT_fastcall:
     case AttributeList::AT_stdcall:
+    case AttributeList::AT_regparm:
       // Don't process these on the DeclSpec.
       if (IsDeclSpec ||
           ProcessFnAttr(S, Result, *AL))