Skip to content

[flang][NFC] Fix deprecation warning #147932

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

Merged
merged 3 commits into from
Jul 11, 2025

Conversation

tblah
Copy link
Contributor

@tblah tblah commented Jul 10, 2025

I started getting deprecation warnings from operations constructors which seem to be doing implicit construction of mlir::ValueRange from a std::nullopt by relying on implicit conversion from std::nullopt into llvm::ArrayRef. ArrayRef{std::nullopt} is what has been deprecated.

I started getting deprecation warnings from operations constructors
which seem to be doing implicit construction of mlir::ValueRange from a
std::nullopt by relying on implicit conversion from std::nullopt into
llvm::ArrayRef. ArrayRef{std::nullopt} is what has been deprecated.
@tblah tblah requested review from clementval and vzakhari July 10, 2025 10:17
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:codegen labels Jul 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 10, 2025

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

@llvm/pr-subscribers-flang-codegen

Author: Tom Eccles (tblah)

Changes

I started getting deprecation warnings from operations constructors which seem to be doing implicit construction of mlir::ValueRange from a std::nullopt by relying on implicit conversion from std::nullopt into llvm::ArrayRef. ArrayRef{std::nullopt} is what has been deprecated.


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

2 Files Affected:

  • (modified) flang/lib/Optimizer/CodeGen/CodeGen.cpp (+4-4)
  • (modified) flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp (+4-3)
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 1bc981516e226..2fe726cbb00e8 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -2240,7 +2240,7 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
       if (!rebox.getSubstr().empty())
         substringOffset = operands[rebox.getSubstrOperandIndex()];
       base = genBoxOffsetGep(rewriter, loc, base, llvmBaseObjectType, zero,
-                             /*cstInteriorIndices=*/std::nullopt, fieldIndices,
+                             /*cstInteriorIndices=*/{}, fieldIndices,
                              substringOffset);
     }
 
@@ -2248,7 +2248,7 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
       // 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,
+                           /*lbounds*/ {}, inputExtents, inputStrides,
                            rewriter);
 
     // The slice is of the form array(i:j:k)[%component]. Compute new extents
@@ -2297,7 +2297,7 @@ struct XReboxOpConversion : public EmboxCommonConversion<fir::cg::XReboxOp> {
       }
     }
     return finalizeRebox(rebox, adaptor, destBoxTy, dest, base,
-                         /*lbounds*/ std::nullopt, slicedExtents, slicedStrides,
+                         /*lbounds*/ {}, slicedExtents, slicedStrides,
                          rewriter);
   }
 
@@ -3396,7 +3396,7 @@ 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, B{}, 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..b60ac11c7795a 100644
--- a/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp
@@ -107,9 +107,10 @@ 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, mlir::ValueRange{},
+        mlir::ValueRange{}, mlir::ValueRange{}, mlir::ValueRange{},
+        embox.getTypeparams(), embox.getSourceBox(),
+        embox.getAllocatorIdxAttr());
     LLVM_DEBUG(llvm::dbgs() << "rewriting " << embox << " to " << xbox << '\n');
     rewriter.replaceOp(embox, xbox.getOperation()->getResults());
     return mlir::success();

@tblah tblah changed the title [flang] Fix deprecation warning [flang][NFC] Fix deprecation warning Jul 10, 2025
@tblah
Copy link
Contributor Author

tblah commented Jul 10, 2025

Ahh this was fixed by #147816

@tblah tblah closed this Jul 10, 2025
@DanielCChen
Copy link
Contributor

@tblah
Your fix in the PR is less verbose than mine in #147816, which is what @vzakhari prefers.
I would like to switch to your fix if that is OK. Do you want to add on top of #147816 or you prefer me to revert it first?

@tblah tblah reopened this Jul 10, 2025
@tblah tblah requested a review from DanielCChen July 10, 2025 14:42
Copy link

github-actions bot commented Jul 10, 2025

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

This is what I get for trying to use the web interface for the merge
conflicts.
Copy link
Contributor

@DanielCChen DanielCChen 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!

@tblah
Copy link
Contributor Author

tblah commented Jul 11, 2025

Windows failure looks like a bot failure.

However it seems MSVC is picking up far more of these deprecation warnings. @DavidTruby please could you look into this when you get time.

@tblah tblah merged commit 9a805ba into llvm:main Jul 11, 2025
8 of 9 checks passed
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.

3 participants