r196658 - CodeGen: Don't emit linkage on thunks that aren't emitted because they're vararg.

Reid Kleckner rnk at google.com
Mon Dec 9 20:06:08 PST 2013


Emitting vtable thunks for vararg thunks make perfect sense.  LLVM just
can't represent them yet.  ;)

In seriousness, we're going to need a way to thunks like these for the MSVC
ABI.  Implementing general pointers to virtual member functions will
require it, because the arguments cannot be copied and we may not have the
body of the function to clone, like we do for vararg virtual methods in
Itanium.


On Sat, Dec 7, 2013 at 8:12 AM, Benjamin Kramer <benny.kra at googlemail.com>wrote:

> Author: d0k
> Date: Sat Dec  7 10:12:52 2013
> New Revision: 196658
>
> URL: http://llvm.org/viewvc/llvm-project?rev=196658&view=rev
> Log:
> CodeGen: Don't emit linkage on thunks that aren't emitted because they're
> vararg.
>
> This can happen when we're trying to emit a thunk with available_externally
> linkage with optimization enabled but bail because it doesn't make sense
> for vararg functions.
>
> PR18098.
>
> Modified:
>     cfe/trunk/lib/CodeGen/CGVTables.cpp
>     cfe/trunk/test/CodeGenCXX/thunks.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=196658&r1=196657&r2=196658&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGVTables.cpp Sat Dec  7 10:12:52 2013
> @@ -422,14 +422,15 @@ void CodeGenVTables::emitThunk(GlobalDec
>      // expensive/sucky at the moment, so don't generate the thunk unless
>      // we have to.
>      // FIXME: Do something better here; GenerateVarArgsThunk is extremely
> ugly.
> -    if (!UseAvailableExternallyLinkage)
> +    if (!UseAvailableExternallyLinkage) {
>        CodeGenFunction(CGM).GenerateVarArgsThunk(ThunkFn, FnInfo, GD,
> Thunk);
> +      CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable);
> +    }
>    } else {
>      // Normal thunk body generation.
>      CodeGenFunction(CGM).GenerateThunk(ThunkFn, FnInfo, GD, Thunk);
> +    CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable);
>    }
> -
> -  CGM.getCXXABI().setThunkLinkage(ThunkFn, ForVTable);
>  }
>
>  void CodeGenVTables::maybeEmitThunkForVTable(GlobalDecl GD,
>
> Modified: cfe/trunk/test/CodeGenCXX/thunks.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/thunks.cpp?rev=196658&r1=196657&r2=196658&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/thunks.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/thunks.cpp Sat Dec  7 10:12:52 2013
> @@ -1,4 +1,5 @@
>  // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables
> -emit-llvm -o - | FileCheck %s
> +// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables
> -emit-llvm -o - -O1 -disable-llvm-optzns | FileCheck %s
>  // RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables
> -fhidden-weak-vtables -emit-llvm -o - | FileCheck
> -check-prefix=CHECK-HIDDEN %s
>
>  namespace Test1 {
> @@ -342,6 +343,27 @@ namespace Test14 {
>    // CHECK: define void @_ZThn8_N6Test141C1fEv({{.*}}) unnamed_addr
> [[NUW:#[0-9]+]]
>  }
>
> +// Varargs non-covariant thunk test.
> +// PR18098
> +namespace Test15 {
> +  struct A {
> +    virtual ~A();
> +  };
> +  struct B {
> +    virtual void f(int x, ...);
> +  };
> +  struct C : A, B {
> +    virtual void c();
> +    virtual void f(int x, ...);
> +  };
> +  void C::c() {}
> +
> +  // C::c
> +  // CHECK: declare void @_ZN6Test151C1fEiz
> +  // non-virtual thunk to C::f
> +  // CHECK: declare void @_ZThn8_N6Test151C1fEiz
> +}
> +
>  /**** The following has to go at the end of the file ****/
>
>  // This is from Test5:
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131209/46645d8c/attachment.html>


More information about the cfe-commits mailing list