[flang-commits] [flang] [flang][driver] Improve diagnostic for assembly inputs (PR #174316)

Soumik Kumar Basu via flang-commits flang-commits at lists.llvm.org
Fri Jan 30 20:33:34 PST 2026


https://github.com/soumikiith updated https://github.com/llvm/llvm-project/pull/174316

>From 191887e8c6abaf7a1d0265f16343036d2f802524 Mon Sep 17 00:00:00 2001
From: soumikiith <cs21resch11004 at iith.ac.in>
Date: Sun, 4 Jan 2026 12:54:33 +0530
Subject: [PATCH 1/6] [flang][driver] Improve diagnostic for assembly inputs

The flang driver currently attempts to invoke the integrated assembler
when given assembly inputs, resulting in an opaque
"unknown integrated tool '-cc1as'" error.

Detect assembly inputs early in the driver and emit a clear diagnostic
explaining that flang does not support assembling, suggesting the use
of clang instead and documenting the required runtime libraries.
---
 flang/test/Driver/asm-error-fix.s   |  9 +++++++++
 flang/tools/flang-driver/driver.cpp | 21 +++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 flang/test/Driver/asm-error-fix.s

diff --git a/flang/test/Driver/asm-error-fix.s b/flang/test/Driver/asm-error-fix.s
new file mode 100644
index 0000000000000..d9d5d444bd698
--- /dev/null
+++ b/flang/test/Driver/asm-error-fix.s
@@ -0,0 +1,9 @@
+! Test that flang rejects assembly files as input
+
+! RUN: not %flang -c %s 2>&1 | FileCheck %s
+
+! CHECK: error: flang does not accept assembly code
+
+.globl foo
+foo:
+  ret
diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp
index 0840255a739f3..136922cceff0d 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -147,6 +147,27 @@ int main(int argc, const char **argv) {
   llvm::SmallVector<std::pair<int, const clang::driver::Command *>, 4>
       failingCommands;
 
+  for (const auto &job : c->getJobs()) {
+    const auto *cmd = llvm::dyn_cast<clang::driver::Command>(&job);
+    if (!cmd)
+      continue;
+      
+    for (const clang::driver::InputInfo &inputInfo : cmd->getInputInfos()) {
+      clang::driver::types::ID type = inputInfo.getType();
+      
+      if (type == clang::driver::types::TY_Asm ||
+          type == clang::driver::types::TY_PP_Asm) {
+        
+        diags.Report(diags.getCustomDiagID(
+            clang::DiagnosticsEngine::Error,
+            "flang does not accept assembly code"))
+            << inputInfo.getAsString();
+            
+        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

>From bb495bd9550e1d81ca6b2aa0ca9c714422b39ff5 Mon Sep 17 00:00:00 2001
From: soumikiith <cs21resch11004 at iith.ac.in>
Date: Sat, 10 Jan 2026 14:29:20 +0530
Subject: [PATCH 2/6] [flang][driver] Improve diagnostic for assembly input

---
 flang/tools/flang-driver/driver.cpp | 36 ++++++++++++++++-------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp
index 136922cceff0d..c0cb2842e5c34 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -147,26 +147,30 @@ int main(int argc, const char **argv) {
   llvm::SmallVector<std::pair<int, const clang::driver::Command *>, 4>
       failingCommands;
 
-  for (const auto &job : c->getJobs()) {
-    const auto *cmd = llvm::dyn_cast<clang::driver::Command>(&job);
-    if (!cmd)
+// Reject assembly files as flang does not support assembling
+if (c) {
+  for (const llvm::opt::Arg *arg : c->getInputArgs()) {
+    if (arg->getOption().getKind() != llvm::opt::Option::InputClass)
       continue;
+
+    llvm::StringRef filename(arg->getValue());
+
+    // Determine file type from extension
+    clang::driver::types::ID type =
+        clang::driver::types::lookupTypeForExtension(
+            filename.rsplit('.').second);
+
+    if (type == clang::driver::types::TY_Asm ||
+        type == clang::driver::types::TY_PP_Asm) {
       
-    for (const clang::driver::InputInfo &inputInfo : cmd->getInputInfos()) {
-      clang::driver::types::ID type = inputInfo.getType();
-      
-      if (type == clang::driver::types::TY_Asm ||
-          type == clang::driver::types::TY_PP_Asm) {
-        
-        diags.Report(diags.getCustomDiagID(
-            clang::DiagnosticsEngine::Error,
-            "flang does not accept assembly code"))
-            << inputInfo.getAsString();
-            
-        return 1;
-      }
+      diags.Report(diags.getCustomDiagID(
+          clang::DiagnosticsEngine::Error,
+          "flang does not support assembly files as input: '%0'"))
+          << filename;
+      return 1;
     }
   }
+}
 
   // Set the environment variable, FLANG_COMPILER_OPTIONS_STRING, to contain all
   // the compiler options. This is intended for the frontend driver,

>From 5a51d14851abd9571c51ad2a8a3d10b4ea117fde Mon Sep 17 00:00:00 2001
From: soumikiith <cs21resch11004 at iith.ac.in>
Date: Sat, 10 Jan 2026 14:31:38 +0530
Subject: [PATCH 3/6] [flang][driver] Improve diagnostic for assembly input

---
 flang/tools/flang-driver/driver.cpp | 44 ++++++++++++++---------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp
index c0cb2842e5c34..305eb106fb8dd 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -147,30 +147,30 @@ int main(int argc, const char **argv) {
   llvm::SmallVector<std::pair<int, const clang::driver::Command *>, 4>
       failingCommands;
 
-// Reject assembly files as flang does not support assembling
-if (c) {
-  for (const llvm::opt::Arg *arg : c->getInputArgs()) {
-    if (arg->getOption().getKind() != llvm::opt::Option::InputClass)
-      continue;
-
-    llvm::StringRef filename(arg->getValue());
-
-    // Determine file type from extension
-    clang::driver::types::ID type =
-        clang::driver::types::lookupTypeForExtension(
-            filename.rsplit('.').second);
-
-    if (type == clang::driver::types::TY_Asm ||
-        type == clang::driver::types::TY_PP_Asm) {
-      
-      diags.Report(diags.getCustomDiagID(
-          clang::DiagnosticsEngine::Error,
-          "flang does not support assembly files as input: '%0'"))
-          << filename;
-      return 1;
+  // Reject assembly files as flang does not support assembling
+  if (c) {
+    for (const llvm::opt::Arg *arg : c->getInputArgs()) {
+      if (arg->getOption().getKind() != llvm::opt::Option::InputClass)
+        continue;
+
+      llvm::StringRef filename(arg->getValue());
+
+      // Determine file type from extension
+      clang::driver::types::ID type =
+          clang::driver::types::lookupTypeForExtension(
+              filename.rsplit('.').second);
+
+      if (type == clang::driver::types::TY_Asm ||
+          type == clang::driver::types::TY_PP_Asm) {
+
+        diags.Report(diags.getCustomDiagID(
+            clang::DiagnosticsEngine::Error,
+            "flang does not support assembly files as input: '%0'"))
+            << filename;
+        return 1;
+      }
     }
   }
-}
 
   // Set the environment variable, FLANG_COMPILER_OPTIONS_STRING, to contain all
   // the compiler options. This is intended for the frontend driver,

>From 04bcb1071d05a62537131e9869fc88fe43eaa896 Mon Sep 17 00:00:00 2001
From: soumikiith <cs21resch11004 at iith.ac.in>
Date: Wed, 14 Jan 2026 13:47:00 +0530
Subject: [PATCH 4/6] =?UTF-8?q?I=E2=80=99ve=20moved=20the=20assembly-input?=
 =?UTF-8?q?=20rejection=20logic=20into=20a=20small=20helper=20function=20a?=
 =?UTF-8?q?s=20suggested,=20and=20added=20a=20TODO=20noting=20that=20it=20?=
 =?UTF-8?q?is=20temporary=20and=20should=20be=20removed=20once=20flang=20s?=
 =?UTF-8?q?upports=20assembly=20inputs.=20The=20helper=20conservatively=20?=
 =?UTF-8?q?inspects=20only=20InputClass=20arguments=20and=20skips=20inputs?=
 =?UTF-8?q?=20without=20an=20extension=20to=20avoid=20misclassification.?=
 =?UTF-8?q?=20The=20main=20driver=20logic=20is=20now=20unchanged=20aside?=
 =?UTF-8?q?=20from=20the=20single=20call=20to=20this=20helper.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 flang/tools/flang-driver/driver.cpp | 54 ++++++++++++++++-------------
 1 file changed, 30 insertions(+), 24 deletions(-)

diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp
index 305eb106fb8dd..946d50d19cca8 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -83,6 +83,32 @@ static void ExpandResponseFiles(llvm::StringSaver &saver,
   }
 }
 
+static bool rejectAssemblyInputs(const llvm::opt::ArgList &Args,
+                                 clang::DiagnosticsEngine &Diags) {
+
+  for (const llvm::opt::Arg *Arg : Args) {
+    if (Arg->getOption().getKind() != llvm::opt::Option::InputClass)
+      continue;
+
+    llvm::StringRef Filename(Arg->getValue());
+
+    llvm::StringRef Ext = Filename.rsplit('.').second;
+
+    clang::driver::types::ID Type =
+        clang::driver::types::lookupTypeForExtension(Ext);
+
+    if (Type == clang::driver::types::TY_Asm ||
+        Type == clang::driver::types::TY_PP_Asm) {
+      Diags.Report(Diags.getCustomDiagID(
+          clang::DiagnosticsEngine::Error,
+          "flang does not support assembly files as input: '%0'"))
+          << Filename;
+      return true;
+    }
+  }
+  return false;
+}
+
 int main(int argc, const char **argv) {
 
   // Initialize variables to call the driver
@@ -147,30 +173,10 @@ int main(int argc, const char **argv) {
   llvm::SmallVector<std::pair<int, const clang::driver::Command *>, 4>
       failingCommands;
 
-  // Reject assembly files as flang does not support assembling
-  if (c) {
-    for (const llvm::opt::Arg *arg : c->getInputArgs()) {
-      if (arg->getOption().getKind() != llvm::opt::Option::InputClass)
-        continue;
-
-      llvm::StringRef filename(arg->getValue());
-
-      // Determine file type from extension
-      clang::driver::types::ID type =
-          clang::driver::types::lookupTypeForExtension(
-              filename.rsplit('.').second);
-
-      if (type == clang::driver::types::TY_Asm ||
-          type == clang::driver::types::TY_PP_Asm) {
-
-        diags.Report(diags.getCustomDiagID(
-            clang::DiagnosticsEngine::Error,
-            "flang does not support assembly files as input: '%0'"))
-            << filename;
-        return 1;
-      }
-    }
-  }
+  // Reject assembly files as flang does not support assembly inputs.
+  // TODO: Since clang supports this, flang should too.
+  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,

>From c1ff7f11df9148921e1690bbb050ac5eb349ae5a Mon Sep 17 00:00:00 2001
From: soumikiith <cs21resch11004 at iith.ac.in>
Date: Fri, 16 Jan 2026 14:51:15 +0530
Subject: [PATCH 5/6] Addressed the style feedback by switching to camelCase
 variable names, removing the early continue, and cleaning up the spacing in
 the helper function.

---
 flang/tools/flang-driver/driver.cpp | 38 +++++++++++++----------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp
index 946d50d19cca8..0e7d31a50e105 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -83,27 +83,23 @@ static void ExpandResponseFiles(llvm::StringSaver &saver,
   }
 }
 
-static bool rejectAssemblyInputs(const llvm::opt::ArgList &Args,
-                                 clang::DiagnosticsEngine &Diags) {
-
-  for (const llvm::opt::Arg *Arg : Args) {
-    if (Arg->getOption().getKind() != llvm::opt::Option::InputClass)
-      continue;
-
-    llvm::StringRef Filename(Arg->getValue());
-
-    llvm::StringRef Ext = Filename.rsplit('.').second;
-
-    clang::driver::types::ID Type =
-        clang::driver::types::lookupTypeForExtension(Ext);
-
-    if (Type == clang::driver::types::TY_Asm ||
-        Type == clang::driver::types::TY_PP_Asm) {
-      Diags.Report(Diags.getCustomDiagID(
-          clang::DiagnosticsEngine::Error,
-          "flang does not support assembly files as input: '%0'"))
-          << Filename;
-      return true;
+static bool rejectAssemblyInputs(const llvm::opt::ArgList &args,
+                                 clang::DiagnosticsEngine &diags) {
+  for (const llvm::opt::Arg *arg : args) {
+    if (arg->getOption().getKind() == llvm::opt::Option::InputClass) {
+      llvm::StringRef filename(arg->getValue());
+      llvm::StringRef ext = filename.rsplit('.').second;
+      clang::driver::types::ID type =
+          clang::driver::types::lookupTypeForExtension(ext);
+
+      if (type == clang::driver::types::TY_Asm ||
+          type == clang::driver::types::TY_PP_Asm) {
+        diags.Report(diags.getCustomDiagID(
+            clang::DiagnosticsEngine::Error,
+            "flang does not support assembly files as input: '%0'"))
+            << filename;
+        return true;
+      }
     }
   }
   return false;

>From 9dd29ed2620ad90b3eb6e794bfb6087b142e3391 Mon Sep 17 00:00:00 2001
From: soumikiith <cs21resch11004 at iith.ac.in>
Date: Sat, 31 Jan 2026 10:01:47 +0530
Subject: [PATCH 6/6] [Flang] Add and fix asm-error-fix driver test

Add .s to config.suffixes in lit.cfg.py so that lit discovers
assembly file tests, and fix the CHECK string in asm-error-fix.s
to match flang's actual error message.
---
 flang/test/Driver/asm-error-fix.s | 2 +-
 flang/test/lit.cfg.py             | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/flang/test/Driver/asm-error-fix.s b/flang/test/Driver/asm-error-fix.s
index d9d5d444bd698..725366de84eda 100644
--- a/flang/test/Driver/asm-error-fix.s
+++ b/flang/test/Driver/asm-error-fix.s
@@ -2,7 +2,7 @@
 
 ! RUN: not %flang -c %s 2>&1 | FileCheck %s
 
-! CHECK: error: flang does not accept assembly code
+! CHECK: error: flang does not support assembly files as input
 
 .globl foo
 foo:
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index 4221354df34a2..3a87f9ea06803 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -64,6 +64,7 @@
     ".ll",
     ".fir",
     ".mlir",
+    ".s",
 ]
 
 config.substitutions.append(("%PATH%", config.environment["PATH"]))



More information about the flang-commits mailing list