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] Make adapt.valuebyref attribute work again #73658

Merged
merged 4 commits into from
Nov 29, 2023

Conversation

Leporacanthicus
Copy link
Contributor

This got "lost" in the HLFIR transformation. This patch applies the old attribute to the AssociateOp that needs it, and forwards it to the AllocaOp that is generated when lowering to FIR.

This got "lost" in the HLFIR transformation. This patch applies
the old attribute to the AssociateOp that needs it, and forwards
it to the AllocaOp that is generated when lowering to FIR.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir labels Nov 28, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 28, 2023

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-fir-hlfir

Author: Mats Petersson (Leporacanthicus)

Changes

This got "lost" in the HLFIR transformation. This patch applies the old attribute to the AssociateOp that needs it, and forwards it to the AllocaOp that is generated when lowering to FIR.


Patch is 69.99 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/73658.diff

36 Files Affected:

  • (modified) flang/include/flang/Lower/HlfirIntrinsics.h (+3-2)
  • (modified) flang/include/flang/Optimizer/Builder/HLFIRTools.h (+2-1)
  • (modified) flang/include/flang/Optimizer/HLFIR/HLFIROps.td (+2-2)
  • (modified) flang/lib/Lower/ConvertCall.cpp (+12-6)
  • (modified) flang/lib/Optimizer/Builder/HLFIRTools.cpp (+18-12)
  • (modified) flang/lib/Optimizer/Builder/TemporaryStorage.cpp (+2-1)
  • (modified) flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp (+3-1)
  • (modified) flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp (+11-3)
  • (modified) flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp (+2-1)
  • (modified) flang/test/HLFIR/associate-codegen.fir (+7-7)
  • (modified) flang/test/HLFIR/call_with_poly_dummy.f90 (+2-2)
  • (modified) flang/test/HLFIR/extents-of-shape-of.f90 (+1-1)
  • (modified) flang/test/HLFIR/mul_transpose.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/array-ctor-as-elemental-nested.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/array-ctor-as-elemental.f90 (+5-5)
  • (modified) flang/test/Lower/HLFIR/array-ctor-as-inlined-temp.f90 (+3-3)
  • (modified) flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/associate-for-args-with-alloc-components.f90 (+3-3)
  • (modified) flang/test/Lower/HLFIR/calls-assumed-shape.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/calls-constant-expr-arg-polymorphic.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/calls-constant-expr-arg.f90 (+2-2)
  • (modified) flang/test/Lower/HLFIR/calls-f77.f90 (+5-5)
  • (modified) flang/test/Lower/HLFIR/calls-optional.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/charconvert.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/cray-pointers.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/elemental-array-ops.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/elemental-call-vector-subscripts.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/elemental-user-procedure-ref-polymorphic.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/entry_return.f90 (+4-4)
  • (modified) flang/test/Lower/HLFIR/expr-addr.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/poly_expr_for_nonpoly_dummy.f90 (+2-2)
  • (modified) flang/test/Lower/HLFIR/polymorphic-expressions.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/transformational.f90 (+1-1)
  • (modified) flang/test/Lower/HLFIR/user-defined-assignment.f90 (+4-4)
  • (modified) flang/test/Lower/HLFIR/vector-subscript-as-value.f90 (+1-1)
  • (modified) flang/test/Lower/Intrinsics/storage_size-2.f90 (+1-1)
