[libcxx-commits] [libcxx] [libc++] Optimize std::find_if (PR #167697)

Thurston Dang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 13 10:56:28 PST 2026


thurstond wrote:

Separately, there's a heap buffer overflow report (https://lab.llvm.org/buildbot/#/builders/55/builds/22573/steps/13/logs/stdio):

```
READ of size 8 at 0xe7b9fffedb30 tags: 13/01(13) (ptr/mem) in thread T0
Invalid access starting at offset 1
    #0 0xbcf231eda71c in find_if<std::__1::__wrap_iter<const llvm::Record **>, (lambda at /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:193:31) &> /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_install_hwasan/include/c++/v1/__algorithm/find_if.h:28:16
    #1 0xbcf231eda71c in remove_if<std::__1::__wrap_iter<const llvm::Record **>, (lambda at /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:193:31)> /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_install_hwasan/include/c++/v1/__algorithm/remove_if.h:28:13
    #2 0xbcf231eda71c in remove_if<std::__1::vector<const llvm::Record *, std::__1::allocator<const llvm::Record *> > &, (lambda at /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:193:31)> /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/include/llvm/ADT/STLExtras.h:1783:10
    #3 0xbcf231eda71c in erase_if<std::__1::vector<const llvm::Record *, std::__1::allocator<const llvm::Record *> >, (lambda at /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:193:31)> /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/include/llvm/ADT/STLExtras.h:2169:11
    #4 0xbcf231eda71c in featureKeyValues /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:193:3
    #5 0xbcf231eda71c in (anonymous namespace)::SubtargetEmitter::emitMCDesc(llvm::raw_ostream&, llvm::DenseMap<llvm::Record const*, unsigned int, llvm::DenseMapInfo<llvm::Record const*, void>, llvm::detail::DenseMapPair<llvm::Record const*, unsigned int>> const&) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:2062:26
    #6 0xbcf231ecfee4 in (anonymous namespace)::SubtargetEmitter::run(llvm::raw_ostream&) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:2251:44
    #7 0xbcf231ecf190 in llvm::TableGen::Emitter::OptClass<(anonymous namespace)::SubtargetEmitter>::run(llvm::StringRef, llvm::RecordKeeper const&) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/include/llvm/TableGen/TableGenBackend.h:64:18
    #8 0xbcf2320b5370 in llvm::TableGen::Emitter::ApplyCallback(llvm::RecordKeeper const&, llvm::TableGenOutputFiles&, llvm::StringRef) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/TableGen/TableGenBackend.cpp:75:16
    #9 0xbcf23204ce50 in llvm::TableGenMain(char const*, llvm::function_ref<bool (llvm::TableGenOutputFiles&, llvm::RecordKeeper const&)>) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/TableGen/Main.cpp:174:7
    #10 0xbcf2318691a8 in tblgen_main(int, char**) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/Basic/TableGen.cpp:77:10
    #11 0xfbab947a22d8  (/lib/aarch64-linux-gnu/libc.so.6+0x222d8) (BuildId: 399cf29a11ad91a5d31f063a4869f3535e7a4b7a)
    #12 0xfbab947a23b8 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x223b8) (BuildId: 399cf29a11ad91a5d31f063a4869f3535e7a4b7a)
    #13 0xbcf231760eac in _start (/home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm_build_hwasan/bin/llvm-tblgen+0x1e0eac)
[0xe7b9fffedb30,0xe7b9fffedb40) is a small allocated heap chunk; size: 16 offset: 0
Cause: heap-buffer-overflow
0xe7b9fffedb30 is located 0 bytes inside a 1-byte region [0xe7b9fffedb30,0xe7b9fffedb31)
allocated by thread T0 here:
    #0 0xbcf23179ced4 in operator new(unsigned long) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/compiler-rt/lib/hwasan/hwasan_new_delete.cpp:122:3
    #1 0xbcf231eda6a8 in __libcpp_allocate<const llvm::Record *> /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_install_hwasan/include/c++/v1/__new/allocate.h:42:28
    #2 0xbcf231eda6a8 in allocate /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_install_hwasan/include/c++/v1/__memory/allocator.h:92:14
    #3 0xbcf231eda6a8 in __allocate_at_least<std::__1::allocator<const llvm::Record *>, std::__1::allocator_traits<std::__1::allocator<const llvm::Record *> > > /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_install_hwasan/include/c++/v1/__memory/allocate_at_least.h:46:94
    #4 0xbcf231eda6a8 in __vallocate /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_install_hwasan/include/c++/v1/__vector/vector.h:595:25
    #5 0xbcf231eda6a8 in __init_with_size<const llvm::Record *const *, const llvm::Record *const *> /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_install_hwasan/include/c++/v1/__vector/vector.h:613:7
    #6 0xbcf231eda6a8 in vector<const llvm::Record *const *, 0> /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/libcxx_install_hwasan/include/c++/v1/__vector/vector.h:212:5
    #7 0xbcf231eda6a8 in operator vector /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:279:14
    #8 0xbcf231eda6a8 in featureKeyValues /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:190:7
    #9 0xbcf231eda6a8 in (anonymous namespace)::SubtargetEmitter::emitMCDesc(llvm::raw_ostream&, llvm::DenseMap<llvm::Record const*, unsigned int, llvm::DenseMapInfo<llvm::Record const*, void>, llvm::detail::DenseMapPair<llvm::Record const*, unsigned int>> const&) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:2062:26
    #10 0xbcf231ecfee4 in (anonymous namespace)::SubtargetEmitter::run(llvm::raw_ostream&) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/SubtargetEmitter.cpp:2251:44
    #11 0xbcf231ecf190 in llvm::TableGen::Emitter::OptClass<(anonymous namespace)::SubtargetEmitter>::run(llvm::StringRef, llvm::RecordKeeper const&) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/include/llvm/TableGen/TableGenBackend.h:64:18
    #12 0xbcf2320b5370 in llvm::TableGen::Emitter::ApplyCallback(llvm::RecordKeeper const&, llvm::TableGenOutputFiles&, llvm::StringRef) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/TableGen/TableGenBackend.cpp:75:16
    #13 0xbcf23204ce50 in llvm::TableGenMain(char const*, llvm::function_ref<bool (llvm::TableGenOutputFiles&, llvm::RecordKeeper const&)>) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/lib/TableGen/Main.cpp:174:7
    #14 0xbcf2318691a8 in tblgen_main(int, char**) /home/b/sanitizer-aarch64-linux-bootstrap-hwasan/build/llvm-project/llvm/utils/TableGen/Basic/TableGen.cpp:77:10
    #15 0xfbab947a22d8  (/lib/aarch64-linux-gnu/libc.so.6+0x222d8) (BuildId: 399cf29a11ad91a5d31f063a4869f3535e7a4b7a)
    #16 0xdfbab947a23b8  (<unknown module>)
    #17 0x7dbcf231760eac  (<unknown module>)


Thread: T0 0xebaa00002000 stack: [0xffffd5e4f000,0xffffd6a4f000) sz: 12582912 tls: [0xfbab94ee6b20,0xfbab94ee79c0)
Memory tags around the buggy address (one tag corresponds to 16 bytes):
  0xe7b9fffed300: 08  01  b6  08  bd  6c  08  72  87  08  54  d0  08  5b  53  08 
  0xe7b9fffed400: a6  bf  08  4f  31  08  59  e0  08  26  63  08  03  16  08  08 
  0xe7b9fffed500: 0c  fe  08  15  92  08  0d  e3  08  08  35  03  08  09  45  08 
  0xe7b9fffed600: ac  43  08  71  55  08  08  c4  bb  08  24  e4  08  17  99  08 
  0xe7b9fffed700: ba  32  08  36  cc  08  5a  a0  08  97  0c  08  a6  73  08  35 
  0xe7b9fffed800: 4a  08  e4  23  08  7b  7e  08  73  8d  08  e0  9a  08  0c  ad 
  0xe7b9fffed900: 08  e6  40  08  0a  3b  08  74  08  08  05  54  08  54  4f  08 
  0xe7b9fffeda00: 04  04  04  04  04  04  04  04  04  04  12  04  04  04  08  89 
=>0xe7b9fffedb00: 04  2c  46 [01] 00  00  00  00  00  00  00  00  00  00  00  00 
  0xe7b9fffedc00: 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
  0xe7b9fffedd00: 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
  0xe7b9fffede00: 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
  0xe7b9fffedf00: 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
  0xe7b9fffee000: 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
  0xe7b9fffee100: 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
  0xe7b9fffee200: 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
  0xe7b9fffee300: 00  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00 
Tags for short granules around the buggy address (one tag corresponds to 16 bytes):
  0xe7b9fffeda00: 39  5a  de  12  72  8a  54  90  d7  c3  ..  12  63  ba  3d  .. 
=>0xe7b9fffedb00: 1f  ..  .. [13] ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  .. 
  0xe7b9fffedc00: ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  ..  .. 
See https://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html#short-granules for a description of short granule tags
Registers where the failure occurred (pc 0xbcf231eda71c):
    x0  1300e7b9fffedb30  x1  0000000000000000  x2  0000000000000000  x3  be700dd8bd52c336
    x4  0000000000001d4d  x5  0000000000000014  x6  0000ffffd5e4f000  x7  0000000000000001
    x8  1300e7b9fffedb30  x9  0000000000000001  x10 0000000000000013  x11 0000ffffd6a4b9f0
    x12 0000000000000000  x13 0000000000000000  x14 0200ebaaffffffff  x15 00401d754000015f
    x16 0000bcf231778f80  x17 0000000000000007  x18 000000000000001a  x19 6c00bcf23167c560
    x20 0200ebab00000000  x21 0000000000000000  x22 e100ffffd6a4c540  x23 0000000000000000
    x24 00401d7540000181  x25 8500ffffd6a4c400  x26 6100ffffd6a4c4e0  x27 0000ffffd6a4c480
    x28 d100ffffd6a4ccc0  x29 0000ffffd6a4c600  x30 0000bcf231eda720   sp 0000ffffd6a4c1c0
```


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


More information about the libcxx-commits mailing list