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
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@P-E-P P-E-P added this pull request to the merge queue Sep 25, 2025
Merged via the queue into Rust-GCC:master with commit 32ce955 Sep 25, 2025
13 checks passed
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.

2 participants