summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp9
-rw-r--r--clang/test/Sema/attr-visibility.c2
3 files changed, 13 insertions, 0 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b0e5deba517..8826d0397be 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1815,6 +1815,8 @@ def warn_attribute_unknown_visibility : Warning<"unknown visibility '%0'">;
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<
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 861b91420d5..0e1c43c7a47 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1752,6 +1752,15 @@ static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr) {
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));
}
diff --git a/clang/test/Sema/attr-visibility.c b/clang/test/Sema/attr-visibility.c
index 5cf269582ab..afeb4f1546f 100644
--- a/clang/test/Sema/attr-visibility.c
+++ b/clang/test/Sema/attr-visibility.c
@@ -7,3 +7,5 @@ void test2() __attribute__((visibility("internal")));
// 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}}
OpenPOWER on IntegriCloud