diff options
author | Nate Begeman <natebegeman@mac.com> | 2008-03-14 18:07:10 +0000 |
---|---|---|
committer | Nate Begeman <natebegeman@mac.com> | 2008-03-14 18:07:10 +0000 |
commit | c8e89a8ce5057750c338854085dca26f8d3136ac (patch) | |
tree | 51e6e599d95919085726368000f3ed2d7b59d404 | |
parent | 63bbe5312cd89ce0ceb684bff68c5baef636e93c (diff) |
Correctly error on arrays with automatic storage full of objects with
non-default address space, and fix comment.
Add a test for this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48366 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Sema/SemaDecl.cpp | 19 | ||||
-rw-r--r-- | test/Sema/address_spaces.c | 5 |
2 files changed, 16 insertions, 8 deletions
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 28940ac939..300a38259b 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -800,12 +800,19 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) { // Handle attributes prior to checking for duplicates in MergeVarDecl HandleDeclAttributes(NewVD, D.getDeclSpec().getAttributes(), D.getAttributes()); - // Emit a warning (error?) if an address space was applied to decl with - // local storage. - if (NewVD->hasLocalStorage() && - (NewVD->getCanonicalType().getAddressSpace() != 0)) { - Diag(D.getIdentifierLoc(), diag::err_as_qualified_auto_decl); - InvalidDecl = true; + + // Emit an error if an address space was applied to decl with local storage. + // 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; + } } // Merge the decl with the existing one if appropriate. If the decl is // in an outer scope, it isn't the same thing. diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c index abf8cbdceb..002ba13088 100644 --- a/test/Sema/address_spaces.c +++ b/test/Sema/address_spaces.c @@ -8,10 +8,11 @@ void foo(_AS3 float *a) { _AS2 *x; _AS1 float * _AS2 *B; - int _AS1 _AS2 *Y; // expected-error {{multiple address spaces specified for type}} + int _AS1 _AS2 *Y; // expected-error {{multiple address spaces specified for type}} 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 local; // expected-error {{automatic variable qualified with an address space}} + _AS1 int array[50]; // expected-error {{automatic variable qualified with an address space}} *a = 5.0f; } |