[llvm] [RFC][Support] Introduce buffered_svector_ostream (PR #97704)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 4 10:45:40 PDT 2024


MaskRay wrote:

The synchronization introduced by 3d1173ba1a53cab08ed2c33e47dd617df77a914b means `OS.tell() == Vec.size()`.
The slow path is `raw_ostream::write => raw_ostream::writeSlow`.

The risk can be demonstrated below
```
  {
    SmallVector<char, 128> Vec;
    raw_svector_ostream OS(Vec);
    OS << "aaa";
    Vec.size()   // NO! size() may be different from OS.tell()
    // ~OS truncates Vec (synchronization)
  }
```

Is there an estimate of the in-tree violations?

If the conceived out-of-tree breakage is small, we could make this part of LLVM_ENABLE_ABI_BREAKING_CHECKS initially, and possibly call `__asan_poison_memory_region` to detect `[tell(), size())` access (due to accessing `SmallVector` before synchronization).


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


More information about the llvm-commits mailing list