[clang] [CIR] Disable CIR pipeline for LLVM IR inputs (PR #187729)
Jan Leyonberg via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 26 09:25:55 PDT 2026
https://github.com/jsjodin updated https://github.com/llvm/llvm-project/pull/187729
>From b3f98883ea83f2f5533c2a080acf9cc364a8d216 Mon Sep 17 00:00:00 2001
From: Jan Leyonberg <jan_sjodin at yahoo.com>
Date: Mon, 9 Mar 2026 11:03:07 -0400
Subject: [PATCH 1/2] [clang] Disable CIR pipeline for LLVM IR inputs
When -fclangir is passed and the input is LLVM IR (e.g. during the
backend phase of OpenMP offloading), the CIR frontend pipeline is not
applicable.
---
clang/lib/Frontend/CompilerInvocation.cpp | 6 ++++++
clang/test/Driver/clangir-no-llvmir.c | 16 ++++++++++++++++
2 files changed, 22 insertions(+)
create mode 100644 clang/test/Driver/clangir-no-llvmir.c
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 748c36efefaed..c6e8644905964 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3291,6 +3291,12 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
Opts.DashX = DashX;
+ // CIR is a source-level frontend pipeline. When the input is already LLVM IR
+ // (e.g. during the backend phase of OpenMP offloading), the standard LLVM
+ // backend should be used instead.
+ if (Opts.UseClangIRPipeline && DashX.getLanguage() == Language::LLVM_IR)
+ Opts.UseClangIRPipeline = false;
+
return Diags.getNumErrors() == NumErrorsBefore;
}
diff --git a/clang/test/Driver/clangir-no-llvmir.c b/clang/test/Driver/clangir-no-llvmir.c
new file mode 100644
index 0000000000000..a13f85aa1c404
--- /dev/null
+++ b/clang/test/Driver/clangir-no-llvmir.c
@@ -0,0 +1,16 @@
+// Verify that -fclangir is always forwarded to -cc1 by the driver, and
+// that the frontend ignores it when the input is LLVM IR.
+
+// -fclangir should be passed to -cc1 for source inputs.
+// RUN: %clang -### -fclangir -S %s 2>&1 | FileCheck %s --check-prefix=SOURCE
+// SOURCE: "-cc1"
+// SOURCE-SAME: "-fclangir"
+// SOURCE-SAME: "-x" "c"
+
+// -fclangir should also be passed to -cc1 for LLVM IR inputs (the frontend
+// will ignore it and use the standard LLVM backend).
+// RUN: %clang -### -fclangir -S -x ir /dev/null 2>&1 | FileCheck %s --check-prefix=LLVMIR
+// LLVMIR: "-cc1"
+// LLVMIR-SAME: "-fclangir"
+
+void foo() {}
>From 41204b83ecb3aff6a2ae211331a65a7bbcbfe4b6 Mon Sep 17 00:00:00 2001
From: Jan Leyonberg <jan_sjodin at yahoo.com>
Date: Wed, 25 Mar 2026 12:30:52 -0400
Subject: [PATCH 2/2] Move test to CIR subdirectory and rename.
---
clang/test/{Driver/clangir-no-llvmir.c => CIR/Driver/clangir.c} | 2 ++
1 file changed, 2 insertions(+)
rename clang/test/{Driver/clangir-no-llvmir.c => CIR/Driver/clangir.c} (94%)
diff --git a/clang/test/Driver/clangir-no-llvmir.c b/clang/test/CIR/Driver/clangir.c
similarity index 94%
rename from clang/test/Driver/clangir-no-llvmir.c
rename to clang/test/CIR/Driver/clangir.c
index a13f85aa1c404..afbe6c6d2388f 100644
--- a/clang/test/Driver/clangir-no-llvmir.c
+++ b/clang/test/CIR/Driver/clangir.c
@@ -1,3 +1,5 @@
+// Tests related to -fclangir option.
+
// Verify that -fclangir is always forwarded to -cc1 by the driver, and
// that the frontend ignores it when the input is LLVM IR.
More information about the cfe-commits
mailing list