[all-commits] [llvm/llvm-project] a6d26c: [clang] Fix dangling false positives for condition...

Haojian Wu via All-commits all-commits at lists.llvm.org
Fri Dec 20 00:26:59 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a6d26c56ff066c8e8f92f4ca169fcf40ae0db537
      https://github.com/llvm/llvm-project/commit/a6d26c56ff066c8e8f92f4ca169fcf40ae0db537
  Author: Haojian Wu <hokein.wu at gmail.com>
  Date:   2024-12-20 (Fri, 20 Dec 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/CheckExprLifetime.cpp
    M clang/test/Sema/warn-lifetime-analysis-nocfg.cpp

  Log Message:
  -----------
  [clang] Fix dangling false positives for conditional operators. (#120233)

When analyzing a dangling gsl pointer, we currently filter out all field
access `MemberExpr` to avoid common false positives (`string_view sv =
Temp().sv`), However, this filter only applies to direct MemberExpr
instances, leaving the conditional operator as an escaping example
(`GSLPointer pointer(Cond ? Owner().ptr : GSLPointer());`).

This patch extends the MemberExpr logic to handle the conditional
operator. The heuristic is intentionally simple, which may result in
some false negatives. However, it effectively covers common cases like
`std::string_view sv = cond ? "123" : std::string();`, which is a
reasonable trade-off.

Fixes https://github.com/llvm/llvm-project/issues/120206



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list