[llvm] [llvm][test][CGPluginTest] Avoid __attribute__((constructor)) for MSVC (PR #227310)
Fabrice de Gans via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 29 10:47:58 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:
I don't know how the resulting initializers differ - or if they even do. It _looks_ fine to me but I don't know if this is going to result in the initialization order differing.
https://github.com/llvm/llvm-project/pull/227310
More information about the llvm-commits
mailing list