Bug 113292 - [modules] internal error when compiling header to module containing static thread_local variable
Summary: [modules] internal error when compiling header to module containing static th...
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 13.2.1
: P3 normal
Target Milestone: 14.0
Assignee: Nathaniel Shead
Keywords: ice-on-valid-code
Depends on:
Blocks: c++-modules
  Show dependency treegraph
Reported: 2024-01-09 16:14 UTC by Ondřej Novák
Modified: 2024-01-27 10:32 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Ondřej Novák 2024-01-09 16:14:57 UTC
may be similar to #99187

you can also see here : https://godbolt.org/z/o4Kf8ed85

class test {
    static const test &get_instance() {
        return instance;
    static thread_local test instance;

Compile with :-std=c++20 -fmodules-ts -x c++-header

internal compiler error: in tree_node, at cp/module.cc:9264
0x263852c internal_error(char const*, ...)
0xa4edb5 fancy_abort(char const*, int, char const*)
0xbbf621 trees_out::core_vals(tree_node*)
0xbc1ef8 trees_out::tree_value(tree_node*)
0xbbea88 trees_out::tree_node(tree_node*)

The error appears, when function is reading static thread_local variable

Comment 1 GCC Commits 2024-01-16 22:41:02 UTC
The master branch has been updated by Nathaniel Shead <nshead@gcc.gnu.org>:


commit r14-8168-g14338386970bc6c2d46b81181f48622fdf25d705
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Thu Jan 11 16:49:39 2024 +1100

    c++: Support thread_local statics in header modules [PR113292]
    Currently, thread_locals in header modules cause ICEs. This patch makes
    the required changes for them to work successfully.
    This requires additionally writing the DECL_TLS_MODEL for thread-local
    variables to the module interface, and the TLS wrapper function needs to
    have its DECL_BEFRIENDING_CLASSES written too as this is used to
    retrieve what VAR_DECL it's a wrapper for when emitting a definition at
    end of TU processing.
            PR c++/113292
            * decl2.cc (get_tls_wrapper_fn): Set DECL_CONTEXT.
            (c_parse_final_cleanups): Suppress warning for no definition of
            TLS wrapper functions in header modules.
            * module.cc (trees_out::lang_decl_vals): Write wrapped variable
            for TLS wrapper functions.
            (trees_in::lang_decl_vals): Read it.
            (trees_out::decl_value): Write TLS model for thread-local vars.
            (trees_in::decl_value): Read it for new decls. Remember to emit
            definitions of TLS wrapper functions later.
            * g++.dg/modules/pr113292_a.H: New test.
            * g++.dg/modules/pr113292_b.C: New test.
            * g++.dg/modules/pr113292_c.C: New test.
    Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Comment 2 Nathaniel Shead 2024-01-27 10:32:43 UTC
Fixed for GCC 14.