diff --git a/flang/include/flang/Lower/HlfirIntrinsics.h b/flang/include/flang/Lower/HlfirIntrinsics.h
index 088f8bccef4aa1b..74adb56ca81f293 100644
--- a/flang/include/flang/Lower/HlfirIntrinsics.h
+++ b/flang/include/flang/Lower/HlfirIntrinsics.h
@@ -76,8 +76,9 @@ struct PreparedActualArgument {
     if (auto *actualEntity = std::get_if<hlfir::Entity>(&actual)) {
       if (!actualEntity->isVariable() && actualEntity->isArray()) {
         mlir::Type storageType = actualEntity->getType();
-        hlfir::AssociateOp associate = hlfir::genAssociateExpr(
-            loc, builder, *actualEntity, storageType, "adapt.impure_arg_eval");
+        hlfir::AssociateOp associate =
+            hlfir::genAssociateExpr(loc, builder, *actualEntity, storageType,
+                                    "adapt.impure_arg_eval", std::nullopt);
         actual = hlfir::Entity{associate};
         return associate;
       }
diff --git a/flang/include/flang/Optimizer/Builder/HLFIRTools.h b/flang/include/flang/Optimizer/Builder/HLFIRTools.h
index 999ac9c7a42fad2..84e29076d839069 100644
--- a/flang/include/flang/Optimizer/Builder/HLFIRTools.h
+++ b/flang/include/flang/Optimizer/Builder/HLFIRTools.h
@@ -243,7 +243,8 @@ hlfir::AssociateOp genAssociateExpr(mlir::Location loc,
                                     fir::FirOpBuilder &builder,
                                     hlfir::Entity value,
                                     mlir::Type variableType,
-                                    llvm::StringRef name);
+                                    llvm::StringRef name,
+                                    std::optional<mlir::NamedAttribute> attr);
 
 /// Get the raw address of a variable (simple fir.ref/fir.ptr, or fir.heap
 /// value). The returned value should be used with care, it does not contain any
diff --git a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td
index 9fbf09331c099c0..f2b91871da47296 100644
--- a/flang/include/flang/Optimizer/HLFIR/HLFIROps.td
+++ b/flang/include/flang/Optimizer/HLFIR/HLFIROps.td
@@ -660,7 +660,7 @@ def hlfir_AssociateOp : hlfir_Op<"associate", [AttrSizedOperandSegments,
     AnyFortranValue:$source,
     Optional<AnyShapeOrShiftType>:$shape,
     Variadic<AnyIntegerType>:$typeparams,
-    Builtin_StringAttr:$uniq_name,
+    OptionalAttr<Builtin_StringAttr>:$uniq_name,
     OptionalAttr<fir_FortranVariableFlagsAttr>:$fortran_attrs
   );
 
@@ -672,7 +672,7 @@ def hlfir_AssociateOp : hlfir_Op<"associate", [AttrSizedOperandSegments,
   }];
 
   let builders = [
-    OpBuilder<(ins "mlir::Value":$source, "llvm::StringRef":$uniq_name,
+    OpBuilder<(ins "mlir::Value":$source, CArg<"llvm::StringRef", "{}">:$uniq_name,
       CArg<"mlir::Value", "{}">:$shape, CArg<"mlir::ValueRange", "{}">:$typeparams,
       CArg<"fir::FortranVariableFlagsAttr", "{}">:$fortran_attrs)>];
 
diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp
index 395a98b43d53793..8dc3cf1fe2643b7 100644
--- a/flang/lib/Lower/ConvertCall.cpp
+++ b/flang/lib/Lower/ConvertCall.cpp
@@ -12,6 +12,7 @@
 
 #include "flang/Lower/ConvertCall.h"
 #include "flang/Lower/Allocatable.h"
+#include "flang/Lower/ConvertExpr.h"
 #include "flang/Lower/ConvertExprToHLFIR.h"
 #include "flang/Lower/ConvertVariable.h"
 #include "flang/Lower/CustomIntrinsicCall.h"
@@ -559,8 +560,9 @@ static hlfir::EntityWithAttributes genStmtFunctionRef(
       // Create an hlfir.associate to create a variable from a potential
       // value argument.
       mlir::Type argType = converter.genType(*arg);
-      auto associate = hlfir::genAssociateExpr(
-          loc, builder, loweredArg, argType, toStringRef(arg->name()));
+      auto associate =
+          hlfir::genAssociateExpr(loc, builder, loweredArg, argType,
+                                  toStringRef(arg->name()), std::nullopt);
       exprAssociations.push_back(associate);
       variableIface = associate;
     }
@@ -958,8 +960,10 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
       // Make a copy in a temporary.
       auto copy = builder.create<hlfir::AsExprOp>(loc, entity);
       mlir::Type storageType = entity.getType();
+      mlir::NamedAttribute byRefAttr =
+          Fortran::lower::getAdaptToByRefAttr(builder);
       hlfir::AssociateOp associate = hlfir::genAssociateExpr(
-          loc, builder, hlfir::Entity{copy}, storageType, "adapt.valuebyref");
+          loc, builder, hlfir::Entity{copy}, storageType, "", byRefAttr);
       entity = hlfir::Entity{associate.getBase()};
       // Register the temporary destruction after the call.
       preparedDummy.pushExprAssociateCleanUp(associate);
