[flang-commits] [flang] [Flang] Store only options in FLANG_COMPILER_OPTIONS_STRING (PR #201278)

Tarun Prabhu via flang-commits flang-commits at lists.llvm.org
Wed Jun 3 03:45:44 PDT 2026


================
@@ -174,22 +175,28 @@ int main(int argc, const char **argv) {
   if (rejectAssemblyInputs(c->getInputArgs(), diags))
     return 1;
 
-  // Set the environment variable, FLANG_COMPILER_OPTIONS_STRING, to contain all
-  // the compiler options. This is intended for the frontend driver,
-  // flang -fc1, to enable the implementation of the COMPILER_OPTIONS
-  // intrinsic. To this end, the frontend driver requires the list of the
-  // original compiler options, which is not available through other means.
+  // Set the environment variable, FLANG_COMPILER_OPTIONS_STRING, to contain
+  // the compiler options (excluding input file names and the program name).
+  // This is intended for the frontend driver, flang -fc1, to enable the
+  // implementation of the COMPILER_OPTIONS intrinsic. To this end, the
+  // frontend driver requires the list of the original compiler options,
+  // which is not available through other means.
   // TODO: This way of passing information between the compiler and frontend
   // drivers is discouraged. We should find a better way not involving env
   // variables.
   std::string compilerOptsGathered;
   llvm::raw_string_ostream os(compilerOptsGathered);
-  for (int i = 0; i < argc; ++i) {
-    os << argv[i];
-    if (i < argc - 1) {
+  const llvm::opt::InputArgList &argList = c->getInputArgs();
+  bool first = true;
+  for (const auto *arg : argList) {
----------------
tarunprabhu wrote:

Could we use a more concrete type here instead of `auto`?

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


More information about the flang-commits mailing list