Skip to content

Commit 388b9f7

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd34a4137834e' from swift/release/5.3 into swift/master
2 parents 507e3e4 + d34a413 commit 388b9f7

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

clang/lib/CodeGen/CGVTables.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ void CodeGenFunction::EmitMustTailThunk(GlobalDecl GD,
438438
// Finish the function to maintain CodeGenFunction invariants.
439439
// FIXME: Don't emit unreachable code.
440440
EmitBlock(createBasicBlock());
441-
FinishFunction();
441+
442+
FinishThunk();
442443
}
443444

444445
void CodeGenFunction::generateThunk(llvm::Function *Fn,
@@ -565,7 +566,7 @@ llvm::Constant *CodeGenVTables::maybeEmitThunk(GlobalDecl GD,
565566
CGM.SetLLVMFunctionAttributesForDefinition(GD.getDecl(), ThunkFn);
566567

567568
// Thunks for variadic methods are special because in general variadic
568-
// arguments cannot be perferctly forwarded. In the general case, clang
569+
// arguments cannot be perfectly forwarded. In the general case, clang
569570
// implements such thunks by cloning the original function body. However, for
570571
// thunks with no return adjustment on targets that support musttail, we can
571572
// use musttail to perfectly forward the variadic arguments.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_cc1 -fexceptions -fcxx-exceptions %s -triple=i686-windows-msvc -emit-llvm -o - | FileCheck %s
2+
3+
// When generating thunks using musttail due to inalloca parameters, don't push
4+
// and pop terminate scopes. PR44987
5+
6+
struct NonTrivial {
7+
NonTrivial();
8+
NonTrivial(const NonTrivial &o);
9+
~NonTrivial();
10+
int x;
11+
};
12+
struct A {
13+
virtual void f(NonTrivial o) noexcept;
14+
};
15+
struct B {
16+
virtual void f(NonTrivial o) noexcept;
17+
};
18+
class C : A, B {
19+
virtual void f(NonTrivial o) noexcept;
20+
};
21+
C c;
22+
23+
// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"?f@C@@G3AEXUNonTrivial@@@Z"(%class.C* %this, <{ %struct.NonTrivial }>* inalloca %0)
24+
// CHECK-NOT: invoke
25+
// CHECK: musttail call x86_thiscallcc void @"?f@C@@EAEXUNonTrivial@@@Z"(%class.C* %{{.*}}, <{ %struct.NonTrivial }>* inalloca %0)
26+
// CHECK-NEXT ret void
27+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %clang_cc1 -fexceptions -fcxx-exceptions %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes | FileCheck %s
2+
3+
// When generating the thunk for secondary, do not push terminate scopes for
4+
// either the varargs or non-varargs case. Related to PR44987.
5+
6+
struct A {
7+
virtual void primary_key();
8+
};
9+
struct B {
10+
virtual void secondary();
11+
virtual void secondary_vararg(int, ...);
12+
};
13+
class C : A, B {
14+
virtual void primary_key();
15+
void secondary() noexcept;
16+
void secondary_vararg(int, ...) noexcept;
17+
};
18+
void C::primary_key() {}
19+
20+
// CHECK-LABEL: define available_externally void @_ZThn8_N1C9secondaryEv(%class.C* %this)
21+
// CHECK-NOT: invoke
22+
// CHECK: tail call void @_ZN1C9secondaryEv(%class.C* %{{.*}})
23+
// CHECK-NOT: invoke
24+
// CHECK: ret void
25+
26+
// CHECK-LABEL: define available_externally void @_ZThn8_N1C16secondary_varargEiz(%class.C* %this, i32 %0, ...)
27+
// CHECK-NOT: invoke
28+
// CHECK: musttail call void (%class.C*, i32, ...) @_ZN1C16secondary_varargEiz(%class.C* %{{.*}}, i32 %{{.*}}, ...) #2
29+
// CHECK-NEXT: ret void

0 commit comments

Comments
 (0)