[PATCH] D129841: [GlobalOpt] Enable evaluation of atomic stores

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 01:58:15 PDT 2022


alexander-shaposhnikov added a comment.

@dvyukov, after looking at https://godbolt.org/z/596b7jE9W - Clang emits separate elements of @llvm.global_ctors for ctor1 and ctor2 with the same priority (default) and LLVM takes advantage of reordering them.
For C++ objects Clang uses a different mechanism to ensure the correct order of initialization of globals (effectively the frontend synthesizes a global ctor (_GLOBAL__I_*) that invokes the constructors  in the correct order and puts it into @llvm.global_ctors
(the optimization pass works with elements of @llvm.global_ctors, so it will either fully statically evaluate it (_GLOBAL__I_*) or won't change it at all).
If I am not mistaken attribute((constructor)) is an extension and I have only found the following bit of documentation: https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Common-Function-Attributes.html#index-constructor-function-attribute
"However, at present, the order in which constructors for C++ objects with static storage duration and functions decorated with attribute constructor are invoked is unspecified. In mixed declarations, attribute init_priority can be used to impose a specific ordering."


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129841/new/

https://reviews.llvm.org/D129841



More information about the llvm-commits mailing list