[PATCH] D137107: Allow MS extension: support of constexpr with __declspec(dllimport).
Zahira Ammarguellat via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 20 06:51:10 PST 2022
zahiraam marked an inline comment as done.
zahiraam added inline comments.
================
Comment at: clang/lib/CodeGen/CodeGenModule.cpp:5009
+ if (isStaticInit(D, getLangOpts()) && NeedsGlobalCtor && NeedsGlobalDtor) {
+ EmitCXXCtorInit(D, GV, true, 201, llvm::StringLiteral("ctor"), false);
+ EmitCXXCtorInit(D, GV, false, 65535, llvm::StringLiteral("dtor"), true);
----------------
efriedma wrote:
> zahiraam wrote:
> > efriedma wrote:
> > > I think you want to use priority 201 whether or not there's a destructor.
> > Is that what you mean?
> I think it should look something more like this:
>
> ```
> if (isStaticInit(D, getLangOpts()) {
> if (NeedsGlobalCtor)
> EmitCXXCtorInit(D, GV, true, 201, llvm::StringLiteral("ctor"), false);
> if (NeedsGlobalDtor)
> EmitCXXCtorInit(D, GV, false, 65535, llvm::StringLiteral("dtor"), true);
> DelayedCXXInitPosition[D] = ~0U;
> } else {
> EmitCXXGlobalVarDeclInitFunc(D, GV, NeedsGlobalCtor);
> }
If you agree with the generated IR for this case, then I will start editing the LIT tests accordingly.
// CHECK: @"?b@@3UB@@A" = dso_local global %struct.B undef
// CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @dtor, ptr null }]
// CHECK: define internal void @dtor()
// CHECK: entry:
// CHECK: %0 = call i32 @atexit(ptr @"??__Fb@@YAXXZ")
// CHECK: ret void
// CHECk: define linkonce_odr dso_local x86_thiscallcc void @"??1B@@QAE at XZ"
// CHECK: entry:
// CHECK: %this.addr = alloca ptr, align 4
// CHECK: store ptr %this, ptr %this.addr, align 4
// CHECK: %this1 = load ptr, ptr %this.addr, align 4
// CHECK: ret void
// CHECK: define internal void @"??__Fb@@YAXXZ"() #0 {
// CHECK: entry:
// CHECK: call x86_thiscallcc void @"??1B@@QAE at XZ"(ptr @"?b@@3UB@@A")
// CHECK: ret void
struct B {
constexpr B() {}
~B() {};
};
constinit B b;
The ctor with priority 201 is generated only when tryEmitForInitializer returns a nullptr (that's the only time when NeedsGlobalCtor is set to true). Correct?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137107/new/
https://reviews.llvm.org/D137107
More information about the cfe-commits
mailing list