parent
9c186c5d27
commit
befc9dfbff
|
@ -64,14 +64,19 @@ public:
|
|||
|
||||
unsigned HeinousExtensions : 1; // Extensions that we really don't like and
|
||||
// may be ripped out at any time.
|
||||
|
||||
private:
|
||||
unsigned GC : 2; // Objective-C Garbage Collection modes. We declare
|
||||
// this enum as unsigned because MSVC insists on making enums
|
||||
// signed. Set/Query this value using accessors.
|
||||
unsigned SymbolVisibility : 3; // Symbol's visibility.
|
||||
|
||||
public:
|
||||
unsigned InstantiationDepth; // Maximum template instantiation depth.
|
||||
|
||||
enum GCMode { NonGC, GCOnly, HybridGC };
|
||||
enum VisibilityMode {NonVisibility, DefaultVisibility, ProtectedVisibility,
|
||||
HiddenVisibility, InternalVisibility };
|
||||
|
||||
LangOptions() {
|
||||
Trigraphs = BCPLComment = DollarIdents = AsmPreprocessor = 0;
|
||||
|
@ -97,6 +102,9 @@ public:
|
|||
|
||||
GCMode getGCMode() const { return (GCMode) GC; }
|
||||
void setGCMode(GCMode m) { GC = (unsigned) m; }
|
||||
|
||||
VisibilityMode getVisibilityMode() const { return (VisibilityMode) SymbolVisibility; }
|
||||
void setVisibilityMode(VisibilityMode v) { SymbolVisibility = (unsigned) v; }
|
||||
|
||||
/// Emit - Emit this LangOptions object to bitcode.
|
||||
void Emit(llvm::Serializer& S) const;
|
||||
|
|
|
@ -451,6 +451,7 @@ OPTION("-ftraditional", ftraditional, Flag, f_Group, INVALID, "", 0, 0, 0)
|
|||
OPTION("-ftrapv", ftrapv, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
|
||||
OPTION("-funwind-tables", funwind_tables, Flag, f_Group, INVALID, "", 0, 0, 0)
|
||||
OPTION("-fverbose-asm", fverbose_asm, Flag, f_Group, INVALID, "", 0, 0, 0)
|
||||
OPTION("-fvisibility=", f_visibility_EQ, Joined, clang_f_Group, INVALID, "", 0, 0, 0)
|
||||
OPTION("-fwritable-strings", fwritable_strings, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
|
||||
OPTION("-fzero-initialized-in-bss", fzero_initialized_in_bss, Flag, f_Group, INVALID, "", 0, 0, 0)
|
||||
OPTION("-f", f, Joined, f_Group, INVALID, "", 0, 0, 0)
|
||||
|
|
|
@ -113,6 +113,25 @@ static void setGlobalVisibility(llvm::GlobalValue *GV,
|
|||
}
|
||||
}
|
||||
|
||||
static void setGlobalOptionVisibility(llvm::GlobalValue *GV,
|
||||
LangOptions::VisibilityMode Vis) {
|
||||
switch (Vis) {
|
||||
default: assert(0 && "Unknown visibility!");
|
||||
case LangOptions::NonVisibility:
|
||||
break;
|
||||
case LangOptions::DefaultVisibility:
|
||||
GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
|
||||
break;
|
||||
case LangOptions::HiddenVisibility:
|
||||
GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
|
||||
break;
|
||||
case LangOptions::ProtectedVisibility:
|
||||
GV->setVisibility(llvm::GlobalValue::ProtectedVisibility);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// \brief Retrieves the mangled name for the given declaration.
|
||||
///
|
||||
/// If the given declaration requires a mangled name, returns an
|
||||
|
@ -247,7 +266,8 @@ void CodeGenModule::SetGlobalValueAttributes(const Decl *D,
|
|||
// -fvisibility, and private_extern.
|
||||
if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>())
|
||||
setGlobalVisibility(GV, attr->getVisibility());
|
||||
// FIXME: else handle -fvisibility
|
||||
else
|
||||
setGlobalOptionVisibility(GV, getLangOptions().getVisibilityMode());
|
||||
|
||||
if (const SectionAttr *SA = D->getAttr<SectionAttr>())
|
||||
GV->setSection(SA->getName());
|
||||
|
@ -751,7 +771,8 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
|
|||
|
||||
if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>())
|
||||
setGlobalVisibility(GV, attr->getVisibility());
|
||||
// FIXME: else handle -fvisibility
|
||||
else
|
||||
setGlobalOptionVisibility(GV, getLangOptions().getVisibilityMode());
|
||||
|
||||
// Set the llvm linkage type as appropriate.
|
||||
if (D->getStorageClass() == VarDecl::Static)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
// RUN: clang-cc -fvisibility=hidden -emit-llvm -o - %s | grep -e "hidden" | count 2
|
||||
|
||||
int Global = 10;
|
||||
|
||||
void Func() {}
|
||||
|
|
@ -764,6 +764,28 @@ void InitializeGCMode(LangOptions &Options) {
|
|||
Options.setGCMode(LangOptions::HybridGC);
|
||||
}
|
||||
|
||||
static llvm::cl::opt<std::string>
|
||||
SymbolVisibility("fvisibility",
|
||||
llvm::cl::desc("Set the default visibility to the specific option"));
|
||||
|
||||
void InitializeSymbolVisibility(LangOptions &Options) {
|
||||
if (SymbolVisibility.empty())
|
||||
return;
|
||||
std::string Visibility = SymbolVisibility;
|
||||
const char *vkind = Visibility.c_str();
|
||||
if (!strcmp(vkind, "default"))
|
||||
Options.setVisibilityMode(LangOptions::DefaultVisibility);
|
||||
else if (!strcmp(vkind, "protected"))
|
||||
Options.setVisibilityMode(LangOptions::ProtectedVisibility);
|
||||
else if (!strcmp(vkind, "hidden"))
|
||||
Options.setVisibilityMode(LangOptions::HiddenVisibility);
|
||||
else if (!strcmp(vkind, "internal"))
|
||||
Options.setVisibilityMode(LangOptions::InternalVisibility);
|
||||
else
|
||||
fprintf(stderr,
|
||||
"-fvisibility only valid for default|protected|hidden|internal\n");
|
||||
}
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
OverflowChecking("ftrapv",
|
||||
llvm::cl::desc("Trap on integer overflow"),
|
||||
|
@ -1770,6 +1792,7 @@ int main(int argc, char **argv) {
|
|||
LangKind LK = GetLanguage(InFile);
|
||||
InitializeLangOptions(LangInfo, LK);
|
||||
InitializeGCMode(LangInfo);
|
||||
InitializeSymbolVisibility(LangInfo);
|
||||
InitializeOverflowChecking(LangInfo);
|
||||
InitializeLanguageStandard(LangInfo, LK, Target.get());
|
||||
|
||||
|
|
Loading…
Reference in New Issue