summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-02 22:50:48 +0000
committerChris Lattner <sabre@nondot.org>2008-01-02 22:50:48 +0000
commit4f203511427272d5a9d3c79e6a1c6796a1fad97d (patch)
tree936b8c03654cee52a2e151a247a58de09137f1c5
parent41e423a6f59445783d3332a3f0af088c1f73bace (diff)
downloadbcm5719-llvm-4f203511427272d5a9d3c79e6a1c6796a1fad97d.tar.gz
bcm5719-llvm-4f203511427272d5a9d3c79e6a1c6796a1fad97d.zip
When promoting array to pointer for argument, don't lose type qualifiers.
llvm-svn: 45510
-rw-r--r--clang/Sema/SemaDecl.cpp6
-rw-r--r--clang/Sema/SemaType.cpp6
-rw-r--r--clang/test/Sema/function.c5
3 files changed, 13 insertions, 4 deletions
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index 7443d365a97..5a588397d9d 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/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/clang/Sema/SemaType.cpp b/clang/Sema/SemaType.cpp
index c3fa8cd46f2..5e9bb3cd823 100644
--- a/clang/Sema/SemaType.cpp
+++ b/clang/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/clang/test/Sema/function.c b/clang/test/Sema/function.c
new file mode 100644
index 00000000000..751339b79ab
--- /dev/null
+++ b/clang/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]);
+
OpenPOWER on IntegriCloud