[llvm] Add clang::lifetimebound annotation to ArrayRef constructors. (PR #113547)

Haojian Wu via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 24 05:26:13 PDT 2024


hokein wrote:

> Any reason for not annotating the rest of the constructors?

Note that the ArrayRef is already annotated as gsl::Pointer, so constructor for the gsl::Owner already works without the lifetimebound annotation. I only target on the non-working cases, mostly the generic pointer/reference types.

Below is my test:

```
llvm::ArrayRef<int> test() {
   int array[10];
   std::vector<int> k;
   std::array<int, 10> k2;
   return k; // warning, local vector (owner)
   return k2; // warning, local array (owner)
   return {1, 2, 3}; // warning, initializing_list, backing array is destoryed.
   return llvm::ArrayRef<int>(array+0, array+10); // wanring
   return array; // warning
   return {array, 10}; // warning
}
```

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


More information about the llvm-commits mailing list