[flang-commits] [flang] [flang][driver] Improve diagnostic for assembly inputs (PR #174316)
Soumik Kumar Basu via flang-commits
flang-commits at lists.llvm.org
Sat Jan 3 23:34:42 PST 2026
https://github.com/soumikiith created https://github.com/llvm/llvm-project/pull/174316
This PR improves the error message when assembly files are passed to the Flang driver.
## Current Behavior
```
$ flang test.s
error: unknown integrated tool '-cc1as'. Valid tools include '-fc1'.
```
## New Behavior
```
$ flang test.s
error: flang does not support assembly files as input
```
## Changes
- Modified the driver to detect assembly file extensions early
- Added a clear, helpful error message
- Added test coverage for the new error message
Fixes #173528
>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] [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
More information about the flang-commits
mailing list