[cfe-commits] r68369 - in /cfe/trunk: include/clang/Basic/LangOptions.h include/clang/Driver/Options.def lib/CodeGen/CodeGenModule.cpp test/CodeGen/visibility-option.c tools/clang-cc/clang-cc.cpp
Fariborz Jahanian
fjahanian at apple.com
Thu Apr 2 20:29:01 PDT 2009
Author: fjahanian
Date: Thu Apr 2 22:28:57 2009
New Revision: 68369
URL: http://llvm.org/viewvc/llvm-project?rev=68369&view=rev
Log:
Implement -fvisibility.
Added:
cfe/trunk/test/CodeGen/visibility-option.c
Modified:
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Driver/Options.def
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=68369&r1=68368&r2=68369&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Thu Apr 2 22:28:57 2009
@@ -64,14 +64,19 @@
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 @@
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;
Modified: cfe/trunk/include/clang/Driver/Options.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.def?rev=68369&r1=68368&r2=68369&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.def (original)
+++ cfe/trunk/include/clang/Driver/Options.def Thu Apr 2 22:28:57 2009
@@ -451,6 +451,7 @@
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)
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=68369&r1=68368&r2=68369&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Apr 2 22:28:57 2009
@@ -113,6 +113,25 @@
}
}
+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 @@
// -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 @@
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)
Added: cfe/trunk/test/CodeGen/visibility-option.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/visibility-option.c?rev=68369&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/visibility-option.c (added)
+++ cfe/trunk/test/CodeGen/visibility-option.c Thu Apr 2 22:28:57 2009
@@ -0,0 +1,6 @@
+// RUN: clang-cc -fvisibility=hidden -emit-llvm -o - %s | grep -e "hidden" | count 2
+
+int Global = 10;
+
+void Func() {}
+
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=68369&r1=68368&r2=68369&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Thu Apr 2 22:28:57 2009
@@ -764,6 +764,28 @@
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 @@
LangKind LK = GetLanguage(InFile);
InitializeLangOptions(LangInfo, LK);
InitializeGCMode(LangInfo);
+ InitializeSymbolVisibility(LangInfo);
InitializeOverflowChecking(LangInfo);
InitializeLanguageStandard(LangInfo, LK, Target.get());
More information about the cfe-commits
mailing list