]> granicus.if.org Git - clang/commitdiff
When promoting array to pointer for argument, don't lose type qualifiers.
authorChris Lattner <sabre@nondot.org>
Wed, 2 Jan 2008 22:50:48 +0000 (22:50 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 2 Jan 2008 22:50:48 +0000 (22:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45510 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaDecl.cpp
Sema/SemaType.cpp
test/Sema/function.c [new file with mode: 0644]

index 7443d365a97726413931d86cdf83d218a9b7a47f..5a588397d9de5da12f554c75056b2c23d8c22851 100644 (file)
@@ -936,9 +936,11 @@ Sema::ActOnParamDeclarator(struct DeclaratorChunk::ParamInfo &PI, Scope *FnScope
   // we need to consider storing both types (in ParmVarDecl)...
   // 
   QualType parmDeclType = QualType::getFromOpaquePtr(PI.TypeInfo);
-  if (const ArrayType *AT = parmDeclType->getAsArrayType())
+  if (const ArrayType *AT = parmDeclType->getAsArrayType()) {
+    // int x[restrict 4] ->  int *restrict
     parmDeclType = Context.getPointerType(AT->getElementType());
-  else if (parmDeclType->isFunctionType())
+    parmDeclType = parmDeclType.getQualifiedType(AT->getIndexTypeQualifier());
+  } else if (parmDeclType->isFunctionType())
     parmDeclType = Context.getPointerType(parmDeclType);
   
   ParmVarDecl *New = new ParmVarDecl(PI.IdentLoc, II, parmDeclType, 
index c3fa8cd46f2fe1001d72d2fc3539a42ed2630f77..5e9bb3cd8238781c47d92ff0f4881d9ddbeb55ea 100644 (file)
@@ -301,9 +301,11 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
           // 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())
+          if (const ArrayType *AT = ArgTy->getAsArrayType()) {
+            // int x[restrict 4] ->  int *restrict
             ArgTy = Context.getPointerType(AT->getElementType());
-          else if (ArgTy->isFunctionType())
+            ArgTy = ArgTy.getQualifiedType(AT->getIndexTypeQualifier());
+          } 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
diff --git a/test/Sema/function.c b/test/Sema/function.c
new file mode 100644 (file)
index 0000000..751339b
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: clang %s -fsyntax-only
+// PR1892
+void f(double a[restrict][5]);  // should promote to restrict ptr.
+void f(double (* restrict a)[5]);
+