File: dllexport-ctor-closure.cpp

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (97 lines) | stat: -rw-r--r-- 4,746 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// RUN: %clang_cc1 -triple i686-windows-msvc -emit-llvm -std=c++14 \
// RUN:    -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases \
// RUN:    -disable-llvm-passes -o - %s -w -fms-compatibility-version=19.00 | \
// RUN:    FileCheck %s

struct CtorWithClosure {
  __declspec(dllexport) CtorWithClosure(...) {}
// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorWithClosure@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
// CHECK:   %[[this_addr:.*]] = alloca ptr, align 4
// CHECK:   store ptr %this, ptr %[[this_addr]], align 4
// CHECK:   %[[this:.*]] = load ptr, ptr %[[this_addr]]
// CHECK:   call noundef ptr (ptr, ...) @"??0CtorWithClosure@@QAA@ZZ"(ptr {{[^,]*}} %[[this]])
// CHECK:   ret void
};

struct CtorWithClosureOutOfLine {
  __declspec(dllexport) CtorWithClosureOutOfLine(...);
};
CtorWithClosureOutOfLine::CtorWithClosureOutOfLine(...) {}
// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorWithClosureOutOfLine@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat

#define DELETE_IMPLICIT_MEMBERS(ClassName) \
    ClassName(ClassName &&) = delete; \
    ClassName(ClassName &) = delete; \
    ~ClassName() = delete; \
    ClassName &operator=(ClassName &) = delete

struct __declspec(dllexport) ClassWithClosure {
  DELETE_IMPLICIT_MEMBERS(ClassWithClosure);
  ClassWithClosure(...) {}
// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FClassWithClosure@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
// CHECK:   %[[this_addr:.*]] = alloca ptr, align 4
// CHECK:   store ptr %this, ptr %[[this_addr]], align 4
// CHECK:   %[[this:.*]] = load ptr, ptr %[[this_addr]]
// CHECK:   call noundef ptr (ptr, ...) @"??0ClassWithClosure@@QAA@ZZ"(ptr {{[^,]*}} %[[this]])
// CHECK:   ret void
};

template <typename T> struct TemplateWithClosure {
  TemplateWithClosure(int x = sizeof(T)) {}
};
extern template struct TemplateWithClosure<char>;
template struct __declspec(dllexport) TemplateWithClosure<char>;
extern template struct TemplateWithClosure<int>;
template struct __declspec(dllexport) TemplateWithClosure<int>;

// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_F?$TemplateWithClosure@D@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
// CHECK:   call {{.*}} @"??0?$TemplateWithClosure@D@@QAE@H@Z"({{.*}}, i32 noundef 1)

// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_F?$TemplateWithClosure@H@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
// CHECK:   call {{.*}} @"??0?$TemplateWithClosure@H@@QAE@H@Z"({{.*}}, i32 noundef 4)

template <typename T> struct __declspec(dllexport) ExportedTemplateWithClosure {
  ExportedTemplateWithClosure(int x = sizeof(T)) {}
};
template <> ExportedTemplateWithClosure<int>::ExportedTemplateWithClosure(int); // Don't try to emit the closure for a declaration.
template <> ExportedTemplateWithClosure<int>::ExportedTemplateWithClosure(int) {};
// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_F?$ExportedTemplateWithClosure@H@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
// CHECK:   call {{.*}} @"??0?$ExportedTemplateWithClosure@H@@QAE@H@Z"({{.*}}, i32 noundef 4)

struct __declspec(dllexport) NestedOuter {
  DELETE_IMPLICIT_MEMBERS(NestedOuter);
  NestedOuter(void *p = 0) {}
  struct __declspec(dllexport) NestedInner {
    DELETE_IMPLICIT_MEMBERS(NestedInner);
    NestedInner(void *p = 0) {}
  };
};

// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FNestedOuter@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FNestedInner@NestedOuter@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat

struct HasDtor {
  ~HasDtor();
  int o;
};
struct HasImplicitDtor1 { HasDtor o; };
struct HasImplicitDtor2 { HasDtor o; };
struct __declspec(dllexport) CtorClosureInline {
  CtorClosureInline(const HasImplicitDtor1 &v = {}) {}
};
struct __declspec(dllexport) CtorClosureOutOfLine {
  CtorClosureOutOfLine(const HasImplicitDtor2 &v = {});
};
CtorClosureOutOfLine::CtorClosureOutOfLine(const HasImplicitDtor2 &v) {}

// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorClosureInline@@QAEXXZ"
// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??1HasImplicitDtor1@@QAE@XZ"
// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FCtorClosureOutOfLine@@QAEXXZ"
// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??1HasImplicitDtor2@@QAE@XZ"

struct SomeStruct {};
constexpr SomeStruct kConstexprStruct;
struct __declspec(dllexport) ConstexprDefaultArg {
  ConstexprDefaultArg(SomeStruct = kConstexprStruct) {}
};
// CHECK-LABEL: define weak_odr dso_local dllexport x86_thiscallcc void @"??_FConstexprDefaultArg@@QAEXXZ"