Fix several bugs in array -> pointer decomposition.

First, we got several CVR propagation cases wrong, which Eli pointed
out in PR2039.

Second, we didn't propagate address space qualifiers correctly, leading
to incorrect lowering of code in CodeGen/address-space.c.

Third, we didn't uniformly propagate the specifier in the array to the
pointer ("int[restrict 4]" -> "int *restrict").

This adds an ASTContext::getArrayDecayedType member that handles the 
non-trivial logic for this seemingly simple operation.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49078 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index ad9d138..5874477 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -317,18 +317,17 @@
           // type in ParmVarDecl (which makes the code generator unhappy).
           //
           // FIXME: We still apparently need the conversion in 
-          // Sema::ParseParamDeclarator(). This doesn't make any sense, since
+          // Sema::ActOnParamDeclarator(). This doesn't make any sense, since
           // it should be driving off the type being created here.
           // 
           // FIXME: If a source translation tool needs to see the original type,
           // then we need to consider storing both types somewhere...
           // 
-          if (const ArrayType *AT = ArgTy->getAsArrayType()) {
-            // int x[restrict 4] ->  int *restrict
-            ArgTy = Context.getPointerType(AT->getElementType());
-            ArgTy = ArgTy.getQualifiedType(AT->getIndexTypeQualifier());
+          if (ArgTy->isArrayType()) {
+            ArgTy = Context.getArrayDecayedType(ArgTy);
           } else if (ArgTy->isFunctionType())
             ArgTy = Context.getPointerType(ArgTy);
+          
           // Look for 'void'.  void is allowed only as a single argument to a
           // function with no other parameters (C99 6.7.5.3p10).  We record
           // int(void) as a FunctionTypeProto with an empty argument list.
@@ -391,9 +390,9 @@
     assert(!ArgTy.isNull() && "Couldn't parse type?");
     // Perform the default function/array conversion (C99 6.7.5.3p[7,8]).
     // This matches the conversion that is done in 
-    // Sema::ParseParamDeclarator(). 
-    if (const ArrayType *AT = ArgTy->getAsArrayType())
-      ArgTy = Context.getPointerType(AT->getElementType());
+    // Sema::ActOnParamDeclarator(). 
+    if (ArgTy->isArrayType())
+      ArgTy = Context.getArrayDecayedType(ArgTy);
     else if (ArgTy->isFunctionType())
       ArgTy = Context.getPointerType(ArgTy);
     ArgTys.push_back(ArgTy);