[cfe-commits] r48784 - in /cfe/trunk: include/clang/AST/Type.h lib/Sema/SemaDecl.cpp test/Sema/address_spaces.c

Nate Begeman natebegeman at mac.com
Tue Mar 25 11:36:32 PDT 2008


Author: sampo
Date: Tue Mar 25 13:36:32 2008
New Revision: 48784

URL: http://llvm.org/viewvc/llvm-project?rev=48784&view=rev
Log:
Extend QualType::getAddressSpace to do the right thing for array types, and in
the future, RecordTypes.

Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Sema/address_spaces.c

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=48784&r1=48783&r2=48784&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Mar 25 13:36:32 2008
@@ -1087,7 +1087,11 @@
   // FIXME: This predicate is a helper to QualType/Type. It needs to 
   // recursively check all fields for const-ness. If any field is declared
   // const, it needs to return false. 
-  bool hasConstFields() const { return false; } 
+  bool hasConstFields() const { return false; }
+
+  // FIXME: RecordType needs to check when it is created that all fields are in
+  // the same address space, and return that.
+  unsigned getAddressSpace() const { return 0; }
   
   static bool classof(const Type *T);
   static bool classof(const RecordType *) { return true; }
@@ -1114,6 +1118,10 @@
 
 /// getAddressSpace - Return the address space of this type.
 inline unsigned QualType::getAddressSpace() const {
+  if (const ArrayType *AT = dyn_cast<ArrayType>(getCanonicalType()))
+    return AT->getBaseType().getAddressSpace();
+  if (const RecordType *RT = dyn_cast<RecordType>(getCanonicalType()))
+    return RT->getAddressSpace();
   if (const ASQualType *ASQT = dyn_cast<ASQualType>(getCanonicalType()))
     return ASQT->getAddressSpace();
   return 0;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=48784&r1=48783&r2=48784&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Mar 25 13:36:32 2008
@@ -808,14 +808,9 @@
     // This includes arrays of objects with address space qualifiers, but not
     // automatic variables that point to other address spaces.
     // ISO/IEC TR 18037 S5.1.2
-    if (NewVD->hasLocalStorage()) {
-      QualType AutoTy = NewVD->getCanonicalType();
-      if (const ArrayType *AT = AutoTy->getAsArrayType())
-        AutoTy = AT->getElementType().getCanonicalType();
-      if (AutoTy.getAddressSpace() != 0) {
-        Diag(D.getIdentifierLoc(), diag::err_as_qualified_auto_decl);
-        InvalidDecl = true;
-      }
+    if (NewVD->hasLocalStorage() && (NewVD->getType().getAddressSpace() != 0)) {
+      Diag(D.getIdentifierLoc(), diag::err_as_qualified_auto_decl);
+      InvalidDecl = true;
     }
     // Merge the decl with the existing one if appropriate. If the decl is
     // in an outer scope, it isn't the same thing.

Modified: cfe/trunk/test/Sema/address_spaces.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_spaces.c?rev=48784&r1=48783&r2=48784&view=diff

==============================================================================
--- cfe/trunk/test/Sema/address_spaces.c (original)
+++ cfe/trunk/test/Sema/address_spaces.c Tue Mar 25 13:36:32 2008
@@ -12,7 +12,8 @@
   int *_AS1 _AS2 *Z;  // expected-error {{multiple address spaces specified for type}}
 
   _AS1 int local;     // expected-error {{automatic variable qualified with an address space}}
-  _AS1 int array[50]; // expected-error {{automatic variable qualified with an address space}}
+  _AS1 int array[5];  // expected-error {{automatic variable qualified with an address space}}
+  _AS1 int arrarr[5][5]; // expected-error {{automatic variable qualified with an address space}}
 
   *a = 5.0f;
 }





More information about the cfe-commits mailing list