llvm-project
llvm-project copied to clipboard
SmallString/SmallVector don't allow self-assign() or append()
The assign(in_iter in_start, in_iter in_end) function of SmallVector (and by extension, SmallString) can't allow assignment to themselves or substrings/subvectors of themselves.
This manifested in a surprising crash in this very innocuous looking code:
SmallString AssetsPath<1024>;
...read AssetsPath...
AssetsPath = llvm::sys::path::parent_path(AssetsPath); // CRASH
The issue is that parent_path returns a StringRef of a substring of its input. The similar function append(in_iter in_start, in_iter in_end) has the same problem.
I notice that the other assign variant of assign: assign(size_type NumElts, ValueParamT Elt) explicitly handles self-assignment
Related is https://github.com/llvm/llvm-project/issues/25667 which I think is the same underlying problem.
Oh, I remember looking into this years ago and kind of running out of steam trying to think about all the cases/how to address them efficiently... so if anyone's interested in this, there's probably some llvm-dev and/or llvm-commits chatter in the archives about the issues here.