llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Jan Leyonberg (jsjodin) <details> <summary>Changes</summary> 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 <noreply@<!-- -->anthropic.com> --- Full diff: https://github.com/llvm/llvm-project/pull/187729.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1) - (added) clang/test/Driver/clangir-no-llvmir.c (+25) ``````````diff 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() {} `````````` </details> https://github.com/llvm/llvm-project/pull/187729 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
