https://github.com/jsjodin created https://github.com/llvm/llvm-project/pull/187729
This patch prevents the -fclangir flag being passed on when the input is LLVM-IR Files. This happened during the backend phase for OMP offloading compilation and would fail with "fatal error: cannot apply AST actions to LLVM IR file". Co-authored-by: Claude Opus 4.6 <[email protected]> >From f63fb5e18b190ffc2b62468de02c9b674a82e3b4 Mon Sep 17 00:00:00 2001 From: Jan Leyonberg <[email protected]> Date: Mon, 9 Mar 2026 11:03:07 -0400 Subject: [PATCH] [clang] Don't pass -fclangir to LLVM-IR files This patch prevents the -fclangir patch being passed on when the input is LLVM-IR Files. This happened during the backend phase for OMP offloading compilation and would fail with "fatal error: cannot apply AST actions to LLVM IR file". Co-authored-by: Claude Opus 4.6 <[email protected]> --- clang/lib/Driver/ToolChains/Clang.cpp | 2 +- clang/test/Driver/clangir-no-llvmir.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 clang/test/Driver/clangir-no-llvmir.c diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 6416baf9126ff..6639a8a6700f1 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5080,7 +5080,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } } - if (Args.hasArg(options::OPT_fclangir)) + if (Args.hasArg(options::OPT_fclangir) && !types::isLLVMIR(Input.getType())) CmdArgs.push_back("-fclangir"); if (IsOpenMPDevice) { diff --git a/clang/test/Driver/clangir-no-llvmir.c b/clang/test/Driver/clangir-no-llvmir.c new file mode 100644 index 0000000000000..c4d6f4cd0eda8 --- /dev/null +++ b/clang/test/Driver/clangir-no-llvmir.c @@ -0,0 +1,25 @@ +// Verify that -fclangir is passed to -cc1 when compiling source, but not when +// the input is LLVM IR (e.g. during the backend phase of OpenMP offloading). +// Without this fix, the backend step would fail with: +// "fatal error: cannot apply AST actions to LLVM IR file" + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fclangir -fopenmp \ +// RUN: -fopenmp-targets=amdgcn-amd-amdhsa --offload-arch=gfx906 \ +// RUN: -nogpulib %s 2>&1 | FileCheck %s + +// Host source compilation should have -fclangir. +// CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu" +// CHECK-SAME: "-fclangir" +// CHECK-SAME: "-x" "c" + +// Device source compilation should have -fclangir. +// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa" +// CHECK-SAME: "-fclangir" +// CHECK-SAME: "-x" "c" + +// After source compilations, no further -cc1 invocations should have -fclangir +// (backend steps take LLVM IR as input, not source). +// CHECK-NOT: "-fclangir" +// CHECK: clang-linker-wrapper + +void foo() {} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
