[PATCH] D73587: [AArch64] Fix data race on RegisterBank initialization.

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 15:02:49 PST 2020


huihuiz created this revision.
huihuiz added reviewers: efriedma, apazos, qcolombet, dsanders.
huihuiz added a project: LLVM.
Herald added subscribers: hiraditya, kristof.beyls.
huihuiz added a comment.

This issue was exposed when linking with ThinLTO+lld, using a compiler built with thread sanitizer enabled.


The initialization of RegisterBank needs to be done only once. The
logic of AlreadyInit has a data race, guard under mutex lock.

This issue was identified through thread sanitizer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73587

Files:
  llvm/lib/Target/AArch64/AArch64RegisterBankInfo.cpp


Index: llvm/lib/Target/AArch64/AArch64RegisterBankInfo.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64RegisterBankInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64RegisterBankInfo.cpp
@@ -38,12 +38,14 @@
 
 AArch64RegisterBankInfo::AArch64RegisterBankInfo(const TargetRegisterInfo &TRI)
     : AArch64GenRegisterBankInfo() {
+  static std::mutex RegisterBankInitLock;
   static bool AlreadyInit = false;
   // We have only one set of register banks, whatever the subtarget
   // is. Therefore, the initialization of the RegBanks table should be
   // done only once. Indeed the table of all register banks
   // (AArch64::RegBanks) is unique in the compiler. At some point, it
   // will get tablegen'ed and the whole constructor becomes empty.
+  std::lock_guard<std::mutex> Guard(RegisterBankInitLock);
   if (AlreadyInit)
     return;
   AlreadyInit = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73587.241007.patch
Type: text/x-patch
Size: 916 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200128/92b952a9/attachment.bin>


More information about the llvm-commits mailing list