Files
clang-p2996/flang/test/Lower/stop-statement.f90
Valentin Clement (バレンタイン クレメン) 12ba74e181 [flang] Do not produce result for void runtime call (#123155)
Runtime function call to a void function are producing a ssa value
because the FunctionType result is set to NoneType with is later
translated to a empty struct. This is not an issue when going to LLVM IR
but it breaks when lowering a gpu module to PTX. This patch update the
RTModel to correctly set the FunctionType result type to nothing.

This is one runtime call before this patch at the LLVM IR dialect step.
```
%45 = llvm.call @_FortranAAssign(%arg0, %1, %44, %4) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i32) -> !llvm.struct<()>
```

After the patch the call would be correctly formed
```
llvm.call @_FortranAAssign(%arg0, %1, %44, %4) : (!llvm.ptr, !llvm.ptr, !llvm.ptr, i32) -> ()
```

Without the patch it would lead to error like:
```
ptxas /tmp/mlir-cuda_device_mod-nvptx64-nvidia-cuda-sm_60-e804b6.ptx, line 10; error   : Output parameter cannot be an incomplete array.
ptxas /tmp/mlir-cuda_device_mod-nvptx64-nvidia-cuda-sm_60-e804b6.ptx, line 125; error   : Call has wrong number of parameters
```

The change is pretty much mechanical.
2025-01-16 12:34:38 -08:00

80 lines
3.0 KiB
Fortran

! RUN: bbc %s -emit-fir -hlfir=false --canonicalize -o - | FileCheck %s
! CHECK-LABEL: stop_test
subroutine stop_test()
! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : i32
! CHECK-DAG: %[[false:.*]] = arith.constant false
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c0]], %[[false]], %[[false]])
! CHECK-NEXT: fir.unreachable
stop
end subroutine
! CHECK-LABEL: stop_code
subroutine stop_code()
stop 42
! CHECK-DAG: %[[c42:.*]] = arith.constant 42 : i32
! CHECK-DAG: %[[false:.*]] = arith.constant false
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c42]], %[[false]], %[[false]])
! CHECK-NEXT: fir.unreachable
end subroutine
! CHECK-LABEL: stop_error
subroutine stop_error()
error stop
! CHECK-DAG: %[[c_1:.*]] = arith.constant 1 : i32
! CHECK-DAG: %[[true:.*]] = arith.constant true
! CHECK-DAG: %[[false:.*]] = arith.constant false
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c_1]], %[[true]], %[[false]])
! CHECK-NEXT: fir.unreachable
end subroutine
! CHECK-LABEL: stop_quiet
subroutine stop_quiet()
logical :: b
stop, quiet = b
! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : i32
! CHECK-DAG: %[[false:.*]] = arith.constant false
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.logical<4> {bindc_name = "b", uniq_name = "_QFstop_quietEb"}
! CHECK: %[[b:.*]] = fir.load %[[ALLOCA]]
! CHECK: %[[bi1:.*]] = fir.convert %[[b]] : (!fir.logical<4>) -> i1
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c0]], %[[false]], %[[bi1]])
! CHECK-NEXT: fir.unreachable
end subroutine
! CHECK-LABEL: stop_quiet_constant
subroutine stop_quiet_constant()
stop, quiet = .true.
! CHECK-DAG: %[[true:.*]] = arith.constant true
! CHECK-DAG: %[[false:.*]] = arith.constant false
! CHECK-DAG: %[[c0:.*]] = arith.constant 0 : i32
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c0]], %[[false]], %[[true]])
! CHECK-NEXT: fir.unreachable
end subroutine
! CHECK-LABEL: stop_error_code_quiet
subroutine stop_error_code_quiet(b)
logical :: b
error stop 66, quiet = b
! CHECK-DAG: %[[c66:.*]] = arith.constant 66 : i32
! CHECK-DAG: %[[true:.*]] = arith.constant true
! CHECK-DAG: %[[b:.*]] = fir.load %arg0
! CHECK-DAG: %[[bi1:.*]] = fir.convert %[[b]] : (!fir.logical<4>) -> i1
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c66]], %[[true]], %[[bi1]])
! CHECK-NEXT: fir.unreachable
end subroutine
! CHECK-LABEL: stop_char_lit
subroutine stop_char_lit
! CHECK-DAG: %[[false:.*]] = arith.constant false
! CHECK-DAG: %[[five:.*]] = arith.constant 5 : index
! CHECK-DAG: %[[lit:.*]] = fir.address_of(@_QQ{{.*}}) : !fir.ref<!fir.char<1,5>>
! CHECK-DAG: %[[buff:.*]] = fir.convert %[[lit]] : (!fir.ref<!fir.char<1,5>>) -> !fir.ref<i8>
! CHECK-DAG: %[[len:.*]] = fir.convert %[[five]] : (index) -> i64
! CHECK: fir.call @{{.*}}StopStatementText(%[[buff]], %[[len]], %[[false]], %[[false]]) {{.*}}:
! CHECK-NEXT: fir.unreachable
stop 'crash'
end subroutine stop_char_lit
! CHECK-DAG: func private @_Fortran{{.*}}StopStatement(i32, i1, i1)
! CHECK-DAG: func private @_Fortran{{.*}}StopStatementText(!fir.ref<i8>, i64, i1, i1)