summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2016-10-05 11:32:00 +0300
committerIvan Maidanski <ivmai@mail.ru>2016-10-05 11:32:00 +0300
commit8a72b0059569406bfc9dd9811f6ef48206ccc75a (patch)
tree3947dd3f83f81e3c14e5a980984f3d0c0661e84c
parent43c543923af72ad495f8c44eaab25ceebe379c4f (diff)
downloadbdwgc-8a72b0059569406bfc9dd9811f6ef48206ccc75a.tar.gz
Eliminate 'address of local variable returned' static analyzer warning
* 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.
-rw-r--r--mark_rts.c8
-rw-r--r--tools/setjmp_t.c4
2 files changed, 9 insertions, 3 deletions
diff --git a/mark_rts.c b/mark_rts.c
index a5b8b08a..055c1dce 100644
--- a/mark_rts.c
+++ b/mark_rts.c
@@ -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). */
}
/*
diff --git a/tools/setjmp_t.c b/tools/setjmp_t.c
index 1bd715dd..c71aea63 100644
--- a/tools/setjmp_t.c
+++ b/tools/setjmp_t.c
@@ -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. */