* [PATCH] PR middle-end/38509: add -Wfree-nonheap-object warning option
@ 2011-08-12 17:27 Mark Heffernan
2011-08-22 7:23 ` Mark Heffernan
0 siblings, 1 reply; 3+ messages in thread
From: Mark Heffernan @ 2011-08-12 17:27 UTC (permalink / raw)
To: GCC Patches
This patch adds an option for enabling/disabling the warning for
attempting to free nonheap objects (PR/38509). The warning is
imprecise and can issue false positives.
Bootstrapped on x86-64. Ok for trunk?
Mark
2011-08-11 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.
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi (revision 177684)
+++ gcc/doc/invoke.texi (working copy)
@@ -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 array
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.
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c (revision 177684)
+++ gcc/builtins.c (working copy)
@@ -6087,7 +6087,8 @@ expand_builtin (tree exp, rtx target, rt
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 */
@@ -11863,11 +11864,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: gcc/common.opt
===================================================================
--- gcc/common.opt (revision 177684)
+++ gcc/common.opt (working copy)
@@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PR middle-end/38509: add -Wfree-nonheap-object warning option
2011-08-12 17:27 [PATCH] PR middle-end/38509: add -Wfree-nonheap-object warning option Mark Heffernan
@ 2011-08-22 7:23 ` Mark Heffernan
2011-08-22 19:13 ` Diego Novillo
0 siblings, 1 reply; 3+ messages in thread
From: Mark Heffernan @ 2011-08-22 7:23 UTC (permalink / raw)
To: GCC Patches; +Cc: Diego Novillo
Ping?
Mark
On Fri, Aug 12, 2011 at 9:41 AM, Mark Heffernan <meheff@google.com> wrote:
> This patch adds an option for enabling/disabling the warning for
> attempting to free nonheap objects (PR/38509). The warning is
> imprecise and can issue false positives.
>
> Bootstrapped on x86-64. Ok for trunk?
>
> Mark
>
> 2011-08-11 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.
>
>
>
> Index: gcc/doc/invoke.texi
> ===================================================================
> --- gcc/doc/invoke.texi (revision 177684)
> +++ gcc/doc/invoke.texi (working copy)
> @@ -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 array
> 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.
>
> Index: gcc/builtins.c
> ===================================================================
> --- gcc/builtins.c (revision 177684)
> +++ gcc/builtins.c (working copy)
> @@ -6087,7 +6087,8 @@ expand_builtin (tree exp, rtx target, rt
> 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 */
> @@ -11863,11 +11864,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: gcc/common.opt
> ===================================================================
> --- gcc/common.opt (revision 177684)
> +++ gcc/common.opt (working copy)
> @@ -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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PR middle-end/38509: add -Wfree-nonheap-object warning option
2011-08-22 7:23 ` Mark Heffernan
@ 2011-08-22 19:13 ` Diego Novillo
0 siblings, 0 replies; 3+ messages in thread
From: Diego Novillo @ 2011-08-22 19:13 UTC (permalink / raw)
To: Mark Heffernan; +Cc: GCC Patches
On 11-08-21 18:14 , Mark Heffernan wrote:
> Ping?
>
> Mark
>
> On Fri, Aug 12, 2011 at 9:41 AM, Mark Heffernan<meheff@google.com> wrote:
>> This patch adds an option for enabling/disabling the warning for
>> attempting to free nonheap objects (PR/38509). The warning is
>> imprecise and can issue false positives.
>>
>> Bootstrapped on x86-64. Ok for trunk?
>>
>> Mark
>>
>> 2011-08-11 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.
OK.
Diego.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-08-22 18:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-12 17:27 [PATCH] PR middle-end/38509: add -Wfree-nonheap-object warning option Mark Heffernan
2011-08-22 7:23 ` Mark Heffernan
2011-08-22 19:13 ` Diego Novillo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).