You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make GNU __thread variable templates thread local [GH #536] - #538
No actionable comments were generated in the recent review.
Walkthrough
The compiler now propagates GNU __thread to variable-template instances and checks their declaration modifiers. C23 generated-C handling recognizes these variables as thread-local. New regression tests cover thread isolation, specializations, dynamic initialization diagnostics, and constant-expression address use.
Changes: GNU thread-local variable templates
Layer / File(s)
Summary
Template modifier propagation and checks src/decls.c, src/decls.h, src/templates.c
The declaration-modifier check is available outside src/decls.c. Variable-template processing copies DM_THREAD to instances, checks initialization against declaration modifiers, and clears the modifier on a specialization’s first declaration.
C23 generated-C handling src/c_gen_be.c
File-scope variable selection recognizes DM_THREAD when the relevant declaration-modifier and TLS-specifier options are enabled. It omits non-extern thread-local variables from the non-defining pass and includes them in the definition pass.
Regression tests and issue note tests/tests/regressions/gh-536*.sft.cpp, tests/tests/regressions/.gh-536*.rto/*, src/pending_changes/gh-536-thread-variable-template.txt
Regression tests cover thread-local instance behavior, specializations, dynamic initialization diagnostics, and constant-expression address use. Test fixtures record GCC and Clang runs. The issue note describes the C23 code-generation case.
The change makes GNU __thread variable-template instances thread-local, adds C23 generated-C handling for them, and adds regression tests for runtime and diagnostic behavior. No concrete merge-blocking defect was found in the reviewed changes.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title says the change makes GNU __thread variable templates thread local, and [GH #536] names the linked issue. The changeset matches this. The templates.c change copies DM_THREAD onto variable-te…
Linked Issues check
[#536] Requirement: instances of GNU __thread variable templates must have thread storage duration. The reviewed summary shows that src/templates.c copies the DM_THREAD modifier, recorded during…
Out of Scope Changes check
All listed changes support the #536 fix. src/c_gen_be.c and src/templates.c implement the thread-local handling. src/decls.c and src/decls.h change check_variable_decl_modifiers from file-lo…
Full details: Title check
Explanation
The title says the change makes GNU __thread variable templates thread local, and [GH #536] names the linked issue. The changeset matches this. The templates.c change copies DM_THREAD onto variable-template instances, the C23 code generation in c_gen_be.c handles __thread file-scope variables, and the new gh-536 regression tests check distinct per-thread addresses. The title is specific and concise, so it passes.
Full details: Linked Issues check
Explanation
[#536] Requirement: instances of GNU __thread variable templates must have thread storage duration. The reviewed summary shows that src/templates.c copies the DM_THREAD modifier, recorded during declaration rescan, onto variable-template instances when thread-local storage specifiers are supported. src/c_gen_be.c adds is_thread_local_in_generated_c, which treats DM_THREAD as thread-local, so __thread declarations get the same file-scope handling as thread_local declarations. This addresses the C back-end cause named in the issue. tests/tests/regressions/gh-536.sft.cpp checks that each tested thread-local instance has a distinct address per thread, starts with its expected value, and keeps modifications local to the thread. The explicit tv<long> specialization is documented as shared, which matches normal explicit-specialization semantics. Automated test coverage exists. This assessment relies on the AI-generated summary and the listed changes; I did not inspect the diff hunks directly, so the exact code paths are not independently verified.
Full details: Out of Scope Changes check
Explanation
All listed changes support the #536 fix. src/c_gen_be.c and src/templates.c implement the thread-local handling. src/decls.c and src/decls.h change check_variable_decl_modifiers from file-local to external linkage, with a no-op macro when DECL_MODIFIERS_IN_USE is disabled. This exposes the helper needed by templates.c and is a supporting change. The added diagnostics for dynamic initialization of thread-local template variables and for taking an instance address in a constant expression are checked by the negative regression tests. These diagnostics follow from thread-local semantics that the issue's thread_local behavior already defines. The pending-changes note and the regression fixtures document and test the change. No unrelated change is identified in the summary.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, GNU
__threadvariable templates are given static storage duration instead of thread storage duration. This PR fixes this.Closes: #536
Summary by CodeRabbit
__threadvariable-template instances now behave as thread-local variables, with separate storage and initialization for each thread.__threadvariables with internal linkage.