[clang] Fix some static initialization race-conditions (PR #181367)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 13 08:37:20 PST 2026
================
@@ -57,26 +58,24 @@ using namespace clang;
#define ABSTRACT_STMT(STMT)
#include "clang/AST/StmtNodes.inc"
-static struct StmtClassNameTable {
+struct StmtClassNameTable {
const char *Name;
unsigned Counter;
unsigned Size;
-} StmtClassInfo[Stmt::lastStmtConstant+1];
+};
static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
- static bool Initialized = false;
- if (Initialized)
- return StmtClassInfo[E];
-
- // Initialize the table on the first use.
- Initialized = true;
+ static std::array<StmtClassNameTable, Stmt::lastStmtConstant + 1>
+ stmtClassInfo = []() {
----------------
zwuis wrote:
It's up to you, but parentheses could be omitted.
https://github.com/llvm/llvm-project/pull/181367
More information about the cfe-commits
mailing list