From 5af27e02917089dd107c58c1cfdb064544010773 Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Fri, 14 Mar 2008 00:22:18 +0000 Subject: [PATCH] ISO/IEC TR 18037 An address space name cannot be used to qualify an object that has automatic storage duration. Still not catching ASQual'd allocas of array type, just scalars at the moment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48350 91177308-0d34-0410-b5e6-96231b3b80d8 --- Sema/SemaDecl.cpp | 9 +++++++-- include/clang/Basic/DiagnosticKinds.def | 2 ++ test/Sema/address_spaces.c | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 7307fc4762..28940ac939 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -757,7 +757,6 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) { D.getDeclSpec().isInlineSpecified(), LastDeclarator); // Handle attributes. - HandleDeclAttributes(NewFD, D.getDeclSpec().getAttributes(), D.getAttributes()); @@ -801,7 +800,13 @@ 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; + } // Merge the decl with the existing one if appropriate. If the decl is // in an outer scope, it isn't the same thing. if (PrevDecl && S->isDeclScope(PrevDecl)) { diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index ffad46609f..c3825624e4 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -584,6 +584,8 @@ DIAG(err_attribute_address_space_not_int, ERROR, "address space attribute requires an integer constant") DIAG(err_attribute_address_multiple_qualifiers, ERROR, "multiple address spaces specified for type") +DIAG(err_as_qualified_auto_decl, ERROR, + "automatic variable qualified with an address space") DIAG(err_attribute_annotate_no_string, ERROR, "argument to annotate attribute was not a string literal") DIAG(warn_attribute_ignored, WARNING, diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c index 7171567d63..abf8cbdceb 100644 --- a/test/Sema/address_spaces.c +++ b/test/Sema/address_spaces.c @@ -11,5 +11,7 @@ void foo(_AS3 float *a) { 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}} + *a = 5.0f; } -- 2.40.0