This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix dereference of std::optional with no value
ClosedPublic

Authored by foad on Jan 26 2023, 9:29 AM.

Diff Detail

Event Timeline

foad created this revision.Jan 26 2023, 9:29 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 26 2023, 9:29 AM
foad requested review of this revision.Jan 26 2023, 9:29 AM

The bug was introduced by D139330.

With D142279 applied this causes an assertion failure in libstdc++:

FAIL: Flang :: Fir/non-trivial-procedure-binding-description.f90 (98 of 100)
******************** TEST 'Flang :: Fir/non-trivial-procedure-binding-description.f90' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/jayfoad2/llvm-release/bin/flang-new -fc1 -emit-mlir /home/jayfoad2/git/llvm-project/flang/test/Fir/non-trivial-procedure-binding-description.f90 -o - | /home/jayfoad2/llvm-release/bin/FileCheck /home/jayfoad2/git/llvm-project/flang/test/Fir/non-trivial-procedure-binding-description.f90 --check-prefix=BEFORE
: 'RUN: at line 2';   /home/jayfoad2/llvm-release/bin/flang-new -fc1 -emit-mlir /home/jayfoad2/git/llvm-project/flang/test/Fir/non-trivial-procedure-binding-description.f90 -o - | fir-opt --abstract-result-on-global-opt | /home/jayfoad2/llvm-release/bin/FileCheck /home/jayfoad2/git/llvm-project/flang/test/Fir/non-trivial-procedure-binding-description.f90 --check-prefix=AFTER
--
Exit Code: 2

Command Output (stderr):
--
/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/optional:477: _Tp &std::_Optional_base_impl<long, std::_Optional_base<long, true, true>>::_M_get() [_Tp = long, _Dp = std::_Optional_base<long, true, true>]: Assertion 'this->_M_is_engaged()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/jayfoad2/llvm-release/bin/flang-new -fc1 -emit-mlir /home/jayfoad2/git/llvm-project/flang/test/Fir/non-trivial-procedure-binding-description.f90 -o -
 #0 0x000000000557e5e7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/jayfoad2/llvm-release/bin/flang-new+0x557e5e7)
 #1 0x000000000557c49e llvm::sys::RunSignalHandlers() (/home/jayfoad2/llvm-release/bin/flang-new+0x557c49e)
 #2 0x000000000557edda SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f2160c65520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f2160cb9a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f2160cb9a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f2160cb9a7c pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f2160c65476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f2160c4b7f3 abort ./stdlib/abort.c:81:7
 #9 0x00007f2160f453ef (/lib/x86_64-linux-gnu/libstdc++.so.6+0xd83ef)
#10 0x000000000690da90 fir::factory::CharacterExprHelper::createAssign(fir::CharBoxValue const&, fir::CharBoxValue const&) (/home/jayfoad2/llvm-release/bin/flang-new+0x690da90)
#11 0x0000000005881fdb (anonymous namespace)::FirConverter::genAssignment(Fortran::evaluate::Assignment const&) Bridge.cpp:0:0
#12 0x0000000005878bb4 (anonymous namespace)::FirConverter::genFIR(Fortran::lower::pft::Evaluation&, bool) Bridge.cpp:0:0

Hi @foad, thank you for the fix. I also started looking into the failures you listed in D142279. To avoid duplicating the efforts: will you investigate the remaining failures?

With the same fix as here, I see these failures:

Flang :: Semantics/OpenACC/acc-canonicalization-validity.f90
flang-Unit :: Frontend/./FlangFrontendTests/5/7
flang-Unit :: Frontend/./FlangFrontendTests/6/7
vzakhari accepted this revision.Jan 26 2023, 9:33 AM
This revision is now accepted and ready to land.Jan 26 2023, 9:33 AM
foad added a comment.Jan 26 2023, 9:35 AM

To avoid duplicating the efforts: will you investigate the remaining failures?

No. I took a very quick look at the remaining failures and decided that I don't know enough about Fortran to fix them!

To avoid duplicating the efforts: will you investigate the remaining failures?

No. I took a very quick look at the remaining failures and decided that I don't know enough about Fortran to fix them!

Okay, I will investigate them.

foad added a comment.Jan 26 2023, 9:37 AM

To avoid duplicating the efforts: will you investigate the remaining failures?

No. I took a very quick look at the remaining failures and decided that I don't know enough about Fortran to fix them!

Okay, I will investigate them.

Thank you!

This revision was landed with ongoing or failed builds.Jan 26 2023, 9:52 AM
This revision was automatically updated to reflect the committed changes.