[flang-commits] [flang] [flang][Driver] Improve error message for assembly file input (PR #174069)
Soumik Kumar Basu via flang-commits
flang-commits at lists.llvm.org
Tue Dec 30 23:50:55 PST 2025
https://github.com/soumikiith updated https://github.com/llvm/llvm-project/pull/174069
>From fa9cb2c547aec8a4dfa7a440a6de93ae2f66bc67 Mon Sep 17 00:00:00 2001
From: soumikiith <cs21resch11004 at iith.ac.in>
Date: Wed, 31 Dec 2025 13:04:46 +0530
Subject: [PATCH] [flang][Driver] Improve error message for assembly file input
---
flang/test/Driver/asm-input-error.s | 14 ++++++++++++++
flang/tools/flang-driver/driver.cpp | 27 +++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
create mode 100644 flang/test/Driver/asm-input-error.s
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; });
More information about the flang-commits
mailing list