[cfe-commits] r45510 - in /cfe/trunk: Sema/SemaDecl.cpp Sema/SemaType.cpp test/Sema/function.c
Chris Lattner
sabre at nondot.org
Wed Jan 2 14:50:48 PST 2008
Author: lattner
Date: Wed Jan 2 16:50:48 2008
New Revision: 45510
URL: http://llvm.org/viewvc/llvm-project?rev=45510&view=rev
Log:
When promoting array to pointer for argument, don't lose type qualifiers.
Added:
cfe/trunk/test/Sema/function.c
Modified:
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/Sema/SemaType.cpp
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=45510&r1=45509&r2=45510&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Jan 2 16:50:48 2008
@@ -936,9 +936,11 @@
// 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,
Modified: cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaType.cpp?rev=45510&r1=45509&r2=45510&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Wed Jan 2 16:50:48 2008
@@ -301,9 +301,11 @@
// 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
Added: cfe/trunk/test/Sema/function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/function.c?rev=45510&view=auto
==============================================================================
--- cfe/trunk/test/Sema/function.c (added)
+++ cfe/trunk/test/Sema/function.c Wed Jan 2 16:50:48 2008
@@ -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]);
+
More information about the cfe-commits
mailing list