From: Daniel Dunbar Date: Wed, 3 Sep 2008 21:54:21 +0000 (+0000) Subject: Set register storage class correctly for function parameters. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33ad0120264da35db85ff8cccee5f08da6a7fbeb;p=clang Set register storage class correctly for function parameters. - PR2730 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55739 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index cc1ace7b33..b45611ca59 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1421,8 +1421,10 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { const DeclSpec &DS = D.getDeclSpec(); // Verify C99 6.7.5.3p2: The only SCS allowed is 'register'. - if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified && - DS.getStorageClassSpec() != DeclSpec::SCS_register) { + VarDecl::StorageClass StorageClass = VarDecl::None; + if (DS.getStorageClassSpec() == DeclSpec::SCS_register) { + StorageClass = VarDecl::Register; + } else if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified) { Diag(DS.getStorageClassSpecLoc(), diag::err_invalid_storage_class_in_func_decl); D.getMutableDeclSpec().ClearStorageClassSpecs(); @@ -1485,7 +1487,7 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) { ParmVarDecl *New = ParmVarDecl::Create(Context, CurContext, D.getIdentifierLoc(), II, - parmDeclType, VarDecl::None, + parmDeclType, StorageClass, 0, 0); if (D.getInvalidType()) diff --git a/test/Sema/expr-address-of.c b/test/Sema/expr-address-of.c index 20390429dd..58bc540a30 100644 --- a/test/Sema/expr-address-of.c +++ b/test/Sema/expr-address-of.c @@ -86,3 +86,6 @@ void f5() { int *_dummy1 = &(arr + 1); // expected-error {{address expression must be an lvalue or a function designator}} } +void f6(register int x) { + int * dummy0 = &x; // expected-error {{address of register variable requested}} +}