[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:19 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 = []() {
+        std::array<StmtClassNameTable, Stmt::lastStmtConstant + 1> table;
----------------
zwuis wrote:

Variable names should start with a upper-case letter. Ditto elsewhere.

https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

https://github.com/llvm/llvm-project/pull/181367


More information about the cfe-commits mailing list