Complain about attempts to use 'protected' visibility on targets

like Darwin that don't support it.  We should also complain about
invalid -fvisibility=protected, but that information doesn't seem
to exist at the most appropriate time, so I've left a FIXME behind.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149186 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
John McCall 2012-01-29 01:20:30 +00:00
Родитель de2fdc249e
Коммит 4188760f6b
7 изменённых файлов: 44 добавлений и 5 удалений

Просмотреть файл

@ -1740,6 +1740,9 @@ def warn_transparent_union_attribute_zero_fields : Warning<
def warn_attribute_type_not_supported : Warning< def warn_attribute_type_not_supported : Warning<
"'%0' attribute argument not supported: %1">; "'%0' attribute argument not supported: %1">;
def warn_attribute_unknown_visibility : Warning<"unknown visibility '%0'">; 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_unknown_machine_mode : Error<"unknown machine mode %0">; def err_unknown_machine_mode : Error<"unknown machine mode %0">;
def err_unsupported_machine_mode : Error<"unsupported machine mode %0">; def err_unsupported_machine_mode : Error<"unsupported machine mode %0">;
def err_mode_not_primitive : Error< def err_mode_not_primitive : Error<

Просмотреть файл

@ -479,6 +479,19 @@ public:
const unsigned RegNum; const unsigned RegNum;
}; };
/// hasProtectedVisibility - Does this target support "protected"
/// visibility?
///
/// Any target which dynamic libraries will naturally support
/// something like "default" (meaning that the symbol is visible
/// outside this shared object) and "hidden" (meaning that it isn't)
/// visibilities, but "protected" is really an ELF-specific concept
/// with wierd semantics designed around the convenience of dynamic
/// linker implementations. Which is not to suggest that there's
/// consistent target-independent semantics for "default" visibility
/// either; the entire thing is pretty badly mangled.
virtual bool hasProtectedVisibility() const { return true; }
virtual bool useGlobalsForAutomaticVariables() const { return false; } virtual bool useGlobalsForAutomaticVariables() const { return false; }
/// getCFStringSection - Return the section to use for CFString /// getCFStringSection - Return the section to use for CFString

Просмотреть файл

@ -218,6 +218,12 @@ public:
return "__TEXT,__StaticInit,regular,pure_instructions"; return "__TEXT,__StaticInit,regular,pure_instructions";
} }
/// Darwin does not support protected visibility. Darwin's "default"
/// is very similar to ELF's "protected"; Darwin requires a "weak"
/// attribute on declarations that can be dynamically replaced.
virtual bool hasProtectedVisibility() const {
return false;
}
}; };

Просмотреть файл

@ -1792,6 +1792,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
else if (Vis == "hidden") else if (Vis == "hidden")
Opts.setVisibilityMode(HiddenVisibility); Opts.setVisibilityMode(HiddenVisibility);
else if (Vis == "protected") else if (Vis == "protected")
// FIXME: diagnose if target does not support protected visibility
Opts.setVisibilityMode(ProtectedVisibility); Opts.setVisibilityMode(ProtectedVisibility);
else else
Diags.Report(diag::err_drv_invalid_value) Diags.Report(diag::err_drv_invalid_value)

Просмотреть файл

@ -1694,9 +1694,16 @@ static void handleVisibilityAttr(Sema &S, Decl *D, const AttributeList &Attr) {
type = VisibilityAttr::Hidden; type = VisibilityAttr::Hidden;
else if (TypeStr == "internal") else if (TypeStr == "internal")
type = VisibilityAttr::Hidden; // FIXME type = VisibilityAttr::Hidden; // FIXME
else if (TypeStr == "protected") else if (TypeStr == "protected") {
type = VisibilityAttr::Protected; // Complain about attempts to use protected visibility on targets
else { // (like Darwin) that don't support it.
if (!S.Context.getTargetInfo().hasProtectedVisibility()) {
S.Diag(Attr.getLoc(), diag::warn_attribute_protected_visibility);
type = VisibilityAttr::Default;
} else {
type = VisibilityAttr::Protected;
}
} else {
S.Diag(Attr.getLoc(), diag::warn_attribute_unknown_visibility) << TypeStr; S.Diag(Attr.getLoc(), diag::warn_attribute_unknown_visibility) << TypeStr;
return; return;
} }

Просмотреть файл

@ -1,5 +1,5 @@
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o - | FileCheck -check-prefix=HIDDEN %s // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -fhidden-weak-vtables -emit-llvm -o - | FileCheck -check-prefix=HIDDEN %s
namespace Test1 { namespace Test1 {

Просмотреть файл

@ -0,0 +1,9 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
void test0() __attribute__((visibility("default")));
void test1() __attribute__((visibility("hidden")));
void test2() __attribute__((visibility("internal")));
// rdar://problem/10753392
void test3() __attribute__((visibility("protected"))); // expected-warning {{target does not support 'protected' visibility; using 'default'}}