[clang] Fix some static initialization race-conditions (PR #181367)
Richard Dzenis via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 13 07:34:39 PST 2026
================
@@ -57,26 +57,19 @@ 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 StmtClassNameTable stmtClassInfo[Stmt::lastStmtConstant + 1] = {
#define ABSTRACT_STMT(STMT)
-#define STMT(CLASS, PARENT) \
- StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
- StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
+#define STMT(CLASS, PARENT) {#CLASS, 0, sizeof(CLASS)},
----------------
RIscRIpt wrote:
Good catch! My bad. Despite all `lit clang/test` pass locally, I wouldn't want to risk here. I'll make an initializer function/lambda.
https://github.com/llvm/llvm-project/pull/181367
More information about the cfe-commits
mailing list