Eliminate 'address of local variable returned' static analyzer warning
authorIvan Maidanski <ivmai@mail.ru>
Wed, 5 Oct 2016 08:32:00 +0000 (11:32 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 5 Oct 2016 08:32:00 +0000 (11:32 +0300)
* mark_rts.c [__GNUC__ >= 4] (GC_approx_sp): Use
__builtin_frame_address(0) instead of &sp (but still write the value to
the volatile local variable to force stack to grow if necessary).
* tools/setjmp_t.c [__GNUC__ >= 4] (nested_sp): Return
__builtin_frame_address(0) instead of sp.

mark_rts.c
tools/setjmp_t.c

index a5b8b08..055c1dc 100644 (file)
@@ -386,13 +386,15 @@ STATIC void GC_remove_tmp_roots(void)
 GC_INNER ptr_t GC_approx_sp(void)
 {
     volatile word sp;
-    sp = (word)&sp;
+#   if defined(__GNUC__) && (__GNUC__ >= 4)
+        sp = (word)__builtin_frame_address(0);
+#   else
+        sp = (word)&sp;
+#   endif
                 /* Also force stack to grow if necessary. Otherwise the */
                 /* later accesses might cause the kernel to think we're */
                 /* doing something wrong.                               */
     return((ptr_t)sp);
-                /* GNU C: alternatively, we may return the value of     */
-                /*__builtin_frame_address(0).                           */
 }
 
 /*
index 1bd715d..c71aea6 100644 (file)
@@ -62,9 +62,13 @@ struct {
 
 word nested_sp(void)
 {
+# if defined(__GNUC__) && (__GNUC__ >= 4)
+    return (word)__builtin_frame_address(0);
+# else
     volatile word sp;
     sp = (word)(&sp);
     return sp;
+# endif
 }
 
 /* To prevent nested_sp inlining. */