forked from OSchip/llvm-project
Implement -fvisibility-inlines-hidden. <rdar://problem/7819834>
llvm-svn: 106003
This commit is contained in:
parent
246e9a07a2
commit
0832963acd
|
@ -102,6 +102,8 @@ public:
|
|||
unsigned DumpRecordLayouts : 1; /// Dump the layout of IRgen'd records.
|
||||
unsigned DumpVTableLayouts : 1; /// Dump the layouts of emitted vtables.
|
||||
unsigned NoConstantCFStrings : 1; // Do not do CF strings
|
||||
unsigned InlineVisibilityHidden : 1; // Whether inline C++ methods have
|
||||
// hidden visibility by default.
|
||||
|
||||
// FIXME: This is just a temporary option, for testing purposes.
|
||||
unsigned NoBitFieldTypeAlign : 1;
|
||||
|
@ -135,7 +137,7 @@ public:
|
|||
GNUMode = GNUKeywords = ImplicitInt = Digraphs = 0;
|
||||
HexFloats = 0;
|
||||
GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 0;
|
||||
NoConstantCFStrings = 0;
|
||||
NoConstantCFStrings = 0; InlineVisibilityHidden = 0;
|
||||
C99 = Microsoft = CPlusPlus = CPlusPlus0x = 0;
|
||||
CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0;
|
||||
Exceptions = SjLjExceptions = Freestanding = NoBuiltin = 0;
|
||||
|
@ -146,7 +148,7 @@ public:
|
|||
AltiVec = OpenCL = StackProtector = 0;
|
||||
|
||||
SymbolVisibility = (unsigned) Default;
|
||||
|
||||
|
||||
ThreadsafeStatics = 1;
|
||||
POSIXThreads = 0;
|
||||
Blocks = 0;
|
||||
|
|
|
@ -437,6 +437,8 @@ def stack_protector : Separate<"-stack-protector">,
|
|||
HelpText<"Enable stack protectors">;
|
||||
def fvisibility : Separate<"-fvisibility">,
|
||||
HelpText<"Default symbol visibility">;
|
||||
def fvisibility_inlines_hidden : Flag<"-fvisibility-inlines-hidden">,
|
||||
HelpText<"Give inline C++ member functions default visibility by default">;
|
||||
def ftemplate_depth : Separate<"-ftemplate-depth">,
|
||||
HelpText<"Maximum depth of recursive template instantiation">;
|
||||
def trigraphs : Flag<"-trigraphs">,
|
||||
|
|
|
@ -383,6 +383,7 @@ def funwind_tables : Flag<"-funwind-tables">, Group<f_Group>;
|
|||
def fuse_cxa_atexit : Flag<"-fuse-cxa-atexit">, Group<f_Group>;
|
||||
def fverbose_asm : Flag<"-fverbose-asm">, Group<f_Group>;
|
||||
def fvisibility_EQ : Joined<"-fvisibility=">, Group<f_Group>;
|
||||
def fvisibility_inlines_hidden : Flag<"-fvisibility-inlines-hidden">, Group<f_Group>;
|
||||
def fwritable_strings : Flag<"-fwritable-strings">, Group<f_Group>;
|
||||
def fzero_initialized_in_bss : Flag<"-fzero-initialized-in-bss">, Group<f_Group>;
|
||||
def ffunction_sections: Flag <"-ffunction-sections">, Group<f_Group>;
|
||||
|
|
|
@ -152,6 +152,13 @@ CodeGenModule::getDeclVisibilityMode(const Decl *D) const {
|
|||
}
|
||||
}
|
||||
|
||||
// If -fvisibility-inlines-hidden was provided, then inline C++ member
|
||||
// functions get "hidden" visibility by default.
|
||||
if (getLangOptions().InlineVisibilityHidden)
|
||||
if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D))
|
||||
if (Method->isInlined())
|
||||
return LangOptions::Hidden;
|
||||
|
||||
// This decl should have the same visibility as its parent.
|
||||
if (const DeclContext *DC = D->getDeclContext())
|
||||
return getDeclVisibilityMode(cast<Decl>(DC));
|
||||
|
|
|
@ -1149,6 +1149,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
CmdArgs.push_back(A->getValue(Args));
|
||||
}
|
||||
|
||||
Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden);
|
||||
|
||||
// -fhosted is default.
|
||||
if (KernelOrKext || Args.hasFlag(options::OPT_ffreestanding,
|
||||
options::OPT_fhosted,
|
||||
|
|
|
@ -595,6 +595,9 @@ static void LangOptsToArgs(const LangOptions &Opts,
|
|||
Res.push_back("protected");
|
||||
}
|
||||
}
|
||||
if (Opts.InlineVisibilityHidden)
|
||||
Res.push_back("-fvisibility-inlines-hidden");
|
||||
|
||||
if (Opts.getStackProtectorMode() != 0) {
|
||||
Res.push_back("-stack-protector");
|
||||
Res.push_back(llvm::utostr(Opts.getStackProtectorMode()));
|
||||
|
@ -1238,6 +1241,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
|
|||
Diags.Report(diag::err_drv_invalid_value)
|
||||
<< Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis;
|
||||
|
||||
if (Args.hasArg(OPT_fvisibility_inlines_hidden))
|
||||
Opts.InlineVisibilityHidden = 1;
|
||||
|
||||
Opts.OverflowChecking = Args.hasArg(OPT_ftrapv);
|
||||
|
||||
// Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
|
||||
|
|
|
@ -1976,6 +1976,8 @@ TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New,
|
|||
Proto->getExtInfo()));
|
||||
}
|
||||
|
||||
InstantiateAttrs(Tmpl, New);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
// RUN: %clang_cc1 -fvisibility-inlines-hidden -emit-llvm -o - %s | FileCheck %s
|
||||
struct X0 {
|
||||
void __attribute__((visibility("default"))) f1() { }
|
||||
void f2() { }
|
||||
void f3();
|
||||
static void f5() { }
|
||||
virtual void f6() { }
|
||||
};
|
||||
|
||||
inline void X0::f3() { }
|
||||
|
||||
template<typename T>
|
||||
struct X1 {
|
||||
void __attribute__((visibility("default"))) f1() { }
|
||||
void f2() { }
|
||||
void f3();
|
||||
void f4();
|
||||
static void f5() { }
|
||||
virtual void f6() { }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline void X1<T>::f3() { }
|
||||
|
||||
template<>
|
||||
inline void X1<int>::f4() { }
|
||||
|
||||
struct __attribute__((visibility("default"))) X2 {
|
||||
void f2() { }
|
||||
};
|
||||
|
||||
void use(X0 *x0, X1<int> *x1, X2 *x2) {
|
||||
// CHECK: define linkonce_odr void @_ZN2X02f1Ev
|
||||
x0->f1();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X02f2Ev
|
||||
x0->f2();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X02f3Ev
|
||||
x0->f3();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X02f5Ev
|
||||
X0::f5();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X02f6Ev
|
||||
x0->X0::f6();
|
||||
// CHECK: define linkonce_odr void @_ZN2X1IiE2f1Ev
|
||||
x1->f1();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f2Ev
|
||||
x1->f2();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f3Ev
|
||||
x1->f3();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f4Ev
|
||||
x1->f4();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f5Ev
|
||||
X1<int>::f5();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X1IiE2f6Ev
|
||||
x1->X1::f6();
|
||||
// CHECK: define linkonce_odr hidden void @_ZN2X22f2Ev
|
||||
x2->f2();
|
||||
}
|
Loading…
Reference in New Issue