rust-lang / rust-lang/rustc_codegen_gcc

Fix some cases of UB

Open
#347 0 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

https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/How.20does.20the.20GCC.20backend.20handle.20code.20C.20would.20disallow.3F

We probably have:

  • clobbering neighboring padding of assigned field

(jakub:

- AFAIK even C++ ought to guarantee state of padding bits in zero-initialization (but undefined when copied over e.g. through structure copy rather than memcpy; but our CONSTRUCTOR right now doesn't have a flag which would say all the padding is zero initialized
- and the question is what SRA etc. will do for it
- if all the Rust struct initializations are supposed to e.g. zero all padding bits, rather than say just small subset of them, then either the middle-end should be adjusted e.g. to have a flag on CONSTRUCTOR which guarantees it, or indeed create fields for all paddings and zero initialize them (all the FEs use stor-layout.cc routines for laying out structures/unions, so one can use that
- and then see where the paddings are and deal with those
- or there is __builtin_clear_padding builtin...

)

  • pointer lifetime end zapping
  • partially uninitialized data in union has to be preserved when it's moved around.

Maybe those will help find out what's currently UB:

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 with the linked Zulip discussion and investigate the listed cases: padding clobbering, pointer-lifetime end zapping, and preservation of partially uninitialized union data. Use -fsanitize and -fanalyzer to identify current undefined behavior; done requires narrowing the cases to reproducible findings and addressing the confirmed issues.

Written by the indexing model from the issue text.

Assessment

Tech stack
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.