[clang] [LifetimeSafety] Detect use-after-return (PR #165370)
Kashika Akhouri via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 14 05:27:31 PST 2025
================
@@ -396,6 +396,124 @@ void loan_from_previous_iteration(MyObj safe, bool condition) {
} // expected-note {{destroyed here}}
}
+//===----------------------------------------------------------------------===//
+// Basic Definite Use-After-Return (Return-Stack-Address) (-W...permissive)
+// These are cases where the pointer is guaranteed to be dangling at the use site.
+//===----------------------------------------------------------------------===//
+
+MyObj* simple_return_stack_address(){
+ MyObj s;
+ MyObj* p = &s; // expected-warning {{address of stack memory is returned later}}
+ return p; // expected-note {{returned here}}
+}
+
+const MyObj* conditional_assign_unconditional_return(const MyObj& safe, bool c){
+ MyObj s;
+ const MyObj* p = &safe;
+ if(c){
----------------
kashika0112 wrote:
Done
https://github.com/llvm/llvm-project/pull/165370
More information about the cfe-commits
mailing list