[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 28 07:27:10 PDT 2024


================
@@ -40,6 +40,12 @@ namespace usage_ok {
   int *p = A().class_member(); // expected-warning {{temporary whose address is used as value of local variable 'p' will be destroyed at the end of the full-expression}}
   int *q = A(); // expected-warning {{temporary whose address is used as value of local variable 'q' will be destroyed at the end of the full-expression}}
   int *r = A(1); // expected-warning {{temporary whose address is used as value of local variable 'r' will be destroyed at the end of the full-expression}}
+
+  void test_assignment() {
----------------
hokein wrote:

Good point, thanks for catching it.

The reason is that we pass the `false` to the `RevisitSubinits` parameter of `visitLocalsRetainedByInitializer` in `checkExprLifeTime`, and we bail out the analysis at https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/CheckExprLifetime.cpp#L728-L729. For the assignment case, we should pass `true`. Fixed and added a testcase. 

https://github.com/llvm/llvm-project/pull/96475


More information about the cfe-commits mailing list