[clang] 7ad6010 - Fix - [Clang] Add the ability to map DLL storage class to visibility

Ben Dunbobbin via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 3 11:14:15 PST 2020


Author: Ben Dunbobbin
Date: 2020-11-03T19:13:54Z
New Revision: 7ad6010f58eac498896e601857ff7eda84466064

URL: https://github.com/llvm/llvm-project/commit/7ad6010f58eac498896e601857ff7eda84466064
DIFF: https://github.com/llvm/llvm-project/commit/7ad6010f58eac498896e601857ff7eda84466064.diff

LOG: Fix - [Clang] Add the ability to map DLL storage class to visibility

415f7ee883 had a silly typo introduced when I inlined some
code into a loop from its own function.

Original commit message:

For PlayStation we offer source code compatibility with
Microsoft's dllimport/export annotations; however, our file
format is based on ELF.

To support this we translate from DLL storage class to ELF
visibility at the end of codegen in Clang.

Other toolchains have used similar strategies (e.g. see the
documentation for this ARM toolchain:

https://developer.arm.com/documentation/dui0530/i/migrating-from-rvct-v3-1-to-rvct-v4-0/changes-to-symbol-visibility-between-rvct-v3-1-and-rvct-v4-0)

This patch adds the ability to perform this translation. Options
are provided to support customizing the mapping behaviour.

Differential Revision: https://reviews.llvm.org/D89970

Added: 
    

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp
    clang/test/CodeGenCXX/visibility-dllstorageclass.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 1efc39bc8fb1..24c067539f83 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -418,7 +418,7 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO,
 
   for (llvm::GlobalValue &GV : M.global_values()) {
     if (GV.hasAppendingLinkage() || GV.hasLocalLinkage())
-      return;
+      continue;
 
     if (GV.isDeclarationForLinker()) {
       GV.setVisibility(GV.getDLLStorageClass() ==
@@ -724,7 +724,7 @@ void CodeGenModule::Release() {
 
   EmitBackendOptionsMetadata(getCodeGenOpts());
 
-  // Set visibility from DLL export class
+  // Set visibility from DLL storage class
   // We do this at the end of LLVM IR generation; after any operation
   // that might affect the DLL storage class or the visibility, and
   // before anything that might act on these.

diff  --git a/clang/test/CodeGenCXX/visibility-dllstorageclass.cpp b/clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
index f090ccb3b099..9003909f3ee0 100644
--- a/clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
+++ b/clang/test/CodeGenCXX/visibility-dllstorageclass.cpp
@@ -19,11 +19,17 @@
 // RUN:     -x c++  %s -S -emit-llvm -o - | \
 // RUN:   FileCheck %s --check-prefixes=EXPLICIT
 
+// Local
+static void l() {}
+void use_locals(){l();}
+// DEFAULT-DAG: define internal void @_ZL1lv()
+// EXPLICIT-DAG: define internal void @_ZL1lv()
+
 // Function
 void f() {}
 void __declspec(dllexport) exported_f() {}
 // DEFAULT-DAG: define hidden void @_Z1fv()
-// DEFAULT-DAG: define dso_local  void @_Z10exported_fv()
+// DEFAULT-DAG: define dso_local void @_Z10exported_fv()
 // EXPLICIT-DAG: define protected void @_Z1fv()
 // EXPLICIT-DAG: define hidden void @_Z10exported_fv()
 


        


More information about the cfe-commits mailing list