Skip to content

cgen: fix x86 segment-override memory operands in basic inline asm - #27782

Merged
medvednikov merged 5 commits into
vlang:masterfrom
fleximus:fix-27777-asm-segment-override
Sep 9, 2026
Merged

cgen: fix x86 segment-override memory operands in basic inline asm#27782
medvednikov merged 5 commits into
vlang:masterfrom
fleximus:fix-27777-asm-segment-override

Conversation

@fleximus

Copy link
Copy Markdown
Member

Fixes #27777

In basic inline assembly (no operand lists), the template string is passed to the assembler verbatim, so segment overrides like gs:[16] were emitted as %%gs:16 and rejected with invalid register name. Registers already handled this via stmt.is_basic; this applies the same escaping rule to segment prefixes: single % in basic asm, %% in extended asm.

Verified with the issue's repro (v -freestanding -cc clang -keepc .) — the binary now disassembles to mov %rdi,%gs:0x10. Added a coutput testdata pair covering both the basic and extended forms.

@medvednikov

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 499d0e3d31

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/v/gen/c/cgen.v Outdated
Comment on lines +6284 to +6287
if !stmt.is_basic {
g.write('%') // escape percent with percent in extended assembly
}
g.write('%${arg.segment}:')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Escape segment prefixes in asm goto

In asm goto blocks that only provide the label list (for example asm goto amd64 { jmp gs:[16]; ; ; ; done }), the parser still leaves stmt.is_basic true because it only counts outputs/inputs/clobbers, but asm_stmt emits __asm__ goto (... : : : : label), which is extended asm. This branch therefore writes %gs: instead of %%gs:, and GCC/Clang parse %g as an operand escape (operand number missing after %-letter). Please base this escaping on whether the emitted C asm is extended, including stmt.is_goto, rather than is_basic alone.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Codex provided feedback for a valid problem here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@medvednikov the checks failing on other code, likely due to the new parser.

@medvednikov

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-09T07:07:14.248068Z 4e26828 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 9ece160d2e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@medvednikov
medvednikov merged commit 9f12a91 into vlang:master Sep 9, 2026
4 of 102 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.

cgen: fix x86 segment-override memory operands in basic inline asm

2 participants