]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/38509 (Bogus "attempt to free a non-heap object" warning)
authorMark Heffernan <meheff@google.com>
Tue, 23 Aug 2011 18:06:42 +0000 (18:06 +0000)
committerMark Heffernan <meheff@gcc.gnu.org>
Tue, 23 Aug 2011 18:06:42 +0000 (18:06 +0000)
2011-08-23  Mark Heffernan  <meheff@google.com>

        PR middle-end/38509
        * common.opt (Wfree-nonheap-object): New option.
        * doc/invoke.texi (Warning options): Document -Wfree-nonheap-object.
        * builtins.c (maybe_emit_free_warning): Add OPT_Wfree_nonheap_object
        to warning.
        (expand_builtin): Make warning conditional.

From-SVN: r178004

gcc/ChangeLog
gcc/builtins.c
gcc/common.opt
gcc/doc/invoke.texi

index 2fed6fa063ce01f6b2ae3109f59a9ffc3a1e5a8d..d65f7522fd3ce2464e998cf569b232886aa363ac 100644 (file)
@@ -1,3 +1,12 @@
+2011-08-23  Mark Heffernan  <meheff@google.com>
+
+       PR middle-end/38509
+       * common.opt (Wfree-nonheap-object): New option.
+       * doc/invoke.texi (Warning options): Document -Wfree-nonheap-object.
+       * builtins.c (maybe_emit_free_warning): Add OPT_Wfree_nonheap_object
+       to warning.
+       (expand_builtin): Make warning conditional.
+
 2011-08-23  Uros Bizjak  <ubizjak@gmail.com>
 
        * config/i386/i386.md (type): Add imulx, ishiftx and rotatex.
index 1f263073fe54a6feeef9462bbaa4b6b4d413a610..b79ce6f4a7479fb7dba887d53de05c923009eb1c 100644 (file)
@@ -6096,7 +6096,8 @@ expand_builtin (tree exp, rtx target, rtx subtarget, enum machine_mode mode,
       break;
 
     case BUILT_IN_FREE:
-      maybe_emit_free_warning (exp);
+      if (warn_free_nonheap_object)
+       maybe_emit_free_warning (exp);
       break;
 
     default:   /* just do library call, if unknown builtin */
@@ -11915,11 +11916,11 @@ maybe_emit_free_warning (tree exp)
     return;
 
   if (SSA_VAR_P (arg))
-    warning_at (tree_nonartificial_location (exp),
-               0, "%Kattempt to free a non-heap object %qD", exp, arg);
+    warning_at (tree_nonartificial_location (exp), OPT_Wfree_nonheap_object,
+               "%Kattempt to free a non-heap object %qD", exp, arg);
   else
-    warning_at (tree_nonartificial_location (exp),
-               0, "%Kattempt to free a non-heap object", exp);
+    warning_at (tree_nonartificial_location (exp), OPT_Wfree_nonheap_object,
+               "%Kattempt to free a non-heap object", exp);
 }
 
 /* Fold a call to __builtin_object_size with arguments PTR and OST,
index 63331d30ecc4ac313dca575c7407ec3844c27fe9..ba3e254dd1432febf773be72df9bf2e74c4296fb 100644 (file)
@@ -543,6 +543,10 @@ Wframe-larger-than=
 Common RejectNegative Joined UInteger
 -Wframe-larger-than=<number>   Warn if a function's stack frame requires more than <number> bytes
 
+Wfree-nonheap-object
+Common Var(warn_free_nonheap_object) Init(1) Warning
+Warn when attempting to free a non-heap object
+
 Winline
 Common Var(warn_inline) Warning
 Warn when an inlined function cannot be inlined
index cbf42766fe63dae58742806a36c13b98addc304c..62a841cca43521ece20ed4eb6b61cb13db44205b 100644 (file)
@@ -244,7 +244,8 @@ Objective-C and Objective-C++ Dialects}.
 -Wfatal-errors  -Wfloat-equal  -Wformat  -Wformat=2 @gol
 -Wno-format-contains-nul -Wno-format-extra-args -Wformat-nonliteral @gol
 -Wformat-security  -Wformat-y2k @gol
--Wframe-larger-than=@var{len} -Wjump-misses-init -Wignored-qualifiers @gol
+-Wframe-larger-than=@var{len} -Wno-free-nonheap-object -Wjump-misses-init @gol
+-Wignored-qualifiers @gol
 -Wimplicit  -Wimplicit-function-declaration  -Wimplicit-int @gol
 -Winit-self  -Winline -Wmaybe-uninitialized @gol
 -Wno-int-to-pointer-cast -Wno-invalid-offsetof @gol
@@ -3960,6 +3961,12 @@ via @code{alloca}, variable-length arrays, or related constructs
 is not included by the compiler when determining
 whether or not to issue a warning.
 
+@item -Wno-free-nonheap-object
+@opindex Wno-free-nonheap-object
+@opindex Wfree-nonheap-object
+Do not warn when attempting to free an object which was not allocated
+on the heap.
+
 @item -Wstack-usage=@var{len}
 @opindex Wstack-usage
 Warn if the stack usage of a function might be larger than @var{len} bytes.