llvm-project/flang/test/Driver/pass-plugin-codegen.f90
Alexis Engelke 277069e8c1
[Flang] Adjust pass plugin support to match Clang (#174006)
- Pass plugins can use LLVM options, matching #173287.
- Pass plugins can run a hook before codegen, matching #171872.
- Pass plugins are now tested whenever they can be built, matching
#171998.

Plugins currently don't work on AIX, tracked in #172203.
2026-01-07 09:59:17 +00:00

39 lines
1.4 KiB
Fortran

! This test checks that the pre-codegen hook of LLVM pass plugins is executed
! before the code generation pipeline. The hook can also replace the output
! with its own.
! UNSUPPORTED: system-windows
! REQUIRES: plugins, examples
! Plugins are currently broken on AIX, at least in the CI.
! XFAIL: system-aix
! Without -last-words the pass does nothing, flang emits assembly.
! RUN: %flang_fc1 -S %s -o - %loadbye \
! RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-INACTIVE
! With -last-words the pass intercepts the code generation and prints
! "CodeGen Bye" instead.
! RUN: %flang_fc1 -S %s -o - %loadbye -mllvm -last-words \
! RUN: | FileCheck %s --check-prefix=CHECK-ACTIVE
! When emitting LLVM IR, no back-end is executed and therefore no
! pre-codegen hook of LLVM pass plugins are executed.
! RUN: %flang_fc1 -emit-llvm %s -o - %loadbye -mllvm -last-words \
! RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-LLVM
! Bye fails and reports an error when an object file should be emitted.
! (Note that this is specific for Bye; other plugins can support this.)
! RUN: not %flang_fc1 -emit-obj %s -o - %loadbye -mllvm -last-words \
! RUN: 2>&1 | FileCheck %s --check-prefix=CHECK-ERR
! CHECK-INACTIVE-NOT: Bye
! CHECK-INACTIVE: empty_:
! CHECK-ACTIVE: CodeGen Bye
! CHECK-LLVM-NOT: Bye
! CHECK-LLVM: define{{.*}} void @empty_
! CHECK-ERR: error: last words unsupported for binary output
subroutine empty
end subroutine empty