From: Chris Lattner Date: Wed, 2 Jan 2008 22:50:48 +0000 (+0000) Subject: When promoting array to pointer for argument, don't lose type qualifiers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=529bd02affa96a311dd9ab131f2ab4d833017fb7;p=clang When promoting array to pointer for argument, don't lose type qualifiers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45510 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 7443d365a9..5a588397d9 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -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, diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp index c3fa8cd46f..5e9bb3cd82 100644 --- a/Sema/SemaType.cpp +++ b/Sema/SemaType.cpp @@ -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 index 0000000000..751339b79a --- /dev/null +++ b/test/Sema/function.c @@ -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]); +