Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Lower BIND(C) assumed length to CFI descriptor #65950

Merged
merged 2 commits into from
Sep 12, 2023

Conversation

jeanPerier
Copy link
Contributor

Outside of BIND(C), assumed length character scalar and explicit shape are passed by address + an extra length argument (fir.boxchar in FIR).

The standard mandates that they be passed via CFI descriptor in BIND(C) interface (fir.box in FIR). This patch fix the handling for this case.

@jeanPerier jeanPerier added the flang Flang issues not falling into any other category label Sep 11, 2023
@jeanPerier jeanPerier requested a review from a team as a code owner September 11, 2023 12:05
Copy link
Contributor

@psteinfeld psteinfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I build and run tests, I get an assertion. Here's the relevant excerpt from the log file:

FAIL: Flang :: Lower/HLFIR/bindc-assumed-length.f90 (1994 of 2453)
******************** TEST 'Flang :: Lower/HLFIR/bindc-assumed-length.f90' FAILED ********************
Script:
--
: 'RUN: at line 4';   bbc -emit-hlfir -o - /local/home/psteinfeld/main/llvm-project/flang/test/Lower/HLFIR/bindc-assumed-length.f90 2>&1 | /local/home/psteinfeld/main/llvm-project/build/bin/FileCheck /local/home/psteinfeld/main/llvm-project/flang/test/Lower/HLFIR/bindc-assumed-length.f90
--
Exit Code: 1

