Repository navigation
Conversation
macro_pattern_match copied a metavariable's fragment specifier (ident, expr, ...) into a function-static buffer and passed a pointer to it on to macro_consume_fragment. Parallel extraction runs the matcher on several workers at once, so one worker could overwrite another's specifier before it was read. The buffer now lives beside the pointer that uses it. The race is latent today: invocation arguments are not captured on the extraction path yet, so the matcher never reaches the buffer and neither the ASan nor the TSan lane can observe it. The new parallel test extracts typed- fragment macros on four threads and checks every expansion resolves; it will exercise the matcher concurrently once argument capture works. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
The threads of parallel_rust_macro_fragments_do_not_share_state call cbm_extract_file directly and ended without releasing the extraction thread-locals, so LeakSanitizer on the Linux GCC leg reported 124,768 bytes in 132 allocations (field-id cache, tree cursor, slab, arena). They now exit the way a pool worker does in pass_parallel.c. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
macro_pattern_match(internal/cbm/lsp/rust_lsp.c) copied amacro_rules!metavariable's fragment specifier (ident,expr, ...) into a function-staticchar frag_buf[16]and passed a pointer to it on tomacro_consume_fragment. The buffer now lives in the matcher's own frame, beside thefragpointer that uses it.Why
Parallel extraction runs this matcher on several workers at once. With a static buffer, one worker can overwrite another's specifier between the copy and the read, which changes how a fragment is consumed and makes macro resolution nondeterministic.
How sure are we, honestly
The race is latent today. Invocation arguments are not captured on the extraction path yet (fragment substitution does not apply: a probe macro
($f:ident) => { $f() }invoked asm!(target)resolves nothing), so the matcher never reaches the buffer. We confirmed this the hard way. With the static restored and the TSan runner rebuilt from scratch, the new test still passes, so neither the ASan nor the TSan lane can observe the old race. The fix is still the right one, because the code is wrong as written and the next change to argument capture would make it live.Test
parallel_rust_macro_fragments_do_not_share_state(suiteparallel, which the TSan lane runs withCBM_WORKERS=4andhalt_on_error). Four threads each extract a Rust file with typed fragments ($n:ident, $e:expr, in a different order per thread) 25 times and must resolve the expansion to their own target every time. Its comment says plainly what it does not prove yet. Once argument capture works, it runs the matcher concurrently and the TSan lane is the one that would catch a shared buffer.Local:
parallel+rust_lspsuites, 615 passed (ASan+UBSan); TSan runner clean with the fix.Side finding (not fixed here)
macro_rules!fragment substitution never takes effect on the extraction path, apparently because the invocation's argument token tree is looked up by a field name the Rust grammar does not use formacro_invocation(unverified; to be investigated separately). Calls written through substituted fragments therefore don't resolve.