[flang-commits] [flang] [flang][Driver] Improve error message for assembly file input (PR #174069)

via flang-commits flang-commits at lists.llvm.org
Tue Dec 30 23:45:14 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-driver

Author: Soumik Kumar Basu (soumikiith)

<details>
<summary>Changes</summary>

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: Currently, the driver does not accept assembly code. Use clang instead.
Note that '-lflang_rt.runtime -lm' is required for linking.
```

## 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

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


2 Files Affected:

- (added) flang/test/Driver/asm-input-error.s (+14) 
- (modified) flang/tools/flang-driver/driver.cpp (+27) 


``````````diff
diff --git a/flang/test/Driver/asm-input-error.s b/flang/test/Driver/asm-input-error.s
new file mode 100644
index 0000000000000..6f148f1f1177e
--- /dev/null
+++ b/flang/test/Driver/asm-input-error.s
@@ -0,0 +1,14 @@
+! Test that assembly input produces a helpful error message when not supported
+! 
+! RUN: not %flang %s 2>&1 | FileCheck %s
+! RUN: not %flang -c %s 2>&1 | FileCheck %s
+! RUN: not %flang %s -o output 2>&1 | FileCheck %s
+
+! CHECK: error: Currently, the driver does not accept assembly code. Use clang instead.
+! CHECK-SAME: Note that '-lflang_rt.runtime -lm' is required for linking.
+
+! Some dummy assembly content
+.text
+.globl dummy_function
+dummy_function:
+    ret
\ No newline at end of file
diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp
index 0840255a739f3..660b291f2bc8a 100644
--- a/flang/tools/flang-driver/driver.cpp
+++ b/flang/tools/flang-driver/driver.cpp
@@ -83,6 +83,24 @@ static void ExpandResponseFiles(llvm::StringSaver &saver,
   }
 }
 
+// Check if any of the input files is an assembly file
+static bool hasAssemblyInput(llvm::ArrayRef<const char *> args) {
+  for (const char *arg : args) {
+    if (!arg)
+      continue;
+    llvm::StringRef argStr(arg);
+    // Skip options (arguments starting with -)
+    if (argStr.starts_with("-"))
+      continue;
+    // Check for assembly file extensions
+    if (argStr.ends_with(".s") || argStr.ends_with(".S") ||
+        argStr.ends_with(".asm"))
+      return true;
+  }
+  return false;
+}
+
+
 int main(int argc, const char **argv) {
 
   // Initialize variables to call the driver
@@ -97,6 +115,15 @@ int main(int argc, const char **argv) {
   llvm::StringSaver saver(a);
   ExpandResponseFiles(saver, args);
 
+    // Check if any input file is an assembly file before processing
+  if (hasAssemblyInput(args)) {
+    llvm::errs() << "error: Currently, the driver does not accept assembly "
+                << "code. Use clang instead. "
+                << "Note that '-lflang_rt.runtime -lm' is required for "
+                << "linking.\n";
+    return 1;
+  }
+
   // Check if flang is in the frontend mode
   auto firstArg = std::find_if(args.begin() + 1, args.end(),
                                [](const char *a) { return a != nullptr; });

``````````

</details>


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


More information about the flang-commits mailing list