rust-lang / rust-lang/rustc_codegen_gcc
Fix some cases of UB
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.2k
- Forks
- 105
- Avg merge
- 8h 20m
- Merged PRs (30d)
- 14
Description
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:
-fsanitize-fanalyzer: https://gcc.gnu.org/onlinedocs/gcc/Static-Analyzer-Options.html
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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