rust-lang / rust-lang/rustc_codegen_gcc

Make sure the GCC backend does not assume "pointer lifetime end zap" rules

Open
#517 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.2k
Forks
105
Avg merge
8h 20m
Merged PRs (30d)
14

Description

C has some very peculiar UB. For instance, when an allocation gets freed, then all pointers to that allocation become indeterminate values. This is sometimes called "pointer lifetime end zap". This means the following code has UB in C:

int *x = malloc(100);
free(x);
// Looking at x again is UB!
if ((uintptr_t)x == 1024) { printf("Hello!\n"); }

Obviously, the equivalent code in Rust is well-defined. Therefore, it would be good to make sure that whatever parts of GCC the backend is using are aware that Rust does not have pointer-lifetime-end-zap. I am somewhat concerned that GCC is modeled closely after C semantics and hence implicitly applies rules like that -- but I don't know how one would even begin to figure this out. Is there something like a LangRef for the GCC IR(s)?

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.

Research direction

Start by investigating the GCC backend and the libgccjit/GCC IR semantics relevant to pointer values after allocation lifetime ends. Determine whether Rust code generation relies on C-style pointer-lifetime-end behavior, then validate that the backend preserves Rust's defined behavior; the issue provides no specific file or test to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.