From 22df7b17f1b086f4347256406703d259753a0cbf Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sun, 6 Feb 2011 20:09:44 +0000 Subject: [PATCH] Fix self-host; if a thunk already exists and has available_externally linkage, we should change its linkage instead of asserting. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124986 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGVTables.cpp | 9 +++++++-- .../CodeGenCXX/thunks-available-externally.cpp | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 3dd7a15fe3..d74226ec89 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -2723,8 +2723,13 @@ void CodeGenVTables::EmitThunk(GlobalDecl GD, const ThunkInfo &Thunk, return; } - // We should never be able to get a function with a definition here. - assert(false && "Shouldn't have an already existing definition"); + // If a function has a body, it should have available_externally linkage. + assert(ThunkFn->hasAvailableExternallyLinkage() && + "Function should have available_externally linkage!"); + + // Change the linkage. + CGM.setFunctionLinkage(cast(GD.getDecl()), ThunkFn); + return; } // Actually generate the thunk body. diff --git a/test/CodeGenCXX/thunks-available-externally.cpp b/test/CodeGenCXX/thunks-available-externally.cpp index 697a000187..dfdb786b18 100644 --- a/test/CodeGenCXX/thunks-available-externally.cpp +++ b/test/CodeGenCXX/thunks-available-externally.cpp @@ -68,3 +68,21 @@ void f() { } } + +// Test that we don't assert. +namespace Test3 { + +struct A { + virtual ~A(); + + int a; +}; + +struct B : A { }; +struct C : virtual B { }; + +void f() { + C c; +} + +} -- 2.40.0