Skip to content

Infer [[clang::lifetimebound]] annotation #170418

@usx95

Description

@usx95
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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions