This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fix data race on RegisterBank initialization.
ClosedPublic

Authored by huihuiz on Jan 28 2020, 2:56 PM.

Details

Summary

The initialization of RegisterBank needs to be done only once. The
logic of AlreadyInit has a data race, use llvm::call_once instead.

This issue was identified through thread sanitizer.

Diff Detail

Event Timeline

huihuiz created this revision.Jan 28 2020, 2:56 PM
huihuiz added a comment.EditedJan 28 2020, 2:58 PM

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

Using std::call_once, instead of a separate flag+mutex, would be a little more readable and efficient.

huihuiz updated this revision to Diff 241039.Jan 28 2020, 5:59 PM

Thanks Eli for the feedback!

huihuiz edited the summary of this revision. (Show Details)Jan 28 2020, 6:03 PM
This revision is now accepted and ready to land.Jan 28 2020, 6:08 PM
arsenm added a subscriber: arsenm.Jan 28 2020, 6:18 PM

The other targets also do this

Thanks @arsenm for catching this!
Fixing in D73604 and D73605