Closed pawosm-arm closed 2 weeks ago
@llvm/issue-subscribers-flang-ir
Author: Paul Osmialowski (pawosm-arm)
@llvm/issue-subscribers-bug
Author: Paul Osmialowski (pawosm-arm)
I've tried this with gfortran, but it's very explicit regarding integer types, so it needed a slight change in the something2
subroutine:
SUBROUTINE something2()
TYPE(c_ptr) :: ptr
INTEGER(c_size_t), PARAMETER :: size = 1
ptr = c_malloc(size)
END SUBROUTINE
Nevertheless, this slight change does not prevent the ICE in flang-new, while gfortran is able to compile the entire module.
Turned out, tco works with -O2
by default. I've tried to compile this code with flang-new -O2
and it worked!
Turned out, tco works with
-O2
by default. I've tried to compile this code withflang-new -O2
and it worked!
Worked as in "compiles to something that doesn't ICE" - does it actually make sense? And does it fail with -O1
in tco?
Sadly, -O2 has been hardcoded https://github.com/llvm/llvm-project/blob/5ee53d417f41e8f452255ded1ff6a522afe17f08/flang/tools/tco/tco.cpp#L136
Sadly, -O2 has been hardcoded
Oh, that's not useful... I wonder if we should make a change - but I guess it's more important to figure out why it fails in -O1
(which I think is the default in flang-new)
The issue may be exposed by O2, but this is not related. You can crash with flang-new -c
[edit: regardless of -O levels] if you add the following to your example:
subroutine test(x, y)
real :: x(:), y(:)
call bar(x+y)
end subroutine
We should change the way TYPE(C_PTR) results are handled in FIR. The AbstractResult pass is rewriting them here to integer results, which is "OK" if this hits the assembly stage without meeting a conflicting usage. But malloc is inserted with the correct signature when lowering fir.allocmem (and probably other things), which conflicts.
edit: The -O difference probably comes from the fact that fir.allocmem are "raised" to alloca when possible here, which prevents the introduction of the conflicting malloc usage.
I tested the original code/problem on a recent flang-new compiled from main branch, and the code compiles without any errors now.
$ flang-new --version
flang-new version 20.0.0git (https://github.com/llvm/llvm-project.git 7792b4ae79e5ac9355ee13b01f16e25455f8427f)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm/llvm-project/install/bin
There's nothing more to do here, closing it.
Hello,
I've found a piece of Fortran code which exposes a puzzling behavior of the flang-new compiler:
Trying to compile this results in an ICE:
It is sufficient to either replace the
ptr = c_malloc(1)
line with theptr = c_null_ptr
line in thesomething2
subroutine or remove thela = ia
line in thesomething1
subroutine to make this problem go away. Also, replacing theLOGICAL
andINTEGER
types insomething1
with matching types (e.g. with bothLOGICAL
or bothINTEGER
) makes the problem go away.I've also tried the explicit bbc -> tco -> opt -> llc path, and the ICE did not occur.