https://github.com/jsjodin updated https://github.com/llvm/llvm-project/pull/187729
>From 83701f4202479072580a50a528c7fe097d573935 Mon Sep 17 00:00:00 2001 From: Jan Leyonberg <[email protected]> Date: Mon, 9 Mar 2026 11:03:07 -0400 Subject: [PATCH] [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() {} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
