From: Fariborz Jahanian Date: Fri, 17 Aug 2012 21:44:55 +0000 (+0000) Subject: c: privide deprecated warning when __private_extern__ storage X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=767a1a2391e60e358ed7d793e091cc1731a5e186;p=clang c: privide deprecated warning when __private_extern__ storage specifier is unsed in a declaration; as it may not make the symbol local to linkage unit as intended. Suggest using "hidden" visibility attribute instead. // rdar://7703982 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162138 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index c00c9a8150..0623966279 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1490,10 +1490,10 @@ def note_non_literal_user_provided_dtor : Note< def note_non_literal_nontrivial_dtor : Note< "%0 is not literal because it has a non-trivial destructor">; def warn_private_extern : Warning< - "Use of __private_extern__ on tentative definition has unexpected" - " behaviour - use __attribute__((visibility(\"hidden\"))) on extern" - " declaration or definition instead">, - InGroup, DefaultIgnore; + "use of __private_extern__ on a declaration may not produce external symbol " + "private to the linkage unit and is deprecated">, InGroup; +def note_private_extern : Note< + "use __attribute__((visibility(\"hidden\"))) attribute instead">; // C++11 char16_t/char32_t def warn_cxx98_compat_unicode_type : Warning< diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index ea181de00a..e1b146d9b4 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -6758,8 +6758,10 @@ void Sema::ActOnUninitializedDecl(Decl *RealDecl, AbstractVariableType)) Var->setInvalidDecl(); if (!Type->isDependentType() && !Var->isInvalidDecl() && - Var->getStorageClass() == SC_PrivateExtern) + Var->getStorageClass() == SC_PrivateExtern) { Diag(Var->getLocation(), diag::warn_private_extern); + Diag(Var->getLocation(), diag::note_private_extern); + } return; diff --git a/test/Sema/asm.c b/test/Sema/asm.c index 44d83e9214..155d736b99 100644 --- a/test/Sema/asm.c +++ b/test/Sema/asm.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -triple i386-pc-linux-gnu -verify -fsyntax-only +// RUN: %clang_cc1 %s -Wno-private-extern -triple i386-pc-linux-gnu -verify -fsyntax-only void f() { int i; diff --git a/test/Sema/attr-used.c b/test/Sema/attr-used.c index 0838816924..e2dfab141a 100644 --- a/test/Sema/attr-used.c +++ b/test/Sema/attr-used.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only %s +// RUN: %clang_cc1 -verify -fsyntax-only -Wno-private-extern %s extern int l0 __attribute__((used)); // expected-warning {{used attribute ignored}} __private_extern__ int l1 __attribute__((used)); // expected-warning {{used attribute ignored}} diff --git a/test/Sema/private-extern.c b/test/Sema/private-extern.c index 25591dc5b1..e480f3f224 100644 --- a/test/Sema/private-extern.c +++ b/test/Sema/private-extern.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -verify -fsyntax-only %s +// RUN: %clang_cc1 -verify -fsyntax-only -Wno-private-extern %s static int g0; // expected-note{{previous definition}} int g0; // expected-error{{non-static declaration of 'g0' follows static declaration}} diff --git a/test/Sema/tentative-decls.c b/test/Sema/tentative-decls.c index e14540ba84..bf2b1e4ee6 100644 --- a/test/Sema/tentative-decls.c +++ b/test/Sema/tentative-decls.c @@ -33,7 +33,8 @@ static int i3 = 5; extern int i3; // rdar://7703982 -__private_extern__ int pExtern; // expected-warning {{Use of __private_extern__ on tentative definition has unexpected behaviour}} +__private_extern__ int pExtern; // expected-warning {{use of __private_extern__ on a declaration may not produce external symbol private to the linkage unit and is deprecated}} \ +// expected-note {{use __attribute__((visibility("hidden"))) attribute instead}} int pExtern = 0; int i4; diff --git a/test/Sema/thread-specifier.c b/test/Sema/thread-specifier.c index 0d439b1669..c06aad8acb 100644 --- a/test/Sema/thread-specifier.c +++ b/test/Sema/thread-specifier.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify -pedantic %s +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic %s __thread int t1; __thread extern int t2; // expected-warning {{'__thread' before 'extern'}}