[llvm] [SandboxVec][NFC] Avoid temporary vectors. (PR #190867)
Jorge Gorbe Moya via llvm-commits
llvm-commits at lists.llvm.org
Sun May 3 16:10:34 PDT 2026
================
@@ -384,6 +384,16 @@ class VecUtils {
return make_range(Begin, End);
}
+ /// Helps convert things like `ArrayRef<Instruction *>` to `ArrayRef<Value *>`
+ /// and vice versa. For example, given an `ArrayRef<Instruction *> Instrs`, we
+ /// can get an ArrayRef of values:
+ /// `ArrayRef<Value *> Vals = VecUtils::toArrayRef<Value *>(Instrs);`
+ template <typename ToElmT, typename FromArrayRefT>
+ static ArrayRef<ToElmT> toArrayRef(FromArrayRefT From) {
+ return ArrayRef<ToElmT>(reinterpret_cast<const ToElmT *>(From.data()),
----------------
slackito wrote:
Is this cast (and, specifically, using the pointer normally afterwards) guaranteed to be safe? I'm thinking it might be susceptible to this kind of reinterpret_cast failure: https://anteru.net/blog/2007/c-background-static-reinterpret-and-c-style-casts/
https://github.com/llvm/llvm-project/pull/190867
More information about the llvm-commits
mailing list