-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Remove potential unitialized memory in the GC stack #60651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Only issue was. Writing a test for this was almost impossible. |
src/codegen.cpp
Outdated
| auto tracked = TrackCompositeType(ty); | ||
| jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_gcframe); | ||
| Instruction *last_inserted = ctx.topalloca; | ||
| for (const auto &indices : tracked) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be as simple as:
jl_datatype_t *dt = (jl_datatype_t *)v.typ;
bool hasptr = dt->layout->first_ptr >= 0;
size_t npointers = hasptr ? dt->layout->npointers : 0;
auto InsertPoint = ctx.builder.saveIP();
ctx.builder.SetInsertPoint(ctx.topalloca->getParent(), ++ctx.topalloca->getIterator());
for (size_t i = 0; i < npointers; i++) {
// make sure these are nullptr early from LLVM's perspective, in case it decides to SROA it
Value *ptr_field = emit_ptrgep(ctx, loc, jl_ptr_offset(dt, i) * sizeof(void *));
StoreInst *store = ctx.builder.CreateAlignedStore(
Constant::getNullValue(ctx.types().T_prjlvalue), ptr_field, Align(sizeof(void *)));
}
ctx.builder.restoreIP(InsertPoint);although you can get fancier if you want to coalesce adjacent roots to a single memset.
This logic should probably be moved to cgutils.cpp and implemented more similar to split_value_into / undef_derived_strct
It might be a reasonable addition to the GCinvariantPass? edit: Gabriel pointed out that DCE and (post-)dominating stores / loads will break that check, so that won't work sadly. |
Use Julia's datatype layout information (jl_ptr_offset) to iterate through pointer fields instead of walking LLVM types with TrackCompositeType. This approach is simpler and consistent with similar code like undef_derived_strct. Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
Addressed the review feedback - simplified the code to use Julia's datatype layout information ( |
(cherry picked from commit f9d461f)
(cherry picked from commit f9d461f)
Fixes #60622
This was a very messy thing. But apparently the code we generate for value_to_pointer is liable to being transformed by LLVM, and under some transformations specifically LICM we can materialize a root that didn't exist at codegen time and that root is liable to being being undef which can cause segfaults
This conservativaly initializes the gc pointers to zero.