[all-commits] [llvm/llvm-project] 1374aa: [clang] Don't infer lifetime_capture-by for refere...
Haojian Wu via All-commits
all-commits at lists.llvm.org
Thu Jan 9 07:27:18 PST 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 1374aa35a3f62c774548361276a87eb472893262
https://github.com/llvm/llvm-project/commit/1374aa35a3f62c774548361276a87eb472893262
Author: Haojian Wu <hokein.wu at gmail.com>
Date: 2025-01-09 (Thu, 09 Jan 2025)
Changed paths:
M clang/lib/Sema/CheckExprLifetime.cpp
M clang/lib/Sema/CheckExprLifetime.h
M clang/lib/Sema/SemaAttr.cpp
M clang/test/AST/attr-lifetime-capture-by.cpp
M clang/test/Sema/warn-lifetime-analysis-capture-by.cpp
Log Message:
-----------
[clang] Don't infer lifetime_capture-by for reference of raw pointer types. (#122240)
When a vector is instantiated with a pointer type (`T` being `const
Foo*`), the inferred annotation becomes `push_back(const Foo*& value
[[clang::lifetime_capture_by(this)]])`.
For reference parameters, the `lifetime_capture_by` attribute treats the
lifetime as referring to the referenced object -- in this case, the
**pointer** itself, not the pointee object. In the `push_back`, we copy
the pointer's value, which does not establish a reference to the
pointer. This behavior is safe and does not capture the pointer's
lifetime.
The annotation should not be inferred for cases where `T` is a pointer
type, as the intended semantics do not align with the annotation.
Fixes #121391
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