[PATCH] D154924: [bolt] Fix MSVC builds

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 11 00:34:37 PDT 2023


smeenai created this revision.
smeenai added reviewers: ayermolo, Amir, maksfb.
Herald added a reviewer: rafauler.
Herald added a subscriber: treapster.
Herald added a project: All.
smeenai requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

We need to explicitly mark DWARFUnitInfo as non-copyable since MSVC's
STL has a `noexcept(false)` move constructor for `unordered_map`; see
the added comment for more details.

An alternative might be using SmallVector instead of std::vector, since
that never tries to copy elements [1]. That would result in a bunch of
API changes though, so I figured a smaller targeted fix was better.

[1] https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154924

Files:
  bolt/include/bolt/Core/DIEBuilder.h


Index: bolt/include/bolt/Core/DIEBuilder.h
===================================================================
--- bolt/include/bolt/Core/DIEBuilder.h
+++ bolt/include/bolt/Core/DIEBuilder.h
@@ -58,6 +58,20 @@
     // A map of DIE offsets in original DWARF section to DIE ID.
     // Whih is used to access DieInfoVector.
     std::unordered_map<uint64_t, uint32_t> DIEIDMap;
+
+    // Some STL implementations don't have a noexcept move constructor for
+    // unordered_map (e.g. https://github.com/microsoft/STL/issues/165 explains
+    // why the Microsoft STL doesn't). In that case, the default move
+    // constructor generated for DWARFUnitInfo isn't noexcept either, and thus
+    // resizing a vector of DWARFUnitInfo will copy elements instead of moving
+    // them (https://en.cppreference.com/w/cpp/utility/move_if_noexcept).
+    // DWARFUnitInfo isn't copyable though, since the DieInfoVector member is a
+    // vector of unique_ptrs and unique_ptr isn't copyable, so using a vector of
+    // DWARFUnitInfo causes build errors. Explicitly marking DWARFUnitInfo as
+    // non-copyable forces vector resizes to move instead and fixes the issue.
+    DWARFUnitInfo() = default;
+    DWARFUnitInfo(const DWARFUnitInfo &) = delete;
+    DWARFUnitInfo(DWARFUnitInfo &&) = default;
   };
 
   enum class ProcessingType { DWARF4TUs, DWARF5TUs, CUs };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154924.538932.patch
Type: text/x-patch
Size: 1363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230711/ee73237e/attachment.bin>


More information about the llvm-commits mailing list