Skip to content

[Flang] Fix PowerPC build failure due to the deprecation of ArrayRef(std::nullopt_t) {}. #147816

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DanielCChen
Copy link
Contributor

@DanielCChen DanielCChen commented Jul 9, 2025

Our local Flang build on PowerPC was broken as

llvm/flang/../mlir/include/mlir/IR/ValueRange.h:401:20: error: 'ArrayRef' is deprecated: Use {} or ArrayRef<T>() instead [-Werror,-Wdeprecated-declarations]
  401 |       : ValueRange(ArrayRef<Value>(std::forward<Arg>(arg))) {}
      |                    ^
llvm/flang/lib/Optimizer/CodeGen/CodeGen.cpp:2243:53: note: in instantiation of function template specialization 'mlir::ValueRange::ValueRange<const std::nullopt_t &, void>' requested here
 2243 |                              /*cstInteriorIndices=*/std::nullopt, fieldIndices,
      |                                                     ^
 llvm/include/llvm/ADT/ArrayRef.h:70:18: note: 'ArrayRef' has been explicitly marked deprecated here
   70 |     /*implicit*/ LLVM_DEPRECATED("Use {} or ArrayRef<T>() instead", "{}")
      |                  ^
llvm/include/llvm/Support/Compiler.h:244:50: note: expanded from macro 'LLVM_DEPRECATED'
  244 | #define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
      |                                                  ^
1 error generated.

This patch is to fix it.

@DanielCChen DanielCChen self-assigned this Jul 9, 2025
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:codegen labels Jul 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2025

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

Author: Daniel Chen (DanielCChen)

Changes

Our local Flang build was broken as

llvm/flang/../mlir/include/mlir/IR/ValueRange.h:401:20: error: 'ArrayRef' is deprecated: Use {} or ArrayRef&lt;T&gt;() instead [-Werror,-Wdeprecated-declarations]
  401 |       : ValueRange(ArrayRef&lt;Value&gt;(std::forward&lt;Arg&gt;(arg))) {}
      |                    ^
llvm/flang/lib/Optimizer/CodeGen/CodeGen.cpp:2243:53: note: in instantiation of function template specialization 'mlir::ValueRange::ValueRange&lt;const std::nullopt_t &amp;, void&gt;' requested here
 2243 |                              /*cstInteriorIndices=*/std::nullopt, fieldIndices,
      |                                                     ^
 llvm/include/llvm/ADT/ArrayRef.h:70:18: note: 'ArrayRef' has been explicitly marked deprecated here
   70 |     /*implicit*/ LLVM_DEPRECATED("Use {} or ArrayRef&lt;T&gt;() instead", "{}")
      |                  ^
llvm/include/llvm/Support/Compiler.h:244:50: note: expanded from macro 'LLVM_DEPRECATED'
  244 | #define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
      |                                                  ^
1 error generated.

This patch is to fix it.


Full diff: https://github.com/llvm/llvm-project/pull/147816.diff

2 Files Affected:

  • (modified) flang/lib/Optimizer/CodeGen/CodeGen.cpp (+10-8)
  • (modified) flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp (+5-3)
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 1bc981516e226..3bbc32f23bcfa 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -2239,17 +2239,18 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
         getSubcomponentIndices(rebox, rebox.getBox(), operands, fieldIndices);
       if (!rebox.getSubstr().empty())
         substringOffset = operands[rebox.getSubstrOperandIndex()];
-      base = genBoxOffsetGep(rewriter, loc, base, llvmBaseObjectType, zero,
-                             /*cstInteriorIndices=*/std::nullopt, fieldIndices,
-                             substringOffset);
+      base =
+          genBoxOffsetGep(rewriter, loc, base, llvmBaseObjectType, zero,
+                          /*cstInteriorIndices=*/llvm::ArrayRef<mlir::Value>(),
+                          fieldIndices, substringOffset);
     }
 
     if (rebox.getSlice().empty())
       // The array section is of the form array[%component][substring], keep
       // the input array extents and strides.
       return finalizeRebox(rebox, adaptor, destBoxTy, dest, base,
-                           /*lbounds*/ std::nullopt, inputExtents, inputStrides,
-                           rewriter);
+                           /*lbounds*/ llvm::ArrayRef<mlir::Value>(),
+                           inputExtents, inputStrides, rewriter);
 
     // The slice is of the form array(i:j:k)[%component]. Compute new extents
     // and strides.
@@ -2297,8 +2298,8 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
       }
     }
     return finalizeRebox(rebox, adaptor, destBoxTy, dest, base,
-                         /*lbounds*/ std::nullopt, slicedExtents, slicedStrides,
-                         rewriter);
+                         /*lbounds*/ llvm::ArrayRef<mlir::Value>(),
+                         slicedExtents, slicedStrides, rewriter);
   }
 
   /// Apply a new shape to the data described by a box given the base address,
