Skip to content

Conversation

P-E-P
Copy link
Member

@P-E-P P-E-P commented Sep 18, 2025

Fix segfault on builtin metavars as well as location on substituted tokens.

Builtin metavars are not in the fragment, the compiler should not emit
an error message.

gcc/rust/ChangeLog:

	* expand/rust-macro-substitute-ctx.cc (is_builtin_metavariable): Add
	function to check builtin metavars knowledge.
	(SubstituteCtx::check_repetition_amount): Do not process missing
	fragment.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Emitting the errors later means some error could be emitted multiple
times.

gcc/rust/ChangeLog:

	* expand/rust-macro-expand.cc (transcribe_expression): Emit error
	early.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
gcc/rust/ChangeLog:

	* expand/rust-macro-expand.cc: Forward invocation tree locus to
	substitution context.
	* expand/rust-macro-substitute-ctx.cc: Use origin location for expanded
	tokens.
	* expand/rust-macro-substitute-ctx.h (class SubstituteCtx): Save
	invocation location.

gcc/testsuite/ChangeLog:

	* rust/compile/macros/mbe/macro58.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P requested a review from CohenArthur September 18, 2025 15:53
@P-E-P P-E-P marked this pull request as ready for review September 18, 2025 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant