Skip to content

Commit

Permalink
[flang] Embox argument for assumed type dummy argument to !fir.box<none>
Browse files Browse the repository at this point in the history
When passing an argument to an assumed type dummy argument, embox
it directly to a !fir.box<none> box.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D146207
  • Loading branch information
clementval committed Mar 16, 2023
1 parent c3a6bea commit b52e974
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion flang/include/flang/Optimizer/Builder/FIRBuilder.h
Expand Up @@ -336,7 +336,7 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
/// Array entities are boxed with a shape and possibly a shift. Character
/// entities are boxed with a LEN parameter.
mlir::Value createBox(mlir::Location loc, const fir::ExtendedValue &exv,
bool isPolymorphic = false);
bool isPolymorphic = false, bool isAssumedType = false);

mlir::Value createBox(mlir::Location loc, mlir::Type boxType,
mlir::Value addr, mlir::Value shape, mlir::Value slice,
Expand Down
10 changes: 5 additions & 5 deletions flang/lib/Lower/ConvertExpr.cpp
Expand Up @@ -2714,12 +2714,13 @@ class ScalarExprLowering {
// actually a variable.
box = Fortran::evaluate::IsVariable(*expr)
? builder.createBox(loc, genBoxArg(*expr),
fir::isPolymorphicType(argTy))
fir::isPolymorphicType(argTy),
fir::isBoxNone(argTy))
: builder.createBox(getLoc(), genTempExtAddr(*expr),
fir::isPolymorphicType(argTy));

fir::isPolymorphicType(argTy),
fir::isBoxNone(argTy));
if (box.getType().isa<fir::BoxType>() &&
fir::isPolymorphicType(argTy)) {
fir::isPolymorphicType(argTy) && !fir::isBoxNone(argTy)) {
mlir::Type actualTy = argTy;
if (Fortran::lower::isParentComponent(*expr))
actualTy = fir::BoxType::get(converter.genType(*expr));
Expand Down Expand Up @@ -2758,7 +2759,6 @@ class ScalarExprLowering {
box = fir::getBase(newExv);
}
}

caller.placeInput(arg, box);
}
} else if (arg.passBy == PassBy::AddressAndLength) {
Expand Down
8 changes: 6 additions & 2 deletions flang/lib/Optimizer/Builder/FIRBuilder.cpp
Expand Up @@ -506,7 +506,8 @@ mlir::Value fir::FirOpBuilder::createSlice(mlir::Location loc,

mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc,
const fir::ExtendedValue &exv,
bool isPolymorphic) {
bool isPolymorphic,
bool isAssumedType) {
mlir::Value itemAddr = fir::getBase(exv);
if (itemAddr.getType().isa<fir::BaseBoxType>())
return itemAddr;
Expand All @@ -525,7 +526,10 @@ mlir::Value fir::FirOpBuilder::createBox(mlir::Location loc,
boxTy = fir::BoxType::get(elementType);
if (isPolymorphic) {
elementType = fir::updateTypeForUnlimitedPolymorphic(elementType);
boxTy = fir::ClassType::get(elementType);
if (isAssumedType)
boxTy = fir::BoxType::get(elementType);
else
boxTy = fir::ClassType::get(elementType);
}
}

Expand Down
23 changes: 23 additions & 0 deletions flang/test/Lower/assumed-type.f90
@@ -0,0 +1,23 @@
! RUN: bbc -polymorphic-type -emit-fir %s -o - | FileCheck %s

module assumed_type_test

interface
subroutine assumed(a)
type(*), intent(in), target :: a
end subroutine
end interface

contains

subroutine call_assmued()
integer, target :: i
call assumed(i)
end subroutine

! CHECK-LABEL: func.func @_QMassumed_type_testPcall_assmued() {
! CHECK: %[[I:.*]] = fir.alloca i32 {bindc_name = "i", fir.target, uniq_name = "_QMassumed_type_testFcall_assmuedEi"}
! CHECK: %[[BOX_NONE:.*]] = fir.embox %[[I]] : (!fir.ref<i32>) -> !fir.box<none>
! CHECK: fir.call @_QPassumed(%[[BOX_NONE]]) fastmath<contract> : (!fir.box<none>) -> ()

end module

0 comments on commit b52e974

Please sign in to comment.