alexfh created this revision.
alexfh added a reviewer: ilya-biryukov.
Herald added a subscriber: jfb.
Herald added a project: clang.

Fixes a data race and makes it possible to run clang-based tools in
multithreaded environment with TSan.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58612

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ASTContext.cpp

Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -94,18 +94,18 @@
 
 using namespace clang;
 
-unsigned ASTContext::NumImplicitDefaultConstructors;
-unsigned ASTContext::NumImplicitDefaultConstructorsDeclared;
-unsigned ASTContext::NumImplicitCopyConstructors;
-unsigned ASTContext::NumImplicitCopyConstructorsDeclared;
-unsigned ASTContext::NumImplicitMoveConstructors;
-unsigned ASTContext::NumImplicitMoveConstructorsDeclared;
-unsigned ASTContext::NumImplicitCopyAssignmentOperators;
-unsigned ASTContext::NumImplicitCopyAssignmentOperatorsDeclared;
-unsigned ASTContext::NumImplicitMoveAssignmentOperators;
-unsigned ASTContext::NumImplicitMoveAssignmentOperatorsDeclared;
-unsigned ASTContext::NumImplicitDestructors;
-unsigned ASTContext::NumImplicitDestructorsDeclared;
+std::atomic<unsigned> ASTContext::NumImplicitDefaultConstructors;
+std::atomic<unsigned> ASTContext::NumImplicitDefaultConstructorsDeclared;
+std::atomic<unsigned> ASTContext::NumImplicitCopyConstructors;
+std::atomic<unsigned> ASTContext::NumImplicitCopyConstructorsDeclared;
+std::atomic<unsigned> ASTContext::NumImplicitMoveConstructors;
+std::atomic<unsigned> ASTContext::NumImplicitMoveConstructorsDeclared;
+std::atomic<unsigned> ASTContext::NumImplicitCopyAssignmentOperators;
+std::atomic<unsigned> ASTContext::NumImplicitCopyAssignmentOperatorsDeclared;
+std::atomic<unsigned> ASTContext::NumImplicitMoveAssignmentOperators;
+std::atomic<unsigned> ASTContext::NumImplicitMoveAssignmentOperatorsDeclared;
+std::atomic<unsigned> ASTContext::NumImplicitDestructors;
+std::atomic<unsigned> ASTContext::NumImplicitDestructorsDeclared;
 
 enum FloatingRank {
   Float16Rank, HalfRank, FloatRank, DoubleRank, LongDoubleRank, Float128Rank
Index: clang/include/clang/AST/ASTContext.h
===================================================================
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -63,6 +63,7 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
+#include <atomic>
 #include <cassert>
 #include <cstddef>
 #include <cstdint>
@@ -2809,46 +2810,46 @@
   //===--------------------------------------------------------------------===//
 
   /// The number of implicitly-declared default constructors.
-  static unsigned NumImplicitDefaultConstructors;
+  static std::atomic<unsigned> NumImplicitDefaultConstructors;
 
   /// The number of implicitly-declared default constructors for
   /// which declarations were built.
-  static unsigned NumImplicitDefaultConstructorsDeclared;
+  static std::atomic<unsigned> NumImplicitDefaultConstructorsDeclared;
 
   /// The number of implicitly-declared copy constructors.
-  static unsigned NumImplicitCopyConstructors;
+  static std::atomic<unsigned> NumImplicitCopyConstructors;
 
   /// The number of implicitly-declared copy constructors for
   /// which declarations were built.
-  static unsigned NumImplicitCopyConstructorsDeclared;
+  static std::atomic<unsigned> NumImplicitCopyConstructorsDeclared;
 
   /// The number of implicitly-declared move constructors.
-  static unsigned NumImplicitMoveConstructors;
+  static std::atomic<unsigned> NumImplicitMoveConstructors;
 
   /// The number of implicitly-declared move constructors for
   /// which declarations were built.
-  static unsigned NumImplicitMoveConstructorsDeclared;
+  static std::atomic<unsigned> NumImplicitMoveConstructorsDeclared;
 
   /// The number of implicitly-declared copy assignment operators.
-  static unsigned NumImplicitCopyAssignmentOperators;
+  static std::atomic<unsigned> NumImplicitCopyAssignmentOperators;
 
   /// The number of implicitly-declared copy assignment operators for
   /// which declarations were built.
-  static unsigned NumImplicitCopyAssignmentOperatorsDeclared;
+  static std::atomic<unsigned> NumImplicitCopyAssignmentOperatorsDeclared;
 
   /// The number of implicitly-declared move assignment operators.
-  static unsigned NumImplicitMoveAssignmentOperators;
+  static std::atomic<unsigned> NumImplicitMoveAssignmentOperators;
 
   /// The number of implicitly-declared move assignment operators for
   /// which declarations were built.
-  static unsigned NumImplicitMoveAssignmentOperatorsDeclared;
+  static std::atomic<unsigned> NumImplicitMoveAssignmentOperatorsDeclared;
 
   /// The number of implicitly-declared destructors.
-  static unsigned NumImplicitDestructors;
+  static std::atomic<unsigned> NumImplicitDestructors;
 
   /// The number of implicitly-declared destructors for which
   /// declarations were built.
-  static unsigned NumImplicitDestructorsDeclared;
+  static std::atomic<unsigned> NumImplicitDestructorsDeclared;
 
 public:
   /// Initialize built-in types.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to