[all-commits] [llvm/llvm-project] 3e25ae: [Clang] Correct when Itanium ABI guard variables a...

Tom Honermann via All-commits all-commits at lists.llvm.org
Wed Nov 16 13:36:02 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3e25ae605edd88720de3a4407fdd4ea85f758dce
      https://github.com/llvm/llvm-project/commit/3e25ae605edd88720de3a4407fdd4ea85f758dce
  Author: Tom Honermann <tom.honermann at intel.com>
  Date:   2022-11-16 (Wed, 16 Nov 2022)

  Changed paths:
    M clang/lib/CodeGen/ItaniumCXXABI.cpp
    M clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp
    M clang/test/CodeGenCXX/cxx11-thread-local.cpp
    M clang/test/CodeGenCXX/cxx1y-variable-template.cpp
    M clang/test/CodeGenCXX/global-init.cpp
    M clang/test/CodeGenCXX/static-data-member.cpp
    M clang/test/OpenMP/threadprivate_codegen.cpp

  Log Message:
  -----------
  [Clang] Correct when Itanium ABI guard variables are set for non-block variables with static or thread storage duration.

Previously, Itanium ABI guard variables were set after initialization was
complete for non-block declared variables with static and thread storage
duration. That resulted in initialization of such variables being restarted
in cases where the variable was referenced while it was still under
construction. Per C++20 [class.cdtor]p2, such references are permitted
(though the value obtained by such an access is unspecified). The late
initialization resulted in recursive reinitialization loops for cases like
this:
  template<typename T>
  struct ct {
    struct mc {
      mc() { ct<T>::smf(); }
      void mf() const {}
    };
    thread_local static mc tlsdm;
    static void smf() { tlsdm.mf(); }
  };
  template<typename T>
  thread_local typename ct<T>::mc ct<T>::tlsdm;
  int main() {
    ct<int>::smf();
  }

With this change, guard variables are set before initialization is started
so as to avoid such reinitialization loops.

Fixes https://github.com/llvm/llvm-project/issues/57828

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D135919




More information about the All-commits mailing list