[flang-commits] [flang] [llvm] [flang] Enhance show_descriptor intrinsic to avoid extra copies and extra descriptor creation (PR #173461)

via flang-commits flang-commits at lists.llvm.org
Mon Jan 5 06:34:55 PST 2026


================
@@ -7893,9 +7893,29 @@ void IntrinsicLibrary::genShowDescriptor(
   assert(args.size() == 1 && "expected single argument for show_descriptor");
   const mlir::Value descriptor = fir::getBase(args[0]);
 
-  assert(fir::isa_box_type(descriptor.getType()) &&
-         "argument must have been lowered to box type");
-  fir::runtime::genShowDescriptor(builder, loc, descriptor);
+  // Use consistent !fir.ref<!fir.box<none>> argument type
+  auto targetType = fir::BoxType::get(builder.getNoneType());
+  auto targetRefType = fir::ReferenceType::get(targetType);
+
+  // If it's already a reference to a box, convert it to correct type and
+  // pass it directly
+  if (fir::isa_ref_type(descriptor.getType()) &&
+      fir::isa_box_type(fir::unwrapRefType(descriptor.getType()))) {
----------------
jeanPerier wrote:

```suggestion
  if (fir::isBoxAddress(descriptor.getType())) {
```

https://github.com/llvm/llvm-project/pull/173461


More information about the flang-commits mailing list