Command Output (stderr):
--
/local/home/psteinfeld/main/llvm-project/flang/test/Lower/HLFIR/bindc-assumed-length.f90:6:10: error: CHECK: expected string not found in input
! CHECK: func.func @foo(
         ^
<stdin>:1:1: note: scanning from here
bbc: /local/home/psteinfeld/main/llvm-project/flang/include/flang/Optimizer/Builder/BoxValue.h:300: fir::BoxValue::BoxValue(mlir::Value, llvm::ArrayRef<mlir::Value>, llvm::ArrayRef<mlir::Value>, llvm::ArrayRef<mlir::Value>): Assertion `verify()' failed.
^
<stdin>:16:63: note: possible intended match here
#11 0x0000556c5465d0c8 (anonymous namespace)::FirConverter::startNewFunction(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0
                                                              ^

Input file: <stdin>
Check file: /local/home/psteinfeld/main/llvm-project/flang/test/Lower/HLFIR/bindc-assumed-length.f90

-dump-input=help explains the following input dump.

Input was:
<<<<<<
           1: bbc: /local/home/psteinfeld/main/llvm-project/flang/include/flang/Optimizer/Builder/BoxValue.h:300: fir::BoxValue::BoxValue(mlir::Value, llvm::ArrayRef<mlir::Value>, llvm::ArrayRef<mlir::Value>, llvm::ArrayRef<mlir::Value>): Assertion `verify()' failed. 
check:6'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
           2: PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           3: Stack dump: 
check:6'0     ~~~~~~~~~~~~
           4: 0. Program arguments: bbc -emit-hlfir -o - /local/home/psteinfeld/main/llvm-project/flang/test/Lower/HLFIR/bindc-assumed-length.f90 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           5:  #0 0x0000556c5553326b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/home/psteinfeld/main/llvm-project/build/bin/bbc+0x21ad26b) 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           6:  #1 0x0000556c55530924 SignalHandler(int) Signals.cpp:0:0 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           .
           .
           .
          11:  #6 0x00007f9e23f5da76 .annobin___GI___assert_fail.end assert.c:0:0 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          12:  #7 0x0000556c548e96c0 genBoxDeclare(Fortran::lower::AbstractConverter&, Fortran::lower::SymMap&, Fortran::semantics::Symbol const&, mlir::Value, llvm::ArrayRef<mlir::Value>, llvm::ArrayRef<mlir::Value>, llvm::ArrayRef<mlir::Value>, bool) ConvertVariable.cpp:0:0 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          13:  #8 0x0000556c548ea35e Fortran::lower::mapSymbolAttributes(Fortran::lower::AbstractConverter&, Fortran::lower::pft::Variable const&, Fortran::lower::SymMap&, Fortran::lower::StatementContext&, mlir::Value) (/local/home/psteinfeld/main/llvm-project/build/bin/bbc+0x156435e) 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          14:  #9 0x0000556c548eca7c Fortran::lower::instantiateVariable(Fortran::lower::AbstractConverter&, Fortran::lower::pft::Variable const&, Fortran::lower::SymMap&, llvm::DenseMap<std::tuple<Fortran::semantics::Scope const*, unsigned long>, mlir::Value, llvm::DenseMapInfo<std::tuple<Fortran::semantics::Scope const*, unsigned long>, void>, llvm::detail::DenseMapPair<std::tuple<Fortran::semantics::Scope const*, unsigned long>, mlir::Value>>&) (/local/home/psteinfeld/main/llvm-project/build/bin/bbc+0x1566a7c) 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          15: #10 0x0000556c54623c6c (anonymous namespace)::FirConverter::instantiateVar(Fortran::lower::pft::Variable const&, llvm::DenseMap<std::tuple<Fortran::semantics::Scope const*, unsigned long>, mlir::Value, llvm::DenseMapInfo<std::tuple<Fortran::semantics::Scope const*, unsigned long>, void>, llvm::detail::DenseMapPair<std::tuple<Fortran::semantics::Scope const*, unsigned long>, mlir::Value>>&) Bridge.cpp:0:0 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          16: #11 0x0000556c5465d0c8 (anonymous namespace)::FirConverter::startNewFunction(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:6'1                                                                   ?                                                                      possible intended match
          17: #12 0x0000556c5465e06e (anonymous namespace)::FirConverter::lowerFunc(Fortran::lower::pft::FunctionLikeUnit&) Bridge.cpp:0:0 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          18: #13 0x0000556c54653f17 Fortran::lower::LoweringBridge::lower(Fortran::parser::Program const&, Fortran::semantics::SemanticsContext const&) (/local/home/psteinfeld/main/llvm-project/build/bin/bbc+0x12cdf17) 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          19: #14 0x0000556c53533e93 main (/local/home/psteinfeld/main/llvm-project/build/bin/bbc+0x1ade93) 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          20: #15 0x00007f9e23f51493 __libc_start_main (/lib64/libc.so.6+0x23493) 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          21: #16 0x0000556c535457ee _start (/local/home/psteinfeld/main/llvm-project/build/bin/bbc+0x1bf7ee) 
check:6'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>>>

--

Copy link
Contributor

@clementval clementval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jeanPerier
Copy link
Contributor Author

When I build and run tests, I get an assertion. Here's the relevant excerpt from the log file:

Thanks Pete, I could reproduce and added a fix. There was an assert that was not valid anymore and some more work on the callee side since lowering code is not meant to track scalar characters as descriptors.

@psteinfeld
Copy link
Contributor

When I build and run tests, I get an assertion. Here's the relevant excerpt from the log file:

Thanks Pete, I could reproduce and added a fix. There was an assert that was not valid anymore and some more work on the callee side since lowering code is not meant to track scalar characters as descriptors.

Thanks, Jean. All looks good now.

Outside of BIND(C), assumed length character scalar and explicit shape
are passed by address + an extra length argument (fir.boxchar in FIR).

The standard mandates that they be passed via CFI descriptor in
BIND(C) interface (fir.box in FIR). This patch fix the handling for
this case.
Lowering hit and assert with the previous patch because it is not meant
to manipulate scalars characters as fir.box.

Add the code to open the fir.box of BIND(C) characters on the callee
side, taking care of dealing with the case where the fir.box is optional
and cannot be addressed unconditionally.
@jeanPerier jeanPerier merged commit 5b6f3fc into llvm:main Sep 12, 2023
1 of 2 checks passed
@jeanPerier jeanPerier deleted the jpr-character-bind-c branch September 12, 2023 07:38
Copy link
Contributor

@psteinfeld psteinfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All builds and tests correctly and looks good.

ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
Outside of BIND(C), assumed length character scalar and explicit shape
are passed by address + an extra length argument (fir.boxchar in FIR).

The standard mandates that they be passed via CFI descriptor in BIND(C)
interface (fir.box in FIR). This patch fix the handling for this case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants