Issue 170418
Summary Infer [[clang::lifetimebound]] annotation
Labels clang
Assignees
Reporter usx95
    ```cpp
std::string_view f1(std::string_view a) {
  return a;
}

std::string_view f2(std::string_view a) {
  return f1(a);
}

std::string_view ff(std::string_view a) {
  std::string stack = "something on stack";
 return f2(stack); // warning: return-stack-addr
}
```
Along with annotation suggestions, we can also implicitly add lifetime annotation so that these annotations can be visible to functions which are parsed later. This allows to infer annotations for complete function call stacks (where the definitions are available).

The effectiveness of this also depends on the order of definitions processed by clang. For example, if `f2` was analysed before `f1`, we cannot infer annotation for `f2` and there also cannot detect the `return-stack-addr`. An ideal solution would be to analyse the function at the end of TU in topological order (callee then caller).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to