[flang-commits] [flang] [flang] Apply nocapture attribute to dummy arguments (PR #116182)

via flang-commits flang-commits at lists.llvm.org
Fri Nov 15 05:10:45 PST 2024


================
@@ -45,6 +47,25 @@ void FunctionAttrPass::runOnOperation() {
 
   LLVM_DEBUG(llvm::dbgs() << "Func-name:" << func.getSymName() << "\n");
 
+  llvm::StringRef name = func.getSymName();
+  auto deconstructed = fir::NameUniquer::deconstruct(name);
+  bool isFromModule = !deconstructed.second.modules.empty();
+
+  if ((isFromModule || !func.isDeclaration()) &&
+      !fir::hasBindcAttr(func.getOperation())) {
+    llvm::StringRef nocapture = mlir::LLVM::LLVMDialect::getNoCaptureAttrName();
+    mlir::UnitAttr unitAttr = mlir::UnitAttr::get(func.getContext());
+
+    for (auto [index, argType] : llvm::enumerate(func.getArgumentTypes())) {
+      if (mlir::isa<fir::ReferenceType>(argType) &&
+          !fir::isPointerType(argType) &&
----------------
jeanPerier wrote:

You do not need the `fir::isPointerType` check here: it prevents putting nocapture on `fir.ref<fir.box<fir.ptr<>>` (addresses of descriptor created for Fortran POINTERs). It would be incorrect to add nocapture on the base address of the POINTER (which is the first struct member of the descriptor), but the address of the descriptor itself cannot be taken in Fortran.

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


More information about the flang-commits mailing list