<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/141460>141460</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang][mlir] compiler crashes in where construct
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir,
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shivaramaarao
</td>
</tr>
</table>
<pre>
consider the following program
``` SUBROUTINE init(p,w,r,t)
IMPLICIT NONE
REAL, INTENT(IN) :: p
REAL(KIND=4), INTENT(INOUT) :: w(:,:),r(:,:)
REAL(KIND=4), INTENT(INOUT) :: t(:)
!
where(w(:,1)==0.)
t (:)= 1.0
elsewhere
t(:) = r(:,1) / sub(r(:,1))
end where
CONTAINS
FUNCTION sub(p1) RESULT(p2)
IMPLICIT NONE
REAL, DIMENSION(:), INTENT(IN) :: p1
REAL, DIMENSION(SIZE(p1)) :: p2
p2(:) = p1(:)
END FUNCTION sub
END SUBROUTINE init ```
when compiled under O2 option, the flang compiler crashes
``` #0 0x000055f5af734532 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/shivaram/llvm_mir_flang/bin/flang+0x1784532)
#1 0x000055f5af73169f llvm::sys::RunSignalHandlers() (/home/shivaram/llvm_mir_flang/bin/flang+0x178169f)
#2 0x000055f5af7317e4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f639a448520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f639a49c9fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f639a49c9fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007f639a49c9fc pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007f639a448476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007f639a42e7f3 abort ./stdlib/abort.c:81:7
#9 0x00007f639a42e71b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f639a43fe96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x000055f5b53c265d mlir::RewriterBase::eraseOp(mlir::Operation*)::'lambda0'(mlir::Operation*)::operator()(mlir::Operation*) const PatternMatch.cpp:0:0
#12 0x000055f5b53c136a mlir::RewriterBase::eraseOp(mlir::Operation*)::'lambda0'(mlir::Operation*)::operator()(mlir::Operation*) const PatternMatch.cpp:0:0
#13 0x000055f5b53c136a mlir::RewriterBase::eraseOp(mlir::Operation*)::'lambda0'(mlir::Operation*)::operator()(mlir::Operation*) const PatternMatch.cpp:0:0
#14 0x000055f5b53c136a mlir::RewriterBase::eraseOp(mlir::Operation*)::'lambda0'(mlir::Operation*)::operator()(mlir::Operation*) const PatternMatch.cpp:0:0
#15 0x000055f5b53c0334 mlir::RewriterBase::eraseOp(mlir::Operation*) (/home/shivaram/llvm_mir_flang/bin/flang+0x7410334)
#16 0x000055f5b3744c50 mlir::detail::ConversionPatternRewriterImpl::applyRewrites() (/home/shivaram/llvm_mir_flang/bin/flang+0x5794c50)
#17 0x000055f5b376208f mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/home/shivaram/llvm_mir_flang/bin/flang+0x57b208f)
#18 0x000055f5b3764839 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/home/shivaram/llvm_mir_
lang/bin/flang+0x57b4839)
#19 0x000055f5b0693c14 (anonymous namespace)::LowerHLFIROrderedAssignments::runOnOperation() LowerHLFIROrderedAssignments.cpp:0:0
#20 0x000055f5b515161e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/shivaram/llvm_mir_flang/bin/flang+0x71a161e)
#21 0x000055f5b5151ab0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassIn
trumentation::PipelineParentInfo const*) (/home/shivaram/llvm_mir_flang/bin/flang+0x71a1ab0)
#22 0x000055f5b5152c09 mlir::PassManager::run(mlir::Operation*) (/home/shivaram/llvm_mir_flang/bin/flang+0x71a2c09)
#23 0x000055f5afa59c86 Fortran::frontend::CodeGenAction::generateLLVMIR() (/home/shivaram/llvm_mir_flang/bin/flang+0x1aa9c86)
#24 0x000055f5afa5e898 Fortran::frontend::CodeGenAction::executeAction() (/home/shivaram/llvm_mir_flang/bin/flang+0x1aae898)
#25 0x000055f5af772da0 Fortran::frontend::FrontendAction::execute() (/home/shivaram/llvm_mir_flang/bin/flang+0x17c2da0)
#26 0x000055f5af7600ab Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/home/shivaram/llvm_mir_flang/bin/flang+0x17b00ab)
#27 0x000055f5af77e5c9 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/home/shivaram/llvm_mir_flang/bin/flang+0x17ce5c9)
#28 0x000055f5af128a3f fc1_main(llvm::ArrayRef<char const*>, char const*) (/home/shivaram/llvm_mir_flang/bin/flang+0x1178a3f)
#29 0x000055f5af033f9a main (/home/shivaram/llvm_mir_flang/bin/flang+0x1083f9a)
#30 0x00007f639a42fd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#31 0x00007f639a42fe40 call_init ./csu/../csu/libc-start.c:128:20
#32 0x00007f639a42fe40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#33 0x000055f5af1275b5 _start (/home/shivaram/llvm_mir_flang/bin/flang+0x11775b5)
flang-21: error: unable to execute command: Aborted (core dumped)
flang-21: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 21.0.0git (https://github.com/llvm/llvm-project.git b12d68e0b253b4dc6c3fd9d99ee8421605e274aa)
Target: x86_64-unknown-linux-gnu ```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzcWUtz2zjW_TXwBmUVHn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