[flang] Segmentation fault on assigning array with common, equivalence statements present
I am seeing a segfault when building and running the program below using flang. I am seeing this issue for both x86_64 and aarch64 and have been building with the -static flag.
subroutine foo
implicit NONE
real*8 common_arr1(133),common_arr2(133)
common /my_common_block/ common_arr1,common_arr2
real*8 arr1(133),arr2(133)
real*8 arr3(133,133),arr4(133,133)
equivalence(arr1,common_arr1),(arr2,common_arr2)
equivalence(arr3,arr4)
arr4 = 3
print *, "Passed"
return
end
program test
call foo()
end
gfortran and ifort both seem to handle this ok (please see godbolt here). I'm not entirely sure if I'm understanding the MLIR/LLVM IR/asm dumps correctly, but it looks like the arr4 = 3 snippet might be aliasing to arr1, which I think is leading to a number of bad writes and eventually leading to a segfault.
I originally ran into this when looking at 434.zeusmp in SPEC2006.
From what I can tell, part of the issue seems to be that the AggregateStoreKey values for both arr1 and arr3 are the same (they both seem to have the same scope and the same offset of 0). As a result, the AggregateStoreMap entry for arr3 is overwritten by that for arr1. Then, in ConvertVariable.cpp:instantiateAlias() when trying to fetch the aggregate store for arr4, the entry pointing to arr1 is returned, ultimately leading to the incorrect writes. I'm not entirely sure yet if this is the actual root problem, or if arr1/arr3 should have different scopes, offsets, etc.