Reject GCC asm memory operands on register variables (ImportC) - #5206
Open
niy-ati wants to merge 4 commits into
Open
Reject GCC asm memory operands on register variables (ImportC)#5206niy-ati wants to merge 4 commits into
niy-ati wants to merge 4 commits into
Conversation
The frontend cannot diagnose m / =m constraints on register variables; reject them in GccAsmStatement_toIR when building indirect operands, matching C11 and GDC. Fixes ldc-developers#4967.
Do not fatal() after the first register+memory asm error so -verrors=0 can emit diagnostics for every illegal operand, matching GDC. Correct TEST_OUTPUT line numbers for the two asm statements.
kinke
requested changes
Jul 26, 2026
| } | ||
| if (registerMemError) | ||
| return; | ||
|
|
Member
There was a problem hiding this comment.
This can be more easily integrated in the loop below, where we already check indirect operands for lvalue-ness (and where we shouldn't call fatal() either), inlining checkRegisterMemoryAsmOperand() (no need for an extra function for that).
Member
There was a problem hiding this comment.
Other LDC-specific file additions to the DMD testsuite are named ldc_github_4967.c, to make clear that these are LDC-specific (incl. issue numbers).
Fold the ldc-developers#4967 check into the existing indirect-operand loop, drop the helper and fatal() on operand errors, and rename the fail_compilation test to ldc_github_4967.c.
niy-ati
force-pushed
the
fix-4967-register-asm
branch
2 times, most recently
from
July 26, 2026 18:03
f601977 to
5340084
Compare
Member
|
The other helper was fine, I just meant removing one of the two. And the check can be integrated more nicely, no need for |
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.
Summary
ImportC keeps
registerasSTCregister, but GCC style inline asm with"m"or"=m"constraints takes the operand address during LDC codegen. That is illegal C (same as GDC rejecting it) and was not caught in semantic analysis because the frontend does not interpret asm constraint strings.This rejects indirect memory asm operands that refer to a register variable in
GccAsmStatement_toIR, using the same diagnostic as other ImportC address of register cases.Fixes #4967.
Test plan
Added
tests/dmd/fail_compilation/issue4967.ccovering output and input"m"operands on aregister int.