[llvm] [BOLT] Fix data race in MCPlusBuilder::getOrCreateAnnotationIndex (PR #67004)

Amir Ayupov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 10:31:02 PDT 2023


================
@@ -1784,15 +1790,20 @@ class MCPlusBuilder {
   /// Return annotation index matching the \p Name. Create a new index if the
   /// \p Name wasn't registered previously.
   unsigned getOrCreateAnnotationIndex(StringRef Name) {
-    auto AI = AnnotationNameIndexMap.find(Name);
-    if (AI != AnnotationNameIndexMap.end())
-      return AI->second;
+    {
+      std::optional<unsigned> Index = getAnnotationIndex(Name);
+      if (Index.has_value())
+        return *Index;
----------------
aaupov wrote:

```suggestion
      if (std::optional<unsigned> Index = getAnnotationIndex(Name))
        return *Index;
```

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


More information about the llvm-commits mailing list