Skip to content

asm volatile with no instructions generates invalid C code (missing empty string template) #26719

Description

@RbPyer

Describe the bug

When using asm volatile amd64 with only a memory clobber and no instructions, V generates invalid code that fails to compile with tcc/gcc.

Using nop as a placeholder instruction compiles successfully with tcc but generates unnecessary CPU instructions.

Reproduction Steps

module main

fn main() {
    asm volatile amd64 {
        ; ; ; memory
    }
}

Expected Behavior

This pattern is the standard way to express a compiler-only memory barrier on x86-64, where acquire/release fences don't require CPU instructions (due to TSO memory model) but still need to prevent compiler reordering.

Current Behavior

tcc:

Compilation with unknown C compiler
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/main.01KKCPGT9T6G9Y67QQ1ZJXGC8W.tmp.c:4581: error: string constant expected
=================================================================

gcc:

================== C compilation error (from gcc): ==============
cc: /tmp/v_1000/main.01KKCPTTB4YY157V228X3BMW5Q.tmp.c: В функции «newatomics__fence»:
cc: /tmp/v_1000/main.01KKCPTTB4YY157V228X3BMW5Q.tmp.c:4891:25: ошибка: expected string literal before «:» token
cc:  4891 |                         : : : "memory"
cc:       |                         ^
cc: /tmp/v_1000/main.01KKCPTTB4YY157V228X3BMW5Q.tmp.c:4896:25: ошибка: expected string literal before «:» token
cc:  4896 |                         : : : "memory"
cc:       |                         ^
cc: /tmp/v_1000/main.01KKCPTTB4YY157V228X3BMW5Q.tmp.c:4901:25: ошибка: expected string literal before «:» token
cc:  4901 |                         : : : "memory"
cc:       |                         ^
=================================================================

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.5.1 07ee934

Environment details (OS name and version, etc.)

V full version V 0.5.1 ffc6eaf.07ee934
OS linux, "EndeavourOS Linux"
Processor 32 cpus, 64bit, little endian, AMD Ryzen 9 9950X3D 16-Core Processor
Memory 34.25GB/60.37GB
V executable /home/oswyndel/v/v
V last modified time 2026-03-10 19:45:07
V home dir OK, value: /home/oswyndel/v
VMODULES OK, value: /home/oswyndel/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/oswyndel
Git version git version 2.53.0
V git status 07ee934
.git/config present true
cc version cc (GCC) 15.2.1 20260209
gcc version gcc (GCC) 15.2.1 20260209
clang version clang version 21.1.8
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (GNU libc) 2.43

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions