This is an archive of the discontinued LLVM Phabricator instance.

[llvm][support] Replace `std::vector<bool>` use in YAMLTraits
ClosedPublic

Authored by jansvoboda11 on Jan 25 2022, 1:23 AM.

Details

Summary

LLVM Programmer’s Manual strongly discourages the use of std::vector<bool> and suggests llvm::BitVector as a possible replacement.

This patch replaces the use of std::vector with llvm::BitVector in LLVM's YAML traits and replaces the call to Vec.insert(Vec.begin(), N, false) on empty Vec with Vec.resize(N, false), which has the same sematnics but avoids using insert and iterators, which llvm::BitVector doesn't possess.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Jan 25 2022, 1:23 AM
jansvoboda11 requested review of this revision.Jan 25 2022, 1:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2022, 1:23 AM
dblaikie accepted this revision.Jan 25 2022, 9:17 AM
dblaikie added a subscriber: dblaikie.

SGTM!

This revision is now accepted and ready to land.Jan 25 2022, 9:17 AM
dexonsmith accepted this revision.Jan 25 2022, 10:01 AM

LGTM, with an alternative inline.

llvm/lib/Support/YAMLTraits.cpp
302

I might drop the explicit false parameter, since it feels implied to me (and very slightly noisy), but up to you.

This revision was landed with ongoing or failed builds.Jan 26 2022, 2:20 AM
This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.
llvm/include/llvm/Support/YAMLTraits.h
34

Is the <vector> header still needed then?

jansvoboda11 added inline comments.Feb 7 2022, 1:42 PM
llvm/include/llvm/Support/YAMLTraits.h
34

Yes, see the rest of the diff.