Skip to content

Tests: inline asm coverage (§16) #505

Closed

Description

@ehartford

Summary

Add committed coverage for inline assembly parsing, unsafe enforcement, and LLVM lowering. The current compiler has an asm parser and LLVM bridge support, but the requirement campaign found no tests protecting the surface.

Spec

§16.13 says asm embeds target-specific assembly and requires unsafe context (docs/with-specification.md:8925). The full syntax is asm(template : outputs : inputs : clobbers), each section is optional, trailing sections may be omitted, templates are string literals, inputs/outputs are comma-separated bindings, clobbers are strings, and volatile marks side effects (docs/with-specification.md:8938).

Current state

Parser.parse_asm parses outputs, inputs, clobbers, stores input expressions and output type in extras, and emits NK_ASM_EXPR (src/Parser.w:4840). MIR lowering handles NK_ASM_EXPR extras (src/MirLower.w:7742). LLVM bridge exposes wl_get_inline_asm (src/compiler/LlvmBridge.w:1322). The missing piece is test coverage; #479 tracks target guards, not basic asm coverage.

Implementation plan

  1. Add parser/check tests for every syntactic form: template only, outputs only, inputs, clobbers, and volatile.
  2. Add negative tests proving asm outside unsafe context fails, malformed output/input constraints fail, and non-string templates fail.
  3. Add one host-gated behavior test if possible. On aarch64 Darwin, use a harmless instruction such as moving an input to an output; on x86_64, use an equivalent constraint. If target guards are not implemented yet, keep this as check/IR coverage rather than runtime behavior.
  4. Add an IR/codegen test path that checks generated LLVM contains inline asm for a simple fixture, avoiding reliance on optimizer details.
  5. Once @[target("arch")] architecture guards (§16.13) #479 lands, add target-guarded variants.

Test plan

Add test/spec/spec_ss16_13_inline_asm_parse.w for check-only syntax coverage. Add test/compile_errors/err_inline_asm_requires_unsafe.w, err_inline_asm_template_string.w, and malformed constraint tests. Add test/behavior/behav_inline_asm_basic_<arch>.w or an IR corpus entry if runtime execution is not portable.

Acceptance criteria

  • All optional asm sections have parser/check tests.
  • Unsafe enforcement for asm is tested.
  • At least one codegen path proves NK_ASM_EXPR reaches LLVM inline asm lowering.
  • Target-specific runtime tests are gated or deferred to @[target("arch")] architecture guards (§16.13) #479; no test should fail on a supported host just because it is a different architecture.
  • with build && with build :fixpoint && with build :test pass.

Dependencies

Overlaps #479 for target guards.

Traceability

From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 16.13.1.1, 16.13.1.10, 16.13.1.2, 16.13.1.3, 16.13.1.4, 16.13.1.5, 16.13.1.8, 16.13.1.9.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing — asm clobbers section (behav_asm_clobbers) + non-string-template rejection (err_asm_template_string) pinned (3628d82); template-only/inputs/outputs/multi-output/unsafe-gate/unknown-placeholder already covered (behav_asm_literal_brace, behav_asm_placeholder, behav_asm_multi_output, err_asm_requires_unsafe, err_asm_unknown_placeholder). §16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions