Check pointers in Debug mode

Open
#338 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp, fortran
Domain
compilers

Research direction

The issue does not name implementation files, tests, or entry points. Start by locating Debug-mode runtime pointer handling in the compiler, then cover pointer association, dereference, and target scope exit; done means dangling pointers produce a runtime error instead of a segmentation fault.

Written by the indexing model from the issue text.

Description

Original issue: https://gitlab.com/lfortran/lfortran/-/issues/366

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).

Dominant language
C++
Stars
1.2k
Forks
271
Avg merge
1d 2h
Merged PRs (30d)
173

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lfortran/lfortran

All issues in lfortran/lfortran

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.