From d98e7cf7c10d3569b6d95af2d2f2ce11cd8ef5ba Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 12 May 2009 21:44:00 +0000 Subject: [PATCH] improve the diagnostic for uses of the GCC "global variable in a register" extension. This implements rdar://6880449 - improve diagnostic for usage of "global register variable" GCC extension llvm-svn: 71599 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaDecl.cpp | 8 +++++++- clang/test/Sema/decl-invalid.c | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 65a25ce93473..ed56cad330e6 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -1023,6 +1023,8 @@ def warn_tentative_incomplete_array : Warning< def err_realimag_invalid_type : Error<"invalid type %0 to %1 operator">; def err_typecheck_sclass_fscope : Error< "illegal storage class on file-scoped variable">; +def err_unsupported_global_register : Error< + "global register variables are not supported">; def err_typecheck_sclass_func : Error<"illegal storage class on function">; def err_static_block_func : Error< "function declared in block scope cannot have 'static' storage class">; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d8b6f45e37a9..b233021c42b9 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1742,7 +1742,13 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, // C99 6.9p2: The storage-class specifiers auto and register shall not // appear in the declaration specifiers in an external declaration. if (SC == VarDecl::Auto || SC == VarDecl::Register) { - Diag(D.getIdentifierLoc(), diag::err_typecheck_sclass_fscope); + + // If this is a register variable with an asm label specified, then this + // is a GNU extension. + if (SC == VarDecl::Register && D.getAsmLabel()) + Diag(D.getIdentifierLoc(), diag::err_unsupported_global_register); + else + Diag(D.getIdentifierLoc(), diag::err_typecheck_sclass_fscope); D.setInvalidType(); } } diff --git a/clang/test/Sema/decl-invalid.c b/clang/test/Sema/decl-invalid.c index e14bc9891a45..051f0f7ffbcc 100644 --- a/clang/test/Sema/decl-invalid.c +++ b/clang/test/Sema/decl-invalid.c @@ -20,3 +20,10 @@ const int; // expected-error {{declaration does not declare anything}} struct; // expected-error {{declaration of anonymous struct must be a definition}} // expected-error {{declaration does not declare anything}} typedef int I; I; // expected-error {{declaration does not declare anything}} + + + +// rdar://6880449 +register int test1; // expected-error {{illegal storage class on file-scoped variable}} +register int test2 __asm__("edi"); // expected-error {{global register variables are not supported}} +