98 lines · cpp
1// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++14 \2// RUN: -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases \3// RUN: -disable-llvm-passes -o - %s -w -fms-compatibility-version=19.00 | \4// RUN: FileCheck %s5 6struct CtorWithClosure {7 __declspec(dllexport) CtorWithClosure(...) {}8// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorWithClosure@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat9// CHECK: %[[this_addr:.*]] = alloca ptr, align 410// CHECK: store ptr %this, ptr %[[this_addr]], align 411// CHECK: %[[this:.*]] = load ptr, ptr %[[this_addr]]12// CHECK: call noundef ptr (ptr, ...) @"??0CtorWithClosure@@QAA@ZZ"(ptr {{[^,]*}} %[[this]])13// CHECK: ret void14};15 16struct CtorWithClosureOutOfLine {17 __declspec(dllexport) CtorWithClosureOutOfLine(...);18};19CtorWithClosureOutOfLine::CtorWithClosureOutOfLine(...) {}20// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorWithClosureOutOfLine@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat21 22#define DELETE_IMPLICIT_MEMBERS(ClassName) \23 ClassName(ClassName &&) = delete; \24 ClassName(ClassName &) = delete; \25 ~ClassName() = delete; \26 ClassName &operator=(ClassName &) = delete27 28struct __declspec(dllexport) ClassWithClosure {29 DELETE_IMPLICIT_MEMBERS(ClassWithClosure);30 ClassWithClosure(...) {}31// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FClassWithClosure@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat32// CHECK: %[[this_addr:.*]] = alloca ptr, align 433// CHECK: store ptr %this, ptr %[[this_addr]], align 434// CHECK: %[[this:.*]] = load ptr, ptr %[[this_addr]]35// CHECK: call noundef ptr (ptr, ...) @"??0ClassWithClosure@@QAA@ZZ"(ptr {{[^,]*}} %[[this]])36// CHECK: ret void37};38 39template <typename T> struct TemplateWithClosure {40 TemplateWithClosure(int x = sizeof(T)) {}41};42extern template struct TemplateWithClosure<char>;43template struct __declspec(dllexport) TemplateWithClosure<char>;44extern template struct TemplateWithClosure<int>;45template struct __declspec(dllexport) TemplateWithClosure<int>;46 47// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_F?$TemplateWithClosure@D@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat48// CHECK: call {{.*}} @"??0?$TemplateWithClosure@D@@QAE@H@Z"({{.*}}, i32 noundef 1)49 50// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_F?$TemplateWithClosure@H@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat51// CHECK: call {{.*}} @"??0?$TemplateWithClosure@H@@QAE@H@Z"({{.*}}, i32 noundef 4)52 53template <typename T> struct __declspec(dllexport) ExportedTemplateWithClosure {54 ExportedTemplateWithClosure(int x = sizeof(T)) {}55};56template <> ExportedTemplateWithClosure<int>::ExportedTemplateWithClosure(int); // Don't try to emit the closure for a declaration.57template <> ExportedTemplateWithClosure<int>::ExportedTemplateWithClosure(int) {};58// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_F?$ExportedTemplateWithClosure@H@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat59// CHECK: call {{.*}} @"??0?$ExportedTemplateWithClosure@H@@QAE@H@Z"({{.*}}, i32 noundef 4)60 61struct __declspec(dllexport) NestedOuter {62 DELETE_IMPLICIT_MEMBERS(NestedOuter);63 NestedOuter(void *p = 0) {}64 struct __declspec(dllexport) NestedInner {65 DELETE_IMPLICIT_MEMBERS(NestedInner);66 NestedInner(void *p = 0) {}67 };68};69 70// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FNestedOuter@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat71// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FNestedInner@NestedOuter@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat72 73struct HasDtor {74 ~HasDtor();75 int o;76};77struct HasImplicitDtor1 { HasDtor o; };78struct HasImplicitDtor2 { HasDtor o; };79struct __declspec(dllexport) CtorClosureInline {80 CtorClosureInline(const HasImplicitDtor1 &v = {}) {}81};82struct __declspec(dllexport) CtorClosureOutOfLine {83 CtorClosureOutOfLine(const HasImplicitDtor2 &v = {});84};85CtorClosureOutOfLine::CtorClosureOutOfLine(const HasImplicitDtor2 &v) {}86 87// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorClosureInline@@QAEXXZ"88// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??1HasImplicitDtor1@@QAE@XZ"89// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorClosureOutOfLine@@QAEXXZ"90// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??1HasImplicitDtor2@@QAE@XZ"91 92struct SomeStruct {};93constexpr SomeStruct kConstexprStruct;94struct __declspec(dllexport) ConstexprDefaultArg {95 ConstexprDefaultArg(SomeStruct = kConstexprStruct) {}96};97// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FConstexprDefaultArg@@QAEXXZ"98