Skip to content

checker: do not report .byte inside inline assembly as the deprecated byte type (fix #28739) - #28764

Open
quaesitor-scientiam wants to merge 2 commits into
vlang:masterfrom
quaesitor-scientiam:fix-28739-byte-directive-in-asm
Open

quaesitor-scientiam wants to merge 2 commits into
vlang:masterfrom
quaesitor-scientiam:fix-28739-byte-directive-in-asm

Conversation

@quaesitor-scientiam

Copy link
Copy Markdown
Contributor

Fixes #28739

The deprecated-byte check rescans the raw source text of each file, so the assembler directive .byte (or an Intel-syntax byte ptr operand) inside an asm block was reported as the V type. vlib/v/slow_tests/assembly/asm_test.amd64.v:174 and the .byte snippet in vlib/v/compiler_tests/inline_asm_c_lowering_test.v both hit this under V3.

Fix: collect the span of every asm_stmt node per file and skip byte tokens inside one. Text inside string literals was already skipped, so raw templates were unaffected; this covers V-syntax and Intel-syntax blocks.

Tests:

  • vlib/v/tests/inline_asm_byte_directive_test.v.byte 0x90 in an asm amd64 block; fails on master with the error above, passes with the fix (the $if amd64 branch is parsed and text-scanned on every arch, so the checker path is exercised everywhere).
  • vlib/v/checker/tests/use_byte_instead_of_u8_err.vv still reports all three byte type uses with a compiler built from this branch.

Known limitation: a V expression in an asm operand list (e.g. ; =r (byte(x))) is inside the span and no longer reported; that spelling is deprecated regardless and I found no instance in the tree.

The #28739 repro now passes the checker and fails at link on #28738 (top-level asm block not emitted), which is separate.

🧙 Built with WOZCODE

@JalonSolov

Copy link
Copy Markdown
Collaborator

Local AI Findings:

P2 checker.v:6170: the new offset_in_asm_span check suppresses every byte occurrence inside an asm_stmt, including deprecated V expressions in operand lists such as byte(x). That weakens the existing byte deprecation diagnostic. Restrict the exemption to raw assembler text, excluding spans belonging to parsed asm operands.

The added test covers .byte but not this operand-expression case.

@quaesitor-scientiam

Copy link
Copy Markdown
Contributor Author

Addressed in 193f983: the exemption now subtracts the spans of the block's operand expressions (the asm_stmt child nodes), so assembler text is exempt but a V expression in the operand list is still checked.

Added vlib/v/checker/tests/use_byte_instead_of_u8_in_asm_operand_err.vv with both a .byte 0x90 directive and a ; r (byte(x)) as y operand; only line 8 (the operand) is reported.

One thing I noticed while producing the .out: with a -prealloc compiler (what v self builds) and -no-parallel (what the fixture harness passes), the checker takes check_semantics_scoped_serial, which does not run check_deprecated_byte_types at all — the three existing use_byte_instead_of_u8_*_err.vv fixtures produce no error in that mode on master either. That is a separate, pre-existing gap; I can file it or fold a fix in here if you prefer.

@JalonSolov

Copy link
Copy Markdown
Collaborator

Probably better to do the other fixes in this PR. The current changes are small... it shouldn't add much to extend them.

@quaesitor-scientiam

Copy link
Copy Markdown
Contributor Author

Probably better to do the other fixes in this PR. The current changes are small... it shouldn't add much to extend them.

Opened separate issue #28792 and creased PR #28793 28793

PythonWillRule and others added 2 commits September 21, 2026 07:22
…ed `byte` type

The deprecated-`byte` check rescans the raw source text of each file, so the
assembler directive `.byte` (and an Intel-syntax `byte ptr` operand) inside an
`asm` block was reported as the V type:

    error: byte is deprecated, use u8 instead

Collect the spans of every `asm_stmt` node per file and skip `byte` tokens that
fall inside one. The existing checker error tests still report all three
`byte` type uses.

Fixes vlang#28739

Co-Authored-By: WOZCODE <contact@withwoz.com>
The inline-assembly exemption for the deprecated-`byte` check covered the
whole `asm_stmt` span, so a V expression in the operand list such as
`; r (byte(x))` was no longer reported. Subtract the spans of the block's
operand expressions (its child nodes) from the exemption: assembler text
stays exempt, operand expressions are checked as before.

Add a checker fixture with both a `.byte` directive and a `byte(x)` operand;
only the operand is reported.

Co-Authored-By: WOZCODE <contact@withwoz.com>
@quaesitor-scientiam
quaesitor-scientiam force-pushed the fix-28739-byte-directive-in-asm branch from 193f983 to aa49216 Compare September 21, 2026 11:34
@quaesitor-scientiam

Copy link
Copy Markdown
Contributor Author

Rebased onto 15aa541 (aa49216). The only conflict was the skip condition in check_deprecated_byte_types_in_file: master added tc.deprecated_byte_is_value_ident(file_id, start) there; it is kept, and the assembler-span exemption is added after it — the two are independent.

Still needed on master: with the PR's test and fixture copied into 15aa541, inline_asm_byte_directive_test.v fails with 7:5: error: byte is deprecated, use u8 instead and the operand fixture reports the .byte directive. After the rebase: the test passes on Linux x86_64 and Windows amd64, and use_byte_instead_of_u8_in_asm_operand_err, use_byte_instead_of_u8_err, use_byte_instead_of_u8_array_param_err, use_byte_instead_of_u8_array_type_err and asm_immutable_err match their .out under the harness flags on both.

This branch has not been deployed

No deployments
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.

checker: .byte directive inside an asm block is reported as the deprecated byte type

3 participants