Author: Jan Leyonberg
Date: 2026-04-14T12:48:58-04:00
New Revision: 40a585e742ed6b28306d7511380079325ba1a003

URL: 
https://github.com/llvm/llvm-project/commit/40a585e742ed6b28306d7511380079325ba1a003
DIFF: 
https://github.com/llvm/llvm-project/commit/40a585e742ed6b28306d7511380079325ba1a003.diff

LOG: [CIR] Disable CIR pipeline for LLVM IR inputs (#187729)

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.


Co-authored-by: Claude Opus 4.6 <[email protected]>

Added: 
    clang/test/CIR/Driver/clangir.c

Modified: 
    clang/lib/Frontend/CompilerInvocation.cpp

Removed: 
    


################################################################################
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/CIR/Driver/clangir.c b/clang/test/CIR/Driver/clangir.c
new file mode 100644
index 0000000000000..afbe6c6d2388f
--- /dev/null
+++ b/clang/test/CIR/Driver/clangir.c
@@ -0,0 +1,18 @@
+// 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.
+
+// -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() {}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to