[clang] [clang][ms] Add support for optional function argument in #pragma init_seg (PR #203769)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 7 04:20:05 PDT 2026


================
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s
+
+int __cdecl myexit(void (__cdecl *pf)(void));
+
+struct S {
+  S();
+  ~S();
+};
+
+#pragma init_seg(".myseg", myexit)
+
+S s;
+
+// The initializer pointer is still placed in the custom section.
+// CHECK: @__cxx_init_fn_ptr = private constant ptr @"??__Es@@YAXXZ", section ".myseg"
+
+// The destructor registration calls myexit instead of atexit.
+// CHECK-LABEL: define {{.*}} @"??__Es@@YAXXZ"
+// CHECK: call i32 @"?myexit@@{{[^"]+}}"(
+// CHECK-NOT: call {{.*}} @atexit(
----------------
timofey256 wrote:

I tried to address comments the way Artem proposed - separate positive and negative checks (+ added trailing anchor point)

https://github.com/llvm/llvm-project/pull/203769


More information about the cfe-commits mailing list