[llvm] [profcheck] Don't verify generated global ctors/dtors (PR #170597)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 4 12:52:02 PST 2025


================
@@ -189,11 +195,43 @@ PreservedAnalyses ProfileInjectorPass::run(Function &F,
   return PreservedAnalyses::none();
 }
 
+PreservedAnalyses ProfileVerifierPass::run(Module &M,
+                                           ModuleAnalysisManager &MAM) {
+  auto PopulateIgnoreList = [&](StringRef GVName) {
+    if (const auto *CT = M.getGlobalVariable(GVName))
+      if (const auto *CA =
+              dyn_cast_if_present<ConstantArray>(CT->getInitializer()))
+        for (const auto &Elt : CA->operands())
+          if (const auto *CS = dyn_cast<ConstantStruct>(Elt))
+            if (CS->getNumOperands() >= 2 && CS->getOperand(1))
+              if (const auto *F = dyn_cast<Function>(
+                      CS->getOperand(1)->stripPointerCasts()))
+                IgnoreList.insert(F);
+  };
+  PopulateIgnoreList("llvm.global_ctors");
+  PopulateIgnoreList("llvm.global_dtors");
+
+  // expose the function-level run as public through a wrapper, so we can use
+  // pass manager mechanisms dealing with declarations and with composing the
+  // returned PreservedAnalyses values.
+  struct Wrapper : PassInfoMixin<Wrapper> {
+    ProfileVerifierPass &PVP;
+    PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM) {
+      return PVP.run(F, FAM);
+    }
+    explicit Wrapper(ProfileVerifierPass &PVP) : PVP(PVP) {}
+  };
+
+  return createModuleToFunctionPassAdaptor(Wrapper(*this)).run(M, MAM);
+}
+
 PreservedAnalyses ProfileVerifierPass::run(Function &F,
----------------
boomanaiden154 wrote:

It would be good to make this private.

https://github.com/llvm/llvm-project/blob/097e0e116aa42f114d6e7dd166069f90d85cce97/llvm/tools/opt/NewPMDriver.cpp#L505 needs updating and apparently was not caught at compile time.

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


More information about the llvm-commits mailing list