[cfe-commits] r155603 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/Sema/attr-visibility.c
Rafael Espindola
rafael.espindola at gmail.com
Wed Apr 25 18:26:04 PDT 2012
Author: rafael
Date: Wed Apr 25 20:26:03 2012
New Revision: 155603
URL: http://llvm.org/viewvc/llvm-project?rev=155603&view=rev
Log:
Reject cases like
struct __attribute__((visibility("hidden"))) a;
struct __attribute__((visibility("default"))) b;
which gcc already rejects.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/attr-visibility.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=155603&r1=155602&r2=155603&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Apr 25 20:26:03 2012
@@ -1815,6 +1815,8 @@
def warn_attribute_protected_visibility :
Warning<"target does not support 'protected' visibility; using 'default'">,
InGroup<DiagGroup<"unsupported-visibility">>;
+def err_mismatched_visibilit: Error<"visibility does not match previous declaration">;
+def note_previous_attribute : Note<"previous attribute is here">;
def err_unknown_machine_mode : Error<"unknown machine mode %0">;
def err_unsupported_machine_mode : Error<"unsupported machine mode %0">;
def err_mode_not_primitive : Error<
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=155603&r1=155602&r2=155603&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Apr 25 20:26:03 2012
@@ -1752,6 +1752,15 @@
return;
}
+ VisibilityAttr *PrevAttr = D->getCanonicalDecl()->getAttr<VisibilityAttr>();
+ if (PrevAttr) {
+ VisibilityAttr::VisibilityType PrevVisibility = PrevAttr->getVisibility();
+ if (PrevVisibility != type) {
+ S.Diag(Attr.getLoc(), diag::err_mismatched_visibilit);
+ S.Diag(PrevAttr->getLocation(), diag::note_previous_attribute);
+ return;
+ }
+ }
D->addAttr(::new (S.Context) VisibilityAttr(Attr.getRange(), S.Context, type));
}
Modified: cfe/trunk/test/Sema/attr-visibility.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-visibility.c?rev=155603&r1=155602&r2=155603&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-visibility.c (original)
+++ cfe/trunk/test/Sema/attr-visibility.c Wed Apr 25 20:26:03 2012
@@ -7,3 +7,5 @@
// rdar://problem/10753392
void test3() __attribute__((visibility("protected"))); // expected-warning {{target does not support 'protected' visibility; using 'default'}}
+struct __attribute__((visibility("hidden"))) test4; // expected-note {{previous attribute is here}}
+struct __attribute__((visibility("default"))) test4; // expected-error {{visibility does not match previous declaration}}
More information about the cfe-commits
mailing list