This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix -Wdisallowed-function-list=* (PR c++/39554)


Last one bounced. Re-sending to gcc-patches as a plain-text email:

On Thu, Mar 26, 2009 at 11:14 AM, Raksit Ashok <raksit@google.com> wrote:
> On Thu, Mar 26, 2009 at 8:57 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>>
>> On Thu, Mar 26, 2009 at 01:08:43PM +0100, Richard Guenther wrote:
>> > Can we just make this new warning C only then?
>>
>> Or just remove it altogether? ?Comparison of function names is problematic
>> and we have e.g. the deprecated attribute which can be used very well for
>> what was meant to be done.
>>
>> #include <alloca.h>
>> #undef alloca
>> extern __typeof (alloca) alloca __attribute__((deprecated));
>>
>> ...
>>
>> void foo (int i)
>> {
>> ?void *p = alloca (i);
>> }
>
> Jacub, many thanks for coming up with a fix for the ICE.
> You are right in saying that the reason for adding this warning was to
> disallow alloca's. So our use case is
> "-Wdisallowed-function-list=__builtin_alloca" which works well for c, c++.
> The problem with the "__attribute__((deprecated))" solution is where you put
> this? For a given project, you could find one base header file which is
> include everywhere, and put it there -- but what if we wanted to enforce
> this across 1000s of projects, etc..
>
>>
>> works well for me, you can even include other system headers after this
>> just fine. ?Alternative patch to remove it, bootstrapped/regtested on
>> x86_64-linux and i686-linux.
>>
>> 2009-03-26 ?Jakub Jelinek ?<jakub@redhat.com>
>>
>> ? ? ? ?PR c++/39554
>> ? ? ? ?* opts.c (warning_disallowed_functions, warn_disallowed_functions,
>> ? ? ? ?warn_if_disallowed_function_p): Removed.
>> ? ? ? ?(common_handle_option): Don't handle
>> OPT_Wdisallowed_function_list_.
>> ? ? ? ?* c-parser.c (c_parser_postfix_expression_after_primary): Don't
>> call
>> ? ? ? ?warning_if_disallowed_function_p.
>> ? ? ? ?* flags.h (warn_if_disallowed_function_p,
>> ? ? ? ?warn_disallowed_functions): Removed.
>> ? ? ? ?* common.opt (Wdisallowed-function-list=): Removed.
>> ? ? ? ?* doc/invoke.texi (-Wdisallowed-function-list=): Removed.
>>
>> ? ? ? ?* parser.c (cp_parser_postfix_expression): Don't call
>> ? ? ? ?warning_if_disallowed_function_p.
>>
>> ? ? ? ?* gcc.dg/wdisallowed-functions-1.c: Removed.
>> ? ? ? ?* gcc.dg/wdisallowed-functions-2.c: Removed.
>> ? ? ? ?* g++.dg/warn/Wdisallowed-functions-1.C: Removed.
>> ? ? ? ?* g++.dg/warn/Wdisallowed-functions-2.C: Removed.
>>
>> --- gcc/opts.c.jj ? ? ? 2009-03-26 14:08:22.000000000 +0100
>> +++ gcc/opts.c ?2009-03-26 14:32:41.000000000 +0100
>> @@ -368,12 +368,6 @@ DEF_VEC_ALLOC_P(const_char_p,heap);
>>
>> ?static VEC(const_char_p,heap) *ignored_options;
>>
>> -/* Function calls disallowed under -Wdisallowed-function-list=... ?*/
>> -static VEC(char_p,heap) *warning_disallowed_functions;
>> -
>> -/* If -Wdisallowed-function-list=... ?*/
>> -bool warn_disallowed_functions = false;
>> -
>> ?/* Input file names. ?*/
>> ?const char **in_fnames;
>> ?unsigned num_in_fnames;
>> @@ -740,31 +734,6 @@ flag_instrument_functions_exclude_p (tre
>> ? return false;
>> ?}
>>
>> -
>> -/* Return whether this function call is disallowed. ?*/
>> -void
>> -warn_if_disallowed_function_p (const_tree exp)
>> -{
>> - ?if (TREE_CODE(exp) == CALL_EXPR
>> - ? ? ?&& VEC_length (char_p, warning_disallowed_functions) > 0)
>> - ? ?{
>> - ? ? ?int i;
>> - ? ? ?char *s;
>> - ? ? ?const char *fnname =
>> - ? ? ? ? ?IDENTIFIER_POINTER (DECL_NAME (get_callee_fndecl (exp)));
>> - ? ? ?for (i = 0; VEC_iterate (char_p, warning_disallowed_functions, i,
>> s);
>> - ? ? ? ? ? ++i)
>> - ? ? ? ?{
>> - ? ? ? ? ?if (strcmp (fnname, s) == 0)
>> - ? ? ? ? ? ?{
>> - ? ? ? ? ? ? ?warning (OPT_Wdisallowed_function_list_,
>> - ? ? ? ? ? ? ? ? ? ? ? "disallowed call to %qs", fnname);
>> - ? ? ? ? ? ? ?break;
>> - ? ? ? ? ? ?}
>> - ? ? ? ?}
>> - ? ?}
>> -}
>> -
>> ?/* Decode and handle the vector of command line options. ?LANG_MASK
>> ? ?contains has a single bit set representing the current
>> ? ?language. ?*/
>> @@ -1627,12 +1596,6 @@ common_handle_option (size_t scode, cons
>> ? ? ? set_Wextra (value);
>> ? ? ? break;
>>
>> - ? ?case OPT_Wdisallowed_function_list_:
>> - ? ? ?warn_disallowed_functions = true;
>> - ? ? ?add_comma_separated_to_vector
>> - ? ? ? (&warning_disallowed_functions, arg);
>> - ? ? ?break;
>> -
>> ? ? case OPT_Werror_:
>> ? ? ? enable_warning_as_error (arg, value, lang_mask);
>> ? ? ? break;
>> --- gcc/cp/parser.c.jj ?2009-03-23 22:05:14.000000000 +0100
>> +++ gcc/cp/parser.c ? ? 2009-03-26 14:34:24.000000000 +0100
>> @@ -4823,9 +4823,6 @@ cp_parser_postfix_expression (cp_parser
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?koenig_p,
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?tf_warning_or_error);
>>
>> - ? ? ? ? ? ?if (warn_disallowed_functions)
>> - ? ? ? ? ? ? ?warn_if_disallowed_function_p (postfix_expression);
>> -
>> ? ? ? ? ? ?/* The POSTFIX_EXPRESSION is certainly no longer an id. ?*/
>> ? ? ? ? ? ?idk = CP_ID_KIND_NONE;
>> ? ? ? ? ?}
>> --- gcc/c-parser.c.jj ? 2009-03-23 22:05:14.000000000 +0100
>> +++ gcc/c-parser.c ? ? ?2009-03-26 14:33:29.000000000 +0100
>> @@ -5584,8 +5584,6 @@ c_parser_postfix_expression_after_primar
>> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "expected %<)%>");
>> ? ? ? ? ?expr.value = build_function_call (expr.value, exprlist);
>> ? ? ? ? ?expr.original_code = ERROR_MARK;
>> - ? ? ? ? ?if (warn_disallowed_functions)
>> - ? ? ? ? ? ?warn_if_disallowed_function_p (expr.value);
>> ? ? ? ? ?break;
>> ? ? ? ?case CPP_DOT:
>> ? ? ? ? ?/* Structure element reference. ?*/
>> --- gcc/flags.h.jj ? ? ?2009-03-02 16:22:16.000000000 +0100
>> +++ gcc/flags.h 2009-03-26 14:32:05.000000000 +0100
>> @@ -1,6 +1,6 @@
>> ?/* Compilation switch flag definitions for GCC.
>> ? ?Copyright (C) 1987, 1988, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
>> 2002,
>> - ? 2003, 2004, 2005, 2006, 2007, 2008
>> + ? 2003, 2004, 2005, 2006, 2007, 2008, 2009
>> ? ?Free Software Foundation, Inc.
>>
>> ?This file is part of GCC.
>> @@ -310,13 +310,6 @@ extern enum stack_check_type flag_stack_
>> ? ?instrumentation. ?*/
>> ?extern bool flag_instrument_functions_exclude_p (tree fndecl);
>>
>> -/* Emit warning if the function call is disallowed under
>> - ? -Wdisallowed-function-list=... ?*/
>> -extern void warn_if_disallowed_function_p (const_tree fncall);
>> -
>> -/* True, if the -Wdisallowed-function-list=... option has been specified.
>> ?*/
>> -extern bool warn_disallowed_functions;
>> -
>> ?/* True if the given mode has a NaN representation and the treatment of
>> ? ?NaN operands is important. ?Certain optimizations, such as folding
>> ? ?x * 0 into 0, are not correct for NaN operands, and are normally
>> --- gcc/common.opt.jj ? 2009-03-02 16:22:19.000000000 +0100
>> +++ gcc/common.opt ? ? ?2009-03-26 14:33:05.000000000 +0100
>> @@ -94,10 +94,6 @@ Wdisabled-optimization
>> ?Common Var(warn_disabled_optimization) Warning
>> ?Warn when an optimization pass is disabled
>>
>> -Wdisallowed-function-list=
>> -Common RejectNegative Joined Warning
>> -Warn on calls to these functions
>> -
>> ?Werror
>> ?Common Var(warnings_are_errors)
>> ?Treat all warnings as errors
>> --- gcc/doc/invoke.texi.jj ? ? ?2009-03-25 21:17:55.000000000 +0100
>> +++ gcc/doc/invoke.texi 2009-03-26 14:31:23.000000000 +0100
>> @@ -233,7 +233,6 @@ Objective-C and Objective-C++ Dialects}.
>> ?-Wchar-subscripts -Wclobbered ?-Wcomment @gol
>> ?-Wconversion ?-Wcoverage-mismatch ?-Wno-deprecated ?@gol
>> ?-Wno-deprecated-declarations -Wdisabled-optimization ?@gol
>> --Wdisallowed-function-list=@var{sym},@var{sym},@dots{} @gol
>> ?-Wno-div-by-zero -Wempty-body ?-Wenum-compare -Wno-endif-labels @gol
>> ?-Werror ?-Werror=* @gol
>> ?-Wfatal-errors ?-Wfloat-equal ?-Wformat ?-Wformat=2 @gol
>> @@ -4189,13 +4188,6 @@ minimum maximum, so we do not diagnose o
>>
>> ?This option is implied by @option{-pedantic}, and can be disabled with
>> ?@option{-Wno-overlength-strings}.
>> -
>> -@item -Wdisallowed-function-list=@var{sym},@var{sym},@dots{}
>> -@opindex Wdisallowed-function-list
>> -
>> -If any of @var{sym} is called, GCC will issue a warning. This can be
>> useful
>> -in enforcing coding conventions that ban calls to certain functions, for
>> -example, @code{alloca}, @code{malloc}, etc.
>> ?@end table
>>
>> ?@node Debugging Options
>> --- gcc/testsuite/gcc.dg/wdisallowed-functions-1.c.jj ? 2008-09-30
>> 16:54:49.000000000 +0200
>> +++ gcc/testsuite/gcc.dg/wdisallowed-functions-1.c ? ? ?2009-03-26
>> 14:35:24.000000000 +0100
>> @@ -1,7 +0,0 @@
>> -/* { dg-do compile } */
>> -/* { dg-options "-Wdisallowed-function-list=foobar" } */
>> -
>> -int foobar (int i)
>> -{
>> - ?return (i * 5);
>> -}
>> --- gcc/testsuite/gcc.dg/wdisallowed-functions-2.c.jj ? 2008-09-30
>> 16:54:48.000000000 +0200
>> +++ gcc/testsuite/gcc.dg/wdisallowed-functions-2.c ? ? ?2009-03-26
>> 14:35:24.000000000 +0100
>> @@ -1,12 +0,0 @@
>> -/* { dg-do compile } */
>> -/* { dg-options "-Wdisallowed-function-list=foo,foobar,bar,foobar" } */
>> -
>> -int foobar (int i)
>> -{
>> - ?return (i * 5);
>> -}
>> -
>> -int foobar1 (int i)
>> -{
>> - ?return foobar (i); ?/* { dg-warning "disallowed call to 'foobar'" } */
>> -}
>> --- gcc/testsuite/g++.dg/warn/Wdisallowed-functions-1.C.jj ? ? ?2008-09-30
>> 16:55:11.000000000 +0200
>> +++ gcc/testsuite/g++.dg/warn/Wdisallowed-functions-1.C 2009-03-26
>> 14:35:01.000000000 +0100
>> @@ -1,7 +0,0 @@
>> -/* { dg-do compile } */
>> -/* { dg-options "-Wdisallowed-function-list=foobar" } */
>> -
>> -int foobar (int i)
>> -{
>> - ?return (i * 5);
>> -}
>> --- gcc/testsuite/g++.dg/warn/Wdisallowed-functions-2.C.jj ? ? ?2008-09-30
>> 16:55:11.000000000 +0200
>> +++ gcc/testsuite/g++.dg/warn/Wdisallowed-functions-2.C 2009-03-26
>> 14:35:05.000000000 +0100
>> @@ -1,12 +0,0 @@
>> -/* { dg-do compile } */
>> -/* { dg-options "-Wdisallowed-function-list=foo,foobar,bar,foobar" } */
>> -
>> -int foobar (int i)
>> -{
>> - ?return (i * 5);
>> -}
>> -
>> -int foobar1 (int i)
>> -{
>> - ?return foobar (i); ?/* { dg-warning "disallowed call to 'foobar'" } */
>> -}
>>
>>
>> ? ? ? ?Jakub
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]