r242012 - Set the linkage before setting the visibility.

Rafael Espindola rafael.espindola at gmail.com
Sun Jul 12 23:07:59 PDT 2015


Author: rafael
Date: Mon Jul 13 01:07:58 2015
New Revision: 242012

URL: http://llvm.org/viewvc/llvm-project?rev=242012&view=rev
Log:
Set the linkage before setting the visibility.

Otherwise the visibility setting code would not know that a given
function was available_externally.

Fixes PR24097.

Added:
    cfe/trunk/test/CodeGenCXX/pr24097.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGVTables.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=242012&r1=242011&r2=242012&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Mon Jul 13 01:07:58 2015
@@ -364,7 +364,7 @@ void CodeGenFunction::EmitMustTailThunk(
   FinishFunction();
 }
 
-void CodeGenFunction::GenerateThunk(llvm::Function *Fn,
+void CodeGenFunction::generateThunk(llvm::Function *Fn,
                                     const CGFunctionInfo &FnInfo,
                                     GlobalDecl GD, const ThunkInfo &Thunk) {
   StartThunk(Fn, GD, FnInfo);
@@ -376,13 +376,6 @@ void CodeGenFunction::GenerateThunk(llvm
 
   // Make the call and return the result.
   EmitCallAndReturnForThunk(Callee, &Thunk);
-
-  // Set the right linkage.
-  CGM.setFunctionLinkage(GD, Fn);
-
-  // Set the right visibility.
-  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
-  setThunkVisibility(CGM, MD, Thunk, Fn);
 }
 
 void CodeGenVTables::emitThunk(GlobalDecl GD, const ThunkInfo &Thunk,
@@ -455,11 +448,17 @@ void CodeGenVTables::emitThunk(GlobalDec
         CodeGenFunction(CGM).GenerateVarArgsThunk(ThunkFn, FnInfo, GD, Thunk);
   } else {
     // Normal thunk body generation.
-    CodeGenFunction(CGM).GenerateThunk(ThunkFn, FnInfo, GD, Thunk);
+    CodeGenFunction(CGM).generateThunk(ThunkFn, FnInfo, GD, Thunk);
   }
 
+  CGM.setFunctionLinkage(GD, ThunkFn);
   CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable, GD,
                                   !Thunk.Return.isEmpty());
+
+  // Set the right visibility.
+  const CXXMethodDecl *MD = cast<CXXMethodDecl>(GD.getDecl());
+  setThunkVisibility(CGM, MD, Thunk, ThunkFn);
+
   if (CGM.supportsCOMDAT() && ThunkFn->isWeakForLinker())
     ThunkFn->setComdat(CGM.getModule().getOrInsertComdat(ThunkFn->getName()));
 }

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=242012&r1=242011&r2=242012&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Jul 13 01:07:58 2015
@@ -1294,8 +1294,8 @@ public:
   void EmitMustTailThunk(const CXXMethodDecl *MD, llvm::Value *AdjustedThisPtr,
                          llvm::Value *Callee);
 
-  /// GenerateThunk - Generate a thunk for the given method.
-  void GenerateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
+  /// Generate a thunk for the given method.
+  void generateThunk(llvm::Function *Fn, const CGFunctionInfo &FnInfo,
                      GlobalDecl GD, const ThunkInfo &Thunk);
 
   llvm::Function *GenerateVarArgsThunk(llvm::Function *Fn,

Added: cfe/trunk/test/CodeGenCXX/pr24097.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/pr24097.cpp?rev=242012&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/pr24097.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/pr24097.cpp Mon Jul 13 01:07:58 2015
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -triple=x86_64-pc-linux -fvisibility hidden -emit-llvm -O1 -disable-llvm-optzns -o - | FileCheck %s
+
+struct Filter {
+  virtual void Foo();
+};
+struct Sender {
+  virtual bool Send();
+};
+struct SyncMessageFilter : public Filter, public Sender {
+  bool Send();
+};
+struct TestSyncMessageFilter : public SyncMessageFilter {
+};
+void bar() {
+  TestSyncMessageFilter f;
+  f.Send();
+}
+
+// Test that it is not hidden
+// CHECK: define available_externally zeroext i1 @_ZThn8_N17SyncMessageFilter4SendEv





More information about the cfe-commits mailing list