[clang] [LifetimeSafety] Detect expiry of loans to trivially destructed types (PR #168855)

Kashika Akhouri via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 21 03:51:23 PST 2025


================
@@ -493,6 +515,43 @@ MyObj& reference_return_of_local() {
                     // expected-note at -1 {{returned here}}
 }
 
+int* trivial_int_uar() {
+  int *a;
+  int b = 1;
+  a = &b;          // expected-warning {{address of stack memory is returned later}}
+  return a;        // expected-note {{returned here}}
+}
+
+TriviallyDestructedClass* trivial_class_uar () {
+  TriviallyDestructedClass *ptr;
+  TriviallyDestructedClass s;
+  ptr = &s;       // expected-warning {{address of stack memory is returned later}}
+  return ptr;     // expected-note {{returned here}}
+}
+
+// FIXME: No lifetime warning for this as no loans are issued for paramters
+const int& return_parameter(int a) { 
+  return a; 
+}
+
+// FIXME: No lifetime warning for this as no loans are issued for paramters
----------------
kashika0112 wrote:

Done. PTAL

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


More information about the cfe-commits mailing list