Skip to content

sync.stdatomic: fix tcc builds when tcc has no stdatomic.h - #28027

Merged
medvednikov merged 1 commit into
vlang:masterfrom
xRookieFight:fix/stdatomic-tcc-missing-header
Aug 5, 2026
Merged

sync.stdatomic: fix tcc builds when tcc has no stdatomic.h#28027
medvednikov merged 1 commit into
vlang:masterfrom
xRookieFight:fix/stdatomic-tcc-missing-header

Conversation

@xRookieFight

Copy link
Copy Markdown
Contributor

Fixes #28026.

1.declarations.c.v unconditionally includes the real <stdatomic.h> for tcc builds, right after the bundled compat header has gone out of its way to avoid it. That include was added in #27740 to bring the standard API back for user and third-party headers, and it works fine with the tcc V bundles (0.9.28rc), because that one ships its own self contained stdatomic.h. It falls apart on anything older - tcc 0.9.27 has no such header, so the include either fails outright:

builder error: 'stdatomic.h' not found

or, on a system where tcc does end up finding GCC's copy, dies a bit later on '__ATOMIC_RELAXED' undeclared, since GCC's header is written against builtins tcc does not provide.

Because v run silently retries with cc, none of this is visible unless you pass -no-retry-compilation. Anyone importing sync.stdatomic just quietly loses tcc as a backend.

So instead of including the header blindly, check for it first and fall back to the compat header's own definitions when it is not there. The #include <stdatomic.h> moves into a new tcc_compat_restore.h, guarded by __has_include. When tcc has the header nothing changes at all - same include, same order, same behaviour as today. When it does not, the fallback restores the handful of names the cleanup header stripped and that V itself needs: _Atomic, memory_order, the memory_order_* constants and the thread fence declarations, mirroring what thirdparty/stdatomic/nix/atomic.h already does for tcc.

Older tccs without __has_include support take the fallback branch too, which is the right answer for them anyway.

Testing

Reproduced by removing stdatomic.h from the bundled tcc's include dir, which puts it in the same state as a 0.9.27 install. On master that gives the exact error from the issue; with this patch:

  • v -cc tcc -no-retry-compilation run on the issue's repro - fails on master, prints 1 with the patch
  • v -cc tcc -no-retry-compilation test vlib/sync/ with the header removed - passes
  • v -cc tcc -no-retry-compilation test vlib/sync/ with the header in place - passes, unchanged
  • v -cc gcc test vlib/sync/stdatomic/ - passes
  • v -cc tcc -no-retry-compilation -o v cmd/v - builds

One note on the no-header case: stdatomic_include_after_compat_nix_test.v still fails there, but that is by design - the test itself does #include <stdatomic.h>, so it cannot pass on a compiler that has no such header. CI uses the bundled tcc, so it is unaffected.

@medvednikov
medvednikov merged commit 282bf30 into vlang:master Aug 5, 2026
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.

sync.stdatomic breaks under -cc tcc

2 participants