@@ -3396,7 +3397,8 @@ static void genBrOp(A caseOp, mlir::Block *dest, std::optional<B> destOps,
   if (destOps)
     rewriter.replaceOpWithNewOp<mlir::LLVM::BrOp>(caseOp, *destOps, dest);
   else
-    rewriter.replaceOpWithNewOp<mlir::LLVM::BrOp>(caseOp, std::nullopt, dest);
+    rewriter.replaceOpWithNewOp<mlir::LLVM::BrOp>(
+        caseOp, llvm::ArrayRef<mlir::Value>(), dest);
 }
 
 static void genCaseLadderStep(mlir::Location loc, mlir::Value cmp,
diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
index d09d7d397e8b7..eca2c7f7c942f 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -107,9 +107,11 @@ class EmboxConversion : public mlir::OpRewritePattern<fir::EmboxOp> {
       shapeOpers.push_back(extVal);
     }
     auto xbox = rewriter.create<fir::cg::XEmboxOp>(
-        loc, embox.getType(), embox.getMemref(), shapeOpers, std::nullopt,
-        std::nullopt, std::nullopt, std::nullopt, embox.getTypeparams(),
-        embox.getSourceBox(), embox.getAllocatorIdxAttr());
+        loc, embox.getType(), embox.getMemref(), shapeOpers,
+        llvm::ArrayRef<mlir::Value>(), llvm::ArrayRef<mlir::Value>(),
+        llvm::ArrayRef<mlir::Value>(), llvm::ArrayRef<mlir::Value>(),
+        embox.getTypeparams(), embox.getSourceBox(),
+        embox.getAllocatorIdxAttr());
     LLVM_DEBUG(llvm::dbgs() << "rewriting " << embox << " to " << xbox << '\n');
     rewriter.replaceOp(embox, xbox.getOperation()->getResults());
     return mlir::success();

@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2025

@llvm/pr-subscribers-flang-codegen

Author: Daniel Chen (DanielCChen)

Changes

Our local Flang build was broken as

llvm/flang/../mlir/include/mlir/IR/ValueRange.h:401:20: error: 'ArrayRef' is deprecated: Use {} or ArrayRef&lt;T&gt;() instead [-Werror,-Wdeprecated-declarations]
  401 |       : ValueRange(ArrayRef&lt;Value&gt;(std::forward&lt;Arg&gt;(arg))) {}
      |                    ^
llvm/flang/lib/Optimizer/CodeGen/CodeGen.cpp:2243:53: note: in instantiation of function template specialization 'mlir::ValueRange::ValueRange&lt;const std::nullopt_t &amp;, void&gt;' requested here
 2243 |                              /*cstInteriorIndices=*/std::nullopt, fieldIndices,
      |                                                     ^
 llvm/include/llvm/ADT/ArrayRef.h:70:18: note: 'ArrayRef' has been explicitly marked deprecated here
   70 |     /*implicit*/ LLVM_DEPRECATED("Use {} or ArrayRef&lt;T&gt;() instead", "{}")
      |                  ^
llvm/include/llvm/Support/Compiler.h:244:50: note: expanded from macro 'LLVM_DEPRECATED'
  244 | #define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
      |                                                  ^
1 error generated.

This patch is to fix it.


Full diff: https://github.com/llvm/llvm-project/pull/147816.diff

2 Files Affected:

  • (modified) flang/lib/Optimizer/CodeGen/CodeGen.cpp (+10-8)
  • (modified) flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp (+5-3)
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 1bc981516e226..3bbc32f23bcfa 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -2239,17 +2239,18 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
         getSubcomponentIndices(rebox, rebox.getBox(), operands, fieldIndices);
       if (!rebox.getSubstr().empty())
         substringOffset = operands[rebox.getSubstrOperandIndex()];
-      base = genBoxOffsetGep(rewriter, loc, base, llvmBaseObjectType, zero,
-                             /*cstInteriorIndices=*/std::nullopt, fieldIndices,
-                             substringOffset);
+      base =
+          genBoxOffsetGep(rewriter, loc, base, llvmBaseObjectType, zero,
+                          /*cstInteriorIndices=*/llvm::ArrayRef<mlir::Value>(),
+                          fieldIndices, substringOffset);
     }
 
     if (rebox.getSlice().empty())
       // The array section is of the form array[%component][substring], keep
       // the input array extents and strides.
       return finalizeRebox(rebox, adaptor, destBoxTy, dest, base,
-                           /*lbounds*/ std::nullopt, inputExtents, inputStrides,
-                           rewriter);
+                           /*lbounds*/ llvm::ArrayRef<mlir::Value>(),
+                           inputExtents, inputStrides, rewriter);
 
     // The slice is of the form array(i:j:k)[%component]. Compute new extents
     // and strides.
