[flang-commits] [flang] [flang][runtime] Interoperable POINTER deallocation validation (PR #96100)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Sun Jun 23 21:20:01 PDT 2024


================
@@ -176,6 +183,27 @@ int RTDEF(PointerAllocateSource)(Descriptor &pointer, const Descriptor &source,
   return stat;
 }
 
+static RT_API_ATTRS std::size_t GetByteSize(
+    const ISO::CFI_cdesc_t &descriptor) {
+  std::size_t rank{descriptor.rank};
+  const ISO::CFI_dim_t *dim{descriptor.dim};
+  std::size_t byteSize{descriptor.elem_len};
+  for (std::size_t j{0}; j < rank; ++j) {
+    byteSize *= dim[j].extent;
+  }
+  return byteSize;
+}
+
+bool RT_API_ATTRS ValidatePointerPayload(const ISO::CFI_cdesc_t &desc) {
+  std::size_t byteSize{GetByteSize(desc)};
+  constexpr std::size_t align{sizeof(std::uintptr_t)};
+  byteSize = ((byteSize / align) + 1) * align;
----------------
vzakhari wrote:

```suggestion
  byteSize = ((byteSize + align - 1) / align) * align;
```

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


More information about the flang-commits mailing list