Check pointers in Debug mode
In Fortran a pointer can only point to a variable that has the target
attribute. We should implement an option in Debug mode to check pointers to ensure they cannot segfault, here is how it would work:
- Each pointer will have a flag
dangling
- Each time a pointer is dereferenced at runtime, we check the
dangling
flag, if true, we give a nice runtime error - Each target variable will have a list of pointers that point to it
- Each time we associate a pointer with some target variable, we add the pointer to the target variable's list
- Each time a target variable goes out of scope, we go over the list of pointers and set their
dangling
flag to true.
Thanks to the target
attribute, the pointer list only has to be stored for those, and so the overhead should not be too large (and it's a Debug mode feature anyway).