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

Valentin Churavy via flang-commits flang-commits at lists.llvm.org
Sat Oct 3 12:36:04 PDT 2026


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

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)

>From ee2dae48e22485be4184a63ef9297055130f6bd8 Mon Sep 17 00:00:00 2001
From: Valentin Churavy <v.churavy at gmail.com>
Date: Fri, 2 Oct 2026 21:48:17 +0200
Subject: [PATCH] [flang] Load every -load plugin, not only the last

`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)
---
 flang/lib/Frontend/CompilerInvocation.cpp    |  6 +++---
 flang/test/Examples/load-several-plugins.f90 | 13 +++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 flang/test/Examples/load-several-plugins.f90

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



More information about the flang-commits mailing list