@@ -2297,8 +2298,8 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
       }
     }
     return finalizeRebox(rebox, adaptor, destBoxTy, dest, base,
-                         /*lbounds*/ std::nullopt, slicedExtents, slicedStrides,
-                         rewriter);
+                         /*lbounds*/ llvm::ArrayRef<mlir::Value>(),
+                         slicedExtents, slicedStrides, rewriter);
   }
 
   /// Apply a new shape to the data described by a box given the base address,
@@ -3396,7 +3397,8 @@ static void genBrOp(A caseOp, mlir::Block *dest, std::optional<B> destOps,
   if (destOps)
     rewriter.replaceOpWithNewOp<mlir::LLVM::BrOp>(caseOp, *destOps, dest);
   else
-    rewriter.replaceOpWithNewOp<mlir::LLVM::BrOp>(caseOp, std::nullopt, dest);
+    rewriter.replaceOpWithNewOp<mlir::LLVM::BrOp>(
+        caseOp, llvm::ArrayRef<mlir::Value>(), dest);
 }
 
 static void genCaseLadderStep(mlir::Location loc, mlir::Value cmp,
diff --git a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
index d09d7d397e8b7..eca2c7f7c942f 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -107,9 +107,11 @@ class EmboxConversion : public mlir::OpRewritePattern<fir::EmboxOp> {
       shapeOpers.push_back(extVal);
     }
     auto xbox = rewriter.create<fir::cg::XEmboxOp>(
-        loc, embox.getType(), embox.getMemref(), shapeOpers, std::nullopt,
-        std::nullopt, std::nullopt, std::nullopt, embox.getTypeparams(),
-        embox.getSourceBox(), embox.getAllocatorIdxAttr());
+        loc, embox.getType(), embox.getMemref(), shapeOpers,
+        llvm::ArrayRef<mlir::Value>(), llvm::ArrayRef<mlir::Value>(),
+        llvm::ArrayRef<mlir::Value>(), llvm::ArrayRef<mlir::Value>(),
+        embox.getTypeparams(), embox.getSourceBox(),
+        embox.getAllocatorIdxAttr());
     LLVM_DEBUG(llvm::dbgs() << "rewriting " << embox << " to " << xbox << '\n');
     rewriter.replaceOp(embox, xbox.getOperation()->getResults());
     return mlir::success();

substringOffset);
base =
genBoxOffsetGep(rewriter, loc, base, llvmBaseObjectType, zero,
/*cstInteriorIndices=*/llvm::ArrayRef<mlir::Value>(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer {} vs llvm::ArrayRef<mlir::Value>() - do you see any benefit to use more verbose version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The more verbose version would provide a bit more typing information
The {} is more for initialization. That being said, I am OK to change to it if you think it fits better as it indeed more aligns with the original std::nullopt.

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is that we do not have too many entries of ArrayRef<mlir::Value>() or ArrayRef<mlir::Value>{} in Flang code, so probably {} is a more common style, and we should stick to it. But it is not a big deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will change to it.

@DanielCChen DanielCChen requested a review from madanial0 July 9, 2025 20:33
substringOffset);
base =
genBoxOffsetGep(rewriter, loc, base, llvmBaseObjectType, zero,
/*cstInteriorIndices=*/llvm::ArrayRef<mlir::Value>(),
Copy link
Contributor

Choose a reason for hiding this comment

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

My point is that we do not have too many entries of ArrayRef<mlir::Value>() or ArrayRef<mlir::Value>{} in Flang code, so probably {} is a more common style, and we should stick to it. But it is not a big deal.

Copy link
Contributor

@kazutakahirata kazutakahirata left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@DanielCChen
Copy link
Contributor Author

@vzakhari It seems {} doesn't work with parameter pack in a couple of places. Clang complains

candidate template ignored: substitution failure [with OpTy = fir::cg::XEmboxOp]: deduced incomplete pack <mlir::Type, ::mlir::TypedValue< ::mlir::Type>, llvm::SmallVector<mlir::Value> &, (no value), (no value), (no value), (no value), ::mlir::Operation::operand_range, ::mlir::TypedValue< ::fir::ClassType>, ::mlir::IntegerAttr> for template parameter 'Args'
  502 |   template <typename OpTy, typename... Args>
      |                                        ~~~~
  503 |   OpTy create(Location location, Args &&...args) {
      |        ^
1 error generated.

@vzakhari
Copy link
Contributor

vzakhari commented Jul 9, 2025

I see. Thanks for trying!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:codegen 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.

5 participants