Fortran: Fixes ASan issues in PDT testcases
Fortran compiler fixes ASan problems with parameterized derived types (PDTs) by adjusting memory allocation and type handling.
This commit addresses AddressSanitizer (ASan) issues encountered in Fortran’s parameterized derived type (PDT) test cases, as reported in PR 121972. It corrects logic for identifying PDT components, ensures calloc is used appropriately for types with parameterized or allocatable components, and refines the allocation process for parameterized components of class PDTs.
In Details
The Fortran frontend's handling of Parameterized Derived Types (PDTs) has been improved to resolve AddressSanitizer (ASan) failures, specifically related to memory management within expr.cc, trans-expr.cc, and trans-stmt.cc. The has_parameterized_comps function in expr.cc now correctly returns false for types without PDT components. alloc_scalar_allocatable_for_assignment in trans-expr.cc now uses calloc for PDTs, consistent with allocatable components, and gfc_trans_allocate in trans-stmt.cc merges allocation logic for PDTs and class PDTs, ensuring correct nullification o…
- Fortran
- A high-level programming language commonly used for scientific and high-performance computing. GCC's
gfortranis its Fortran compiler. - AddressSanitizer (ASan)
- A fast memory error detector for C/C++/Objective-C. When enabled during compilation, ASan instruments the code to find bugs like use-after-free, heap buffer overflows, and use-after-return at runtime.
- Parameterized Derived Type (PDT)
- A user-defined type in Fortran whose definition can include parameters that are specified when the type is declared. This allows for more flexible and generic type definitions.
- calloc
- A memory allocation function (similar to
malloc) that allocates memory for an array of elements, initializes all bytes to zero, and returns a pointer to the allocated memory. It's often preferred for arrays or structures that should start with zeroed memory. - PR 121972
- Problem Report number 121972 in the GCC bug tracking system, related to AddressSanitizer issues with Fortran parameterized derived types.