[all-commits] [llvm/llvm-project] 3eba28: [clang] Extend lifetime analysis to support assign...
Haojian Wu via All-commits
all-commits at lists.llvm.org
Thu Jul 18 01:02:56 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 3eba28d1fd3347a1658f68b63285148b0bb25fab
https://github.com/llvm/llvm-project/commit/3eba28d1fd3347a1658f68b63285148b0bb25fab
Author: Haojian Wu <hokein.wu at gmail.com>
Date: 2024-07-18 (Thu, 18 Jul 2024)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/include/clang/Basic/DiagnosticGroups.td
M clang/include/clang/Basic/DiagnosticSemaKinds.td
M clang/lib/Sema/CheckExprLifetime.cpp
M clang/lib/Sema/SemaOverload.cpp
M clang/test/Sema/warn-lifetime-analysis-nocfg-disabled.cpp
M clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
M clang/test/SemaCXX/warn-dangling-local.cpp
Log Message:
-----------
[clang] Extend lifetime analysis to support assignments for pointer-like objects. (#99032)
This is a follow-up patch to #96475 to detect dangling assignments for
C++ pointer-like objects (classes annotated with the
`[[gsl::Pointer]]`). Fixes #63310.
Similar to the behavior for built-in pointer types, if a temporary owner
(`[[gsl::Owner]]`) object is assigned to a pointer-like class object,
and this temporary object is destroyed at the end of the full assignment
expression, the assignee pointer is considered dangling. In such cases,
clang will emit a warning:
```
/tmp/t.cpp:7:20: warning: object backing the pointer my_string_view will be destroyed at the end of the full-expression [-Wdangling-assignment-gsl]
7 | my_string_view = CreateString();
| ^~~~~~~~~~~~~~
1 warning generated.
```
This new warning is `-Wdangling-assignment-gsl`. It is initially
disabled, but I intend to enable it by default in clang 20.
I have initially tested this patch on our internal codebase, and it has
identified many use-after-free bugs, primarily related to `string_view`.
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