[cfe-commits] r48366 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/address_spaces.c

Chris Lattner clattner at apple.com
Fri Mar 14 14:38:13 PDT 2008


On Mar 14, 2008, at 11:07 AM, Nate Begeman wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=48366&view=rev
> Log:
> Correctly error on arrays with automatic storage full of objects with
> non-default address space, and fix comment.
> Add a test for this.

Hey Nate,

I don't think this is the right fix.  It will probably fail for _AS1  
int x[10][10] for example.  I think that the fix is to propagate the  
address space qualifier out of structs and arrays when formed.   
Specifically, if you have:

_AS1 int x;

we should have: ASQualType(int, 1)

if we have:

_AS1 int x[10];

we currently have:  ArrayType(ASQualType(int, 1), 10)

but I think we should get:

ASQualType(ArrayType(int, 10), 1)

What do you think?  This means that the sema for applying  
constructoring arrays (in SemaType) should be aware of this.

-Chris

> Modified:
>    cfe/trunk/Sema/SemaDecl.cpp
>    cfe/trunk/test/Sema/address_spaces.c
>
> Modified: cfe/trunk/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=48366&r1=48365&r2=48366&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/Sema/SemaDecl.cpp Fri Mar 14 13:07:10 2008
> @@ -800,12 +800,19 @@
>     // 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.
>
> Modified: cfe/trunk/test/Sema/address_spaces.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/address_spaces.c?rev=48366&r1=48365&r2=48366&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/test/Sema/address_spaces.c (original)
> +++ cfe/trunk/test/Sema/address_spaces.c Fri Mar 14 13:07:10 2008
> @@ -8,10 +8,11 @@
>   _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;
> }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list