[clang] [LifetimeSafety] Handle escape through assignment to global storage (PR #181646)
Gábor Horváth via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 3 04:46:50 PST 2026
================
@@ -113,12 +113,31 @@ View escape_through_unannotated_call(const MyObj& in [[clang::noescape]]) { // e
return no_annotation_identity(in); // expected-note {{returned here}}
}
-View global_view;
+View global_view; // expected-note {{escapes to this global storage}}
-// FIXME: Escaping through a global variable is not detected.
-void escape_through_global_var(const MyObj& in [[clang::noescape]]) {
+void escape_through_global_var(const MyObj& in [[clang::noescape]]) { // expected-warning {{parameter is marked [[clang::noescape]] but escapes}}
global_view = in;
}
+struct ObjWithStaticField {
+ static int *static_field; // expected-note {{escapes to this global storage}}
+};
+
+void escape_to_static_data_member(int *data [[clang::noescape]]) { // expected-warning {{parameter is marked [[clang::noescape]] but escapes}}
+ ObjWithStaticField::static_field = data;
+}
+
+
+
+void escape_through_static_local(int *data [[clang::noescape]]) { // expected-warning {{parameter is marked [[clang::noescape]] but escapes}}
+ static int *static_local; // expected-note {{escapes to this global storage}}
+ static_local = data;
+}
+
+thread_local int *thread_local_storage; // expected-note {{escapes to this global storage}}
+
+void escape_through_thread_local(int *data [[clang::noescape]]) { // expected-warning {{parameter is marked [[clang::noescape]] but escapes}}
+ thread_local_storage = data;
----------------
Xazax-hun wrote:
Sorry, I just realized how easy to misunderstand my point here. What I meant was, I wonder if for `noescape` arguments we might want to warn as soon as the assignment to the global happens? That being said, I think it might be fine not to do that if we cover the `save_globals` style scenario later on down the line.
https://github.com/llvm/llvm-project/pull/181646
More information about the cfe-commits
mailing list