[flang-commits] [flang] [flang] Load every -load plugin, not only the last (PR #228760)

via flang-commits flang-commits at lists.llvm.org
Sat Oct 3 12:37:09 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-driver

Author: Valentin Churavy (vchuravy)

<details>
<summary>Changes</summary>

Not sure if this is super helpful, but currently we only allow for one flang plugin to be loaded.

Found while working on #<!-- -->228757

:robot:

`flang -fc1 -load a.so -load b.so` loaded only b.so: the option was read with getLastArg. Load each, in order, as clang does. Two plugins are common enough: a plugin that defines directives, and an LLVM pass plugin that is also loaded into the frontend so that its -mllvm options parse.

Assisted-by: Claude Code (Opus 5.5)

---
Full diff: https://github.com/llvm/llvm-project/pull/228760.diff


2 Files Affected:

- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+3-3) 
- (added) flang/test/Examples/load-several-plugins.f90 (+13) 


``````````diff
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 13794f5720e74..e73e28fc19098 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -785,10 +785,10 @@ static bool parseFrontendArgs(FrontendOptions &opts, llvm::opt::ArgList &args,
     }
   }
 
-  // Parsing -load <dsopath> option and storing shared object path
-  if (llvm::opt::Arg *a = args.getLastArg(clang::options::OPT_load)) {
+  // Parsing -load <dsopath> options and storing the shared object paths, in
+  // order: each is loaded, as in clang.
+  for (const llvm::opt::Arg *a : args.filtered(clang::options::OPT_load))
     opts.plugins.push_back(a->getValue());
-  }
 
   // Parsing -plugin <name> option and storing plugin name and setting action
   if (const llvm::opt::Arg *a = args.getLastArg(clang::options::OPT_plugin)) {
diff --git a/flang/test/Examples/load-several-plugins.f90 b/flang/test/Examples/load-several-plugins.f90
new file mode 100644
index 0000000000000..18e4c5770c67d
--- /dev/null
+++ b/flang/test/Examples/load-several-plugins.f90
@@ -0,0 +1,13 @@
+! Every -load plugin is loaded, not only the last: here the plugin that
+! -plugin runs is the first of two.
+
+! REQUIRES: plugins, examples
+! XFAIL: system-aix
+
+! RUN: %flang_fc1 -load %llvmshlibdir/flangPrintFunctionNames%pluginext -load %llvmshlibdir/flangOmpReport%pluginext -plugin print-fns %s 2>&1 | FileCheck %s
+
+! CHECK: Subroutine: s
+! CHECK: ==== Subroutines: 1 ====
+
+subroutine s
+end subroutine

``````````

</details>


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


More information about the flang-commits mailing list