// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 -mconstructor-aliases -fexceptions -fcxx-exceptions -fno-rtti | FileCheck -check-prefix WIN32 -check-prefix WIN32-O0 %s
// RUN: %clang_cc1 -no-opaque-pointers -std=c++11 -emit-llvm -O3 -disable-llvm-passes %s -o - -triple=i386-pc-win32 -mconstructor-aliases -fexceptions -fcxx-exceptions -fno-rtti | FileCheck -check-prefix WIN32 -check-prefix WIN32-O3 -check-prefix WIN32-LIFETIME %s
;
A ;
int ;
void
// With exceptions, we need to clean up at least one of these temporaries.
// WIN32-LABEL: define dso_local void @"?HasEHCleanup@@YAXXZ"() {{.*}} {
// WIN32: %[[base:.*]] = call i8* @llvm.stacksave()
// If this call throws, we have to restore the stack.
// WIN32: call void @"?getA@@YA?AUA@@XZ"(%struct.A* sret(%struct.A) align 4 %{{.*}})
// If this call throws, we have to cleanup the first temporary.
// WIN32: invoke void @"?getA@@YA?AUA@@XZ"(%struct.A* sret(%struct.A) align 4 %{{.*}})
// If this call throws, we have to cleanup the stacksave.
// WIN32: call noundef i32 @"?TakesTwo@@YAHUA@@0@Z"
// WIN32: call void @llvm.stackrestore
// WIN32: ret void
//
// There should be one dtor call for unwinding from the second getA.
// WIN32: cleanuppad
// WIN32: call x86_thiscallcc void @"??1A@@QAE@XZ"({{.*}})
// WIN32-NOT: @"??1A@@QAE@XZ"
// WIN32: }
// This test verifies the fix for a crash that occurred after
// fa87fa97fb79.
void
// With exceptions, we need to clean up at least one of these temporaries.
// WIN32-LABEL: define dso_local void @"?HasEHCleanupNoexcept@@YAXXZ"() {{.*}} {
// WIN32: %[[base:.*]] = call i8* @llvm.stacksave()
// WIN32: invoke void @"?getA@@YA?AUA@@XZ"(%struct.A* sret(%struct.A) align 4 %{{.*}})
// WIN32: invoke void @"?getA@@YA?AUA@@XZ"(%struct.A* sret(%struct.A) align 4 %{{.*}})
// WIN32: invoke noundef i32 @"?TakesTwo@@YAHUA@@0@Z"
// WIN32: call void @llvm.stackrestore
// WIN32: ret void
//
// Since all the calls terminate, there should be no dtors on the unwind
// WIN32: cleanuppad
// WIN32-NOT: @"??1A@@QAE@XZ"
// WIN32: }
void ;
int
// WIN32-LABEL: define dso_local noundef i32 @"?HasDeactivatedCleanups@@YAHXZ"() {{.*}} {
// WIN32: %[[isactive:.*]] = alloca i1
// WIN32: call i8* @llvm.stacksave()
// WIN32: %[[argmem:.*]] = alloca inalloca [[argmem_ty:<{ %struct.A, %struct.A }>]]
// WIN32: %[[arg1:.*]] = getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 1
// WIN32: call x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32: invoke void @"?TakeRef@@YAXABUA@@@Z"
//
// WIN32: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"(%struct.A* {{[^,]*}} %[[arg1]])
// WIN32: store i1 true, i1* %[[isactive]]
//
// WIN32: %[[arg0:.*]] = getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 0
// WIN32: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32: invoke void @"?TakeRef@@YAXABUA@@@Z"
// WIN32: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32: store i1 false, i1* %[[isactive]]
//
// WIN32: invoke noundef i32 @"?TakesTwo@@YAHUA@@0@Z"([[argmem_ty]]* inalloca([[argmem_ty]]) %[[argmem]])
// Destroy the two const ref temporaries.
// WIN32: call x86_thiscallcc void @"??1A@@QAE@XZ"({{.*}})
// WIN32: call x86_thiscallcc void @"??1A@@QAE@XZ"({{.*}})
// WIN32: ret i32
//
// Conditionally destroy arg1.
// WIN32: %[[cond:.*]] = load i1, i1* %[[isactive]]
// WIN32: br i1 %[[cond]]
// WIN32: call x86_thiscallcc void @"??1A@@QAE@XZ"(%struct.A* {{[^,]*}} %[[arg1]])
// WIN32: }
// Test putting the cleanups inside a conditional.
int ;
int
// WIN32-LABEL: define dso_local noundef i32 @"?HasConditionalCleanup@@YAH_N@Z"(i1 noundef zeroext %{{.*}}) {{.*}} {
// WIN32: store i1 false
// WIN32: br i1
// WIN32: call i8* @llvm.stacksave()
// WIN32: call x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"(%struct.A* {{[^,]*}} %{{.*}})
// WIN32: store i1 true
// WIN32: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"(%struct.A* {{[^,]*}} %{{.*}})
// WIN32: call noundef i32 @"?TakesTwo@@YAHUA@@0@Z"
//
// WIN32: call void @llvm.stackrestore
//
// WIN32: call noundef i32 @"?CouldThrow@@YAHXZ"()
//
// Only one dtor in the invoke for arg1
// WIN32: call x86_thiscallcc void @"??1A@@QAE@XZ"({{.*}})
// WIN32-NOT: invoke x86_thiscallcc void @"??1A@@QAE@XZ"
// WIN32: }
// Now test both.
int
// WIN32-O0-LABEL: define dso_local noundef i32 @"?HasConditionalDeactivatedCleanups@@YAH_N@Z"{{.*}} {
// WIN32-O0: alloca i1
// WIN32-O0: %[[arg1_cond:.*]] = alloca i1
// Start all four cleanups as deactivated.
// WIN32-O0: store i1 false
// WIN32-O0: store i1 false
// WIN32-O0: store i1 false
// WIN32-O0: store i1 false
// WIN32-O0: br i1
// True condition.
// WIN32-O0: call x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32-O0: store i1 true
// WIN32-O0: invoke void @"?TakeRef@@YAXABUA@@@Z"
// WIN32-O0: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32-O0: store i1 true, i1* %[[arg1_cond]]
// WIN32-O0: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32-O0: store i1 true
// WIN32-O0: invoke void @"?TakeRef@@YAXABUA@@@Z"
// WIN32-O0: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32-O0: store i1 true
// WIN32-O0: store i1 false, i1* %[[arg1_cond]]
// WIN32-O0: invoke noundef i32 @"?TakesTwo@@YAHUA@@0@Z"
// False condition.
// WIN32-O0: invoke noundef i32 @"?CouldThrow@@YAHXZ"()
// Two normal cleanups for TakeRef args.
// WIN32-O0: call x86_thiscallcc void @"??1A@@QAE@XZ"({{.*}})
// WIN32-O0-NOT: invoke x86_thiscallcc void @"??1A@@QAE@XZ"
// WIN32-O0: ret i32
//
// Somewhere in the landing pad soup, we conditionally destroy arg1.
// WIN32-O0: %[[isactive:.*]] = load i1, i1* %[[arg1_cond]]
// WIN32-O0: br i1 %[[isactive]]
// WIN32-O0: call x86_thiscallcc void @"??1A@@QAE@XZ"({{.*}})
// WIN32-O0: }
// WIN32-O3-LABEL: define dso_local noundef i32 @"?HasConditionalDeactivatedCleanups@@YAH_N@Z"{{.*}} {
// WIN32-O3: alloca i1
// WIN32-O3: alloca i1
// WIN32-O3: %[[arg1_cond:.*]] = alloca i1
// Start all four cleanups as deactivated.
// WIN32-O3: store i1 false
// WIN32-O3: store i1 false
// WIN32-O3: store i1 false
// WIN32-O3: store i1 false
// WIN32-O3: store i1 false
// WIN32-O3: store i1 false
// WIN32-O3: br i1
// True condition.
// WIN32-O3: call x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32-O3: store i1 true
// WIN32-O3: invoke void @"?TakeRef@@YAXABUA@@@Z"
// WIN32-O3: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32-O3: store i1 true, i1* %[[arg1_cond]]
// WIN32-O3: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32-O3: store i1 true
// WIN32-O3: invoke void @"?TakeRef@@YAXABUA@@@Z"
// WIN32-O3: invoke x86_thiscallcc noundef %struct.A* @"??0A@@QAE@XZ"
// WIN32-O3: store i1 true
// WIN32-O3: store i1 false, i1* %[[arg1_cond]]
// WIN32-O3: invoke noundef i32 @"?TakesTwo@@YAHUA@@0@Z"
// False condition.
// WIN32-O3: invoke noundef i32 @"?CouldThrow@@YAHXZ"()
// Two normal cleanups for TakeRef args.
// WIN32-O3: call x86_thiscallcc void @"??1A@@QAE@XZ"({{.*}})
// WIN32-O3-NOT: invoke x86_thiscallcc void @"??1A@@QAE@XZ"
// WIN32-O3: ret i32
//
// Somewhere in the landing pad soup, we conditionally destroy arg1.
// WIN32-O3: %[[isactive:.*]] = load i1, i1* %[[arg1_cond]]
// WIN32-O3: br i1 %[[isactive]]
// WIN32-O3: call x86_thiscallcc void @"??1A@@QAE@XZ"({{.*}})
// WIN32-O3: }
// WIN32-LABEL: define dso_local void @"?f@noexcept_false_dtor@@YAXXZ"()
// WIN32: invoke noundef i32 @"?CouldThrow@@YAHXZ"()
// WIN32: call x86_thiscallcc void @"??1D@noexcept_false_dtor@@QAE@XZ"(%"struct.noexcept_false_dtor::D"* {{[^,]*}} %{{.*}})
// WIN32: cleanuppad
// WIN32: call x86_thiscallcc void @"??1D@noexcept_false_dtor@@QAE@XZ"(%"struct.noexcept_false_dtor::D"* {{[^,]*}} %{{.*}})
// WIN32: cleanupret
;
;
;