[llvm] [llvm][test][CGPluginTest] Avoid __attribute__((constructor)) for MSVC (PR #227310)
Fabrice de Gans via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 01:07:09 PDT 2026
================
@@ -424,12 +424,16 @@ RegisterTargetPassConfigCallback X{[](auto &TM, auto &PM, auto *TPC) {
}};
```
-Note that passes still have to be registered:
+Note that passes still have to be registered. This can be done using a
+static object whose constructor runs when the plugin is loaded:
```cpp
-__attribute__((constructor)) static void initCodeGenPlugin() {
- initializeExamplePass(*PassRegistry::getPassRegistry());
-}
+struct InitCodeGenPlugin {
+ InitCodeGenPlugin() {
+ initializeExamplePass(*PassRegistry::getPassRegistry());
+ }
+};
+static InitCodeGenPlugin InitCodeGenPluginInstance;
----------------
Steelskin wrote:
It is never guaranteed, yes. I was mostly wondering if `__attribute__((constructor))` had additional guarantees. If both tests and build pass, that's good enough for me, though, thank you!
https://github.com/llvm/llvm-project/pull/227310
More information about the llvm-commits
mailing list