@@ -986,8 +990,10 @@ static PreparedDummyArgument preparePresentUserCallActualArgument(
     // The actual is an expression value, place it into a temporary
     // and register the temporary destruction after the call.
     mlir::Type storageType = converter.genType(expr);
+    mlir::NamedAttribute byRefAttr =
+        Fortran::lower::getAdaptToByRefAttr(builder);
     hlfir::AssociateOp associate = hlfir::genAssociateExpr(
-        loc, builder, entity, storageType, "adapt.valuebyref");
+        loc, builder, entity, storageType, "", byRefAttr);
     entity = hlfir::Entity{associate.getBase()};
     preparedDummy.pushExprAssociateCleanUp(associate);
     if (mustSetDynamicTypeToDummyType) {
@@ -1175,8 +1181,8 @@ genUserCall(Fortran::lower::PreparedActualArguments &loweredActuals,
         // Pass-by-value argument of type(C_PTR/C_FUNPTR).
         // Load the __address component and pass it by value.
         if (value.isValue()) {
-          auto associate = hlfir::genAssociateExpr(loc, builder, value, eleTy,
-                                                   "adapt.cptrbyval");
+          auto associate = hlfir::genAssociateExpr(
+              loc, builder, value, eleTy, "adapt.cptrbyval", std::nullopt);
           value = hlfir::Entity{genRecordCPtrValueArg(
               builder, loc, associate.getFirBase(), eleTy)};
           builder.create<hlfir::EndAssociateOp>(loc, associate);
diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
index 88d3f15deb9b3b8..80cfb79600827bd 100644
--- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp
+++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "flang/Optimizer/Builder/HLFIRTools.h"
+#include "flang/Lower/ConvertExpr.h"
 #include "flang/Optimizer/Builder/Character.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/MutableBox.h"
@@ -232,11 +233,11 @@ hlfir::genDeclare(mlir::Location loc, fir::FirOpBuilder &builder,
   return mlir::cast<fir::FortranVariableOpInterface>(declareOp.getOperation());
 }
 
-hlfir::AssociateOp hlfir::genAssociateExpr(mlir::Location loc,
-                                           fir::FirOpBuilder &builder,
-                                           hlfir::Entity value,
-                                           mlir::Type variableType,
-                                           llvm::StringRef name) {
+hlfir::AssociateOp
+hlfir::genAssociateExpr(mlir::Location loc, fir::FirOpBuilder &builder,
+                        hlfir::Entity value, mlir::Type variableType,
+                        llvm::StringRef name,
+                        std::optional<mlir::NamedAttribute> attr) {
   assert(value.isValue() && "must not be a variable");
   mlir::Value shape{};
   if (value.isArray())
@@ -259,8 +260,11 @@ hlfir::AssociateOp hlfir::genAssociateExpr(mlir::Location loc,
   }
   llvm::SmallVector<mlir::Value> lenParams;
   genLengthParameters(loc, builder, value, lenParams);
-  return builder.create<hlfir::AssociateOp>(loc, source, name, shape, lenParams,
-                                            fir::FortranVariableFlagsAttr{});
+  auto res = builder.create<hlfir::AssociateOp>(
+      loc, source, name, shape, lenParams, fir::FortranVariableFlagsAttr{});
+  if (attr)
+    res->setAttrs({*attr});
+  return res;
 }
 
 mlir::Value hlfir::genVariableRawAddress(mlir::Location loc,
@@ -914,8 +918,10 @@ hlfir::translateToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder,
   }
 
   if (entity.getType().isa<hlfir::ExprType>()) {
+    mlir::NamedAttribute byRefAttr =
+        Fortran::lower::getAdaptToByRefAttr(builder);
     hlfir::AssociateOp associate = hlfir::genAssociateExpr(
-        loc, builder, entity, entity.getType(), "adapt.valuebyref");
+        loc, builder, entity, entity.getType(), "", byRefAttr);
     auto *bldr = &builder;
     hlfir::CleanupFunction cleanup = [bldr, loc, associate]() -> void {
       bldr->create<hlfir::EndAssociateOp>(loc, associate);
@@ -1160,9 +1166,9 @@ hlfir::genTypeAndKindConvert(mlir::Location loc, fir::FirOpBuilder &builder,
                             /*isUnordered=*/true);
 
   if (preserveLowerBounds && source.hasNonDefaultLowerBounds()) {
-    hlfir::AssociateOp associate =
-        genAssociateExpr(loc, builder, hlfir::Entity{convertedRhs},
-                         convertedRhs.getType(), ".tmp.keeplbounds");
+    hlfir::AssociateOp associate = genAssociateExpr(
+        loc, builder, hlfir::Entity{convertedRhs}, convertedRhs.getType(),
+        ".tmp.keeplbounds", std::nullopt);
     fir::ShapeOp shapeOp = associate.getShape().getDefiningOp<fir::ShapeOp>();
     assert(shapeOp && "associate shape must be a fir.shape");
     const unsigned rank = shapeOp.getExtents().size();
@@ -1175,7 +1181,7 @@ hlfir::genTypeAndKindConvert(mlir::Location loc, fir::FirOpBuilder &builder,
     mlir::Value shapeShift =
         builder.create<fir::ShapeShiftOp>(loc, shapeShiftType, lbAndExtents);
     auto declareOp = builder.create<hlfir::DeclareOp>(
-        loc, associate.getFirBase(), associate.getUniqName(), shapeShift,
+        loc, associate.getFirBase(), *associate.getUniqName(), shapeShift,
         associate.getTypeparams(), /*flags=*/fir::FortranVariableFlagsAttr{});
     hlfir::Entity castWithLbounds =
         mlir::cast<fir::FortranVariableOpInterface>(declareOp.getOperation());
diff --git a/flang/lib/Optimizer/Builder/TemporaryStorage.cpp b/flang/lib/Optimizer/Builder/TemporaryStorage.cpp
index dbc285ce9e22d5a..0efad4648be3847 100644
--- a/flang/lib/Optimizer/Builder/TemporaryStorage.cpp
+++ b/flang/lib/Optimizer/Builder/TemporaryStorage.cpp
@@ -148,7 +148,8 @@ fir::factory::SimpleCopy::SimpleCopy(mlir::Location loc,
   if (source.isVariable())
     source = hlfir::Entity{builder.create<hlfir::AsExprOp>(loc, source)};
   copy = hlfir::genAssociateExpr(loc, builder, source,
-                                 source.getFortranElementType(), tempName);
+                                 source.getFortranElementType(), tempName,
+                                 std::nullopt);
 }
 
 void fir::factory::SimpleCopy::destroy(mlir::Location loc,
diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
index ab648b2909c33ad..7dc57c4c44478d2 100644
--- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
+++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
@@ -1212,7 +1212,9 @@ void hlfir::AssociateOp::build(mlir::OpBuilder &builder,
                                llvm::StringRef uniq_name, mlir::Value shape,
                                mlir::ValueRange typeparams,
                                fir::FortranVariableFlagsAttr fortran_attrs) {
-  auto nameAttr = builder.getStringAttr(uniq_name);
+  mlir::StringAttr nameAttr;
+  if (!uniq_name.empty())
+    nameAttr = builder.getStringAttr(uniq_name);
   mlir::Type dataType = getFortranElementOrSequenceType(source.getType());
 
   // Preserve polymorphism of polymorphic expr.
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
index 3da8666d7c53f70..759d6be00caeb4b 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
@@ -12,6 +12,7 @@
 // on the heap.
 //===----------------------------------------------------------------------===//
 
+#include "flang/Lower/ConvertExpr.h"
 #include "flang/Optimizer/Builder/Character.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Optimizer/Builder/HLFIRTools.h"
@@ -452,7 +453,7 @@ struct AssociateOpConversion
       //   %0 = hlfir.as_expr %x move %true :
       //       (!fir.box<!fir.heap<!fir.type<_T{y:i32}>>>, i1) ->
       //       !hlfir.expr<!fir.type<_T{y:i32}>>
-      //   %1:3 = hlfir.associate %0 {uniq_name = "adapt.valuebyref"} :
+      //   %1:3 = hlfir.associate %0 {adapt.valuebyref} :
       //       (!hlfir.expr<!fir.type<_T{y:i32}>>) ->
       //       (!fir.ref<!fir.type<_T{y:i32}>>,
       //        !fir.ref<!fir.type<_T{y:i32}>>,
@@ -525,8 +526,15 @@ struct AssociateOpConversion
       return mlir::success();
     }
     if (isTrivialValue) {
-      auto temp = builder.createTemporary(loc, bufferizedExpr.getType(),
-                                          associate.getUniqName());
+      llvm::SmallVector<mlir::NamedAttribute, 1> attrs;
+      if (associate->hasAttr(fir::getAdaptToByRefAttrName())) {
+        attrs.push_back(Fortran::lower::getAdaptToByRefAttr(builder));
+      }
+      llvm::StringRef name = "";
+      if (associate.getUniqName())
+        name = *associate.getUniqName();
+      auto temp =
+          builder.createTemporary(loc, bufferizedExpr.getType(), name, attrs);
       builder.create<fir::StoreOp>(loc, bufferizedExpr, temp);
       mlir::Value mustFree = builder.createBool(loc, false);
       replaceWith(temp, temp, mustFree);
diff --git a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
index c4aee7d39e4a3c5..72c7cdfdef87ce5 100644
--- a/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
+++ b/flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
@@ -414,7 +414,8 @@ convertToMoldType(mlir::Location loc, fir::FirOpBuilder &builder,
   if (input.isValue() && mold.isVariable()) {
     // T to fir.ref<T>, or hlfir.expr<T> to fir.ref<T>.
     hlfir::AssociateOp associate = hlfir::genAssociateExpr(
-        loc, builder, input, mold.getFortranElementType(), ".tmp.val2ref");
+        loc, builder, input, mold.getFortranElementType(), ".tmp.val2ref",
+        std::nullopt);
     cleanups.emplace_back(
         [=]() { b->create<hlfir::EndAssociateOp>(loc, associate); });
     return hlfir::Entity{associate.getBase()};
diff --git a/flang/test/HLFIR/associate-codegen.fir b/flang/test/HLFIR/associate-codegen.fir
index 4cd50af27ebe04f..f5e015c4169f600 100644
--- a/flang/test/HLFIR/associate-codegen.fir
+++ b/flang/test/HLFIR/associate-codegen.fir
@@ -178,7 +178,7 @@ func.func @test_0dim_box(%x : !fir.ref<!fir.box<!fir.heap<i32>>>) {
   %1:2 = hlfir.declare %0 {uniq_name = ".tmp.intrinsic_result"} : (!fir.box<!fir.heap<i32>>) -> (!fir.box<!fir.heap<i32>>, !fir.box<!fir.heap<i32>>)
   %true = arith.constant true
   %2 = hlfir.as_expr %1#0 move %true : (!fir.box<!fir.heap<i32>>, i1) -> !hlfir.expr<i32>
-  %3:3 = hlfir.associate %2 {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<i32>) -> (!fir.ref<i32>, !fir.ref<i32>, i1)
+  %3:3 = hlfir.associate %2 {adapt.valuebyref} : (!hlfir.expr<i32>) -> (!fir.ref<i32>, !fir.ref<i32>, i1)
   return
 }
 // CHECK-LABEL:   func.func @test_0dim_box(
@@ -207,7 +207,7 @@ func.func @test_shape_of(%arg0: !fir.ref<!fir.array<4x3xi32>>) {
     hlfir.yield_element %5 : i32
   }
   %1 = hlfir.shape_of %0 : (!hlfir.expr<3x4xi32>) -> !fir.shape<2>
-  %2:3 = hlfir.associate %0(%1) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<3x4xi32>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x4xi32>>, !fir.ref<!fir.array<3x4xi32>>, i1)
+  %2:3 = hlfir.associate %0(%1) {adapt.valuebyref} : (!hlfir.expr<3x4xi32>, !fir.shape<2>) -> (!fir.ref<!fir.array<3x4xi32>>, !fir.ref<!fir.array<3x4xi32>>, i1)
   // ...
   hlfir.end_associate %2#1, %2#2 : !fir.ref<!fir.array<3x4xi32>>, i1
   return
@@ -294,7 +294,7 @@ func.func @test_get_length(%arg0: !fir.ref<!fir.char<1,2>>) {
   %0 = hlfir.as_expr %arg0 : (!fir.ref<!fir.char<1,2>>) -> !hlfir.expr<!fir.char<1,2>>
   %1 = hlfir.get_length %0 : (!hlfir.expr<!fir.char<1,2>>)  -> index
   %c2 = arith.constant 2 : index
-  %2:3 = hlfir.associate %0 typeparams %c2 {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<!fir.char<1,2>>, index) -> (!fir.ref<!fir.char<1,2>>, !fir.ref<!fir.char<1,2>>, i1)
+  %2:3 = hlfir.associate %0 typeparams %c2 {adapt.valuebyref} : (!hlfir.expr<!fir.char<1,2>>, index) -> (!fir.ref<!fir.char<1,2>>, !fir.ref<!fir.char<1,2>>, i1)
   // ...
   hlfir.end_associate %2#1, %2#2 : !fir.ref<!fir.char<1,2>>, i1
   return
@@ -331,7 +331,7 @@ func.func @_QPtest_multiple_expr_uses_inside_elemental() {
   %22 = fir.shape %21 : (index) -> !fir.shape<1>
   %23 = hlfir.elemental %22 unordered : (!fir.shape<1>) -> !hlfir.expr<?x!fir.logical<4>> {
   ^bb0(%arg2: index):
-    %35:3 = hlfir.associate %20 typeparams %17 {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>, i1)
+    %35:3 = hlfir.associate %20 typeparams %17 {adapt.valuebyref} : (!hlfir.expr<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>, i1)
     hlfir.end_associate %35#1, %35#2 : !fir.ref<!fir.char<1,?>>, i1
     %ci1 = arith.constant 1 : i1
     %42 = fir.convert %ci1 : (i1) -> !fir.logical<4>
@@ -383,9 +383,9 @@ func.func @_QPtest_multitple_associates_for_same_expr() {
     %44 = fir.undefined !fir.ref<!fir.char<1>>
     hlfir.yield_element %44 : !fir.ref<!fir.char<1>>
   }
-  %12:3 = hlfir.associate %11(%4) typeparams %c1 {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<10x!fir.char<1>>, !fir.shape<1>, index) -> (!fir.ref<!fir.array<10x!fir.char<1>>>, !fir.ref<!fir.array<10x!fir.char<1>>>, i1)
+  %12:3 = hlfir.associate %11(%4) typeparams %c1 {adapt.valuebyref} : (!hlfir.expr<10x!fir.char<1>>, !fir.shape<1>, index) -> (!fir.ref<!fir.array<10x!fir.char<1>>>, !fir.ref<!fir.array<10x!fir.char<1>>>, i1)
   hlfir.end_associate %12#1, %12#2 : !fir.ref<!fir.array<10x!fir.char<1>>>, i1
-  %31:3 = hlfir.associate %11(%4) typeparams %c1 {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<10x!fir.char<1>>, !fir.shape<1>, index) -> (!fir.ref<!fir.array<10x!fir.char<1>>>, !fir.ref<!fir.array<10x!fir.char<1>>>, i1)
+  %31:3 = hlfir.associate %11(%4) typeparams %c1 {adapt.valuebyref} : (!hlfir.expr<10x!fir.char<1>>, !fir.shape<1>, index) -> (!fir.ref<!fir.array<10x!fir.char<1>>>, !fir.ref<!fir.array<10x!fir.char<1>>>, i1)
   hlfir.end_associate %31#1, %31#2 : !fir.ref<!fir.array<10x!fir.char<1>>>, i1
   hlfir.destroy %11 : !hlfir.expr<10x!fir.char<1>>
   return
@@ -444,7 +444,7 @@ func.func @_QPtest(%arg0: index, %arg1: index, %arg2 : i32) {
     hlfir.yield_element %16 : i32
   }
   %5 = hlfir.shape_of %4 : (!hlfir.expr<?x?xi32>) -> !fir.shape<2>
-  %6:3 = hlfir.associate %4(%5) {uniq_name = "adapt.valuebyref"} : (!hlfir.expr<?x?xi32>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xi32>>, !fir.ref<!fir.array<?x?xi32>>, i1)
+  %6:3 = hlfir.associate %4(%5) {adapt.valuebyref} : (!hlfir.expr<?x?xi32>, !fir.shape<2>) -> (!fir.box<!fir.array<?x?xi32>>, !fir.ref<!fir.array<?x?xi32>>, i1)
   %13 = arith.cmpi ne, %arg2, %c1_i32 : i32
   cf.cond_br %13, ^bb1, ^bb2
 ^bb1:  // pred: ^bb0
diff --git a/flang/test/HLFIR/call_with_poly_dummy.f90 b/flang/test/HLFIR/call_with_poly_dummy.f90
index 2dc29f86fdf328b..c4b98fbe5f55785 100644
--- a/flang/test/HLFIR/call_with_poly_dummy.f90
+++ b/flang/test/HLFIR/call_with_poly_dummy.f90
@@ -4,7 +4,7 @@
 
 ! CHECK-LABEL:   func.func @_QPtest1() {
 ! CHECK:           %[[VAL_0:.*]] = arith.constant 17 : i32
-! CHECK:           %[[VAL_1:.*]]:3 = hlfir.associate %[[VAL_0]] {uniq_name = "adapt.valuebyref"} : (i32) -> (!fir.ref<i32>, !fir.ref<i32>, i1)
+! CHECK:           %[[VAL_1:.*]]:3 = hlfir.associate %[[VAL_0]] {adapt.valuebyref} : (i32) -> (!fir.ref<i32>, !fir.ref<i32>, i1)
 ! CHECK:           %[[VAL_2:.*]] = fir.embox %[[VAL_1]]#0 : (!fir.ref<i32>) -> !fir.box<i32>
 ! CHECK:           %[[VAL_3:.*]] = fir.rebox %[[VAL_2]] : (!fir.box<i32>) -> !fir.class<none>
 ! CHECK:           fir.call @_QPcallee(%[[VAL_3]]) fastmath<contract> : (!fir.class<none>) -> ()
@@ -27,7 +27,7 @@ end subroutine test1
 ! CHECK:           %[[VAL_3:.*]] = arith.constant 0.000000e+00 : f...
[truncated]

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

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

Thanks for finding and fixing this! Some minor coments

flang/include/flang/Optimizer/Builder/HLFIRTools.h Outdated Show resolved Hide resolved
flang/lib/Optimizer/Builder/HLFIRTools.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

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

Thanks

Copy link

github-actions bot commented Nov 29, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

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

Thanks for the update

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

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

Thanks

@Leporacanthicus Leporacanthicus merged commit 0ccef6a into llvm:main Nov 29, 2023
3 checks passed
jeanPerier added a commit to jeanPerier/llvm-project that referenced this pull request Nov 30, 2023
Added by mistake in llvm#73658.
Not needed and breaks shared library builds.
jeanPerier added a commit that referenced this pull request Nov 30, 2023
Added by mistake in #73658.
Not needed and breaks shared library builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:openmp 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