[flang-commits] [flang] [flang][nfc] Support volatile on ref, box, and class types (PR #134386)
Asher Mancinelli via flang-commits
flang-commits at lists.llvm.org
Mon Apr 7 06:50:22 PDT 2025
================
@@ -215,6 +230,19 @@ mlir::Type getDerivedType(mlir::Type ty) {
.Default([](mlir::Type t) { return t; });
}
+mlir::Type updateTypeWithVolatility(mlir::Type type, bool isVolatile) {
+ // If we already have the volatility we asked for, return the type unchanged.
+ if (fir::isa_volatile_type(type) == isVolatile)
+ return type;
+ return mlir::TypeSwitch<mlir::Type, mlir::Type>(type)
+ .Case<fir::BoxType, fir::ClassType, fir::ReferenceType>(
+ [&](auto ty) -> mlir::Type {
+ using TYPE = decltype(ty);
+ return TYPE::get(ty.getEleTy(), isVolatile);
+ })
+ .Default([&](mlir::Type t) -> mlir::Type { return t; });
----------------
ashermancinelli wrote:
Thanks! I thought about that, but when we convert arguments for function calls (#132486, `FIRBuilder::createConvertWithVolatileCast`) we want to convert values of all types to match the volatility of declared argument types, and values that can't represent volatility should pass through unchanged. If we'd rather assert in the default case, we could add a utility method like `type_can_be_volatile`, and if it's true for the type of a parameter, then convert the type using the method above to match volatility so we don't hit the assert. That seemed a bit more cumbersome to me - but let me know if you think differently and I'll revisit!
https://github.com/llvm/llvm-project/pull/134386
More information about the flang-commits
mailing list