[llvm-branch-commits] [clang] [analyzer] Only underline the exact parameter that is bound to the return value in UseAfterLifetimeEnd (PR #215651)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Aug 12 07:35:19 PDT 2026


================
@@ -410,3 +411,35 @@ void no_dangling_by_value_argument() {
   // The returned reference does not dangle.
   takes_by_value(BoundToSelf());
 }
+
+int multi_params_annotated(int *p_one [[clang::lifetimebound]], int *p_two [[clang::lifetimebound]]);
+
+int test_multi_param_highlight() {
+  int local_one = 1, local_two = 2;
+  // expected-note at -1 {{'local_one' initialized here}}
+  // expected-note at -2 {{'local_two' initialized here}}
+  return multi_params_annotated(&local_one, &local_two);
+  // expected-warning at -1 {{address of stack memory associated with local variable 'local_one' returned}}
+  // expected-warning at -2 {{address of stack memory associated with local variable 'local_two' returned}}
+  // expected-warning at -3 {{Returning value bound to 'local_one' that will go out of scope}}
+  // expected-note at -4    {{Value's lifetime bound to the lifetime of 'local_one' here}}
+  // expected-note at -5    {{Lifetime of 'local_one' ended here}}
+  // expected-warning at -6 {{Returning value bound to 'local_two' that will go out of scope}}
+  // expected-note at -7    {{Value's lifetime bound to the lifetime of 'local_two' here}}
+  // expected-note at -8    {{Lifetime of 'local_two' ended here}}
+
+  // CHECK: :[[@LINE-10]]:33: note: Value's lifetime bound to the lifetime of 'local_one' here
----------------
isuckatcs wrote:

Keeping this check only with the column number is sufficient imo.

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


More information about the llvm-branch-commits mailing list