From owner-svn-src-all@FreeBSD.ORG Sat Nov 16 01:03:58 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0B33FCC7; Sat, 16 Nov 2013 01:03:58 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EDFAC2145; Sat, 16 Nov 2013 01:03:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rAG13vAe062568; Sat, 16 Nov 2013 01:03:57 GMT (envelope-from pfg@svn.freebsd.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id rAG13uh0062561; Sat, 16 Nov 2013 01:03:56 GMT (envelope-from pfg@svn.freebsd.org) Message-Id: <201311160103.rAG13uh0062561@svn.freebsd.org> From: "Pedro F. Giffuni" Date: Sat, 16 Nov 2013 01:03:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r258204 - in head/contrib/gcc: . cp doc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Nov 2013 01:03:58 -0000 Author: pfg Date: Sat Nov 16 01:03:56 2013 New Revision: 258204 URL: http://svnweb.freebsd.org/changeset/base/258204 Log: gcc: Add a new option -Wvla to warn variable length array. Obtained from: gcc 4.3 (rev. 122851; GPLv2) MFC after: 3 weeks Modified: head/contrib/gcc/ChangeLog.gcc43 head/contrib/gcc/c-decl.c head/contrib/gcc/c.opt head/contrib/gcc/cp/decl.c head/contrib/gcc/doc/invoke.texi Modified: head/contrib/gcc/ChangeLog.gcc43 ============================================================================== --- head/contrib/gcc/ChangeLog.gcc43 Sat Nov 16 00:31:32 2013 (r258203) +++ head/contrib/gcc/ChangeLog.gcc43 Sat Nov 16 01:03:56 2013 (r258204) @@ -49,6 +49,14 @@ * config/i386/i386.c (override_options): Likewise. * doc/invoke.texi: Likewise. +2007-03-12 Seongbae Park + + * c-decl.c (warn_variable_length_array): New function. + Refactored from grokdeclarator to handle warn_vla + and handle unnamed array case. + (grokdeclarator): Refactored VLA warning case. + * c.opt (Wvla): New flag. + 2007-03-11 Ian Lance Taylor (r122831 - partial) * tree-vrp.c (vrp_int_const_binop): Handle PLUS_EXPR and Modified: head/contrib/gcc/c-decl.c ============================================================================== --- head/contrib/gcc/c-decl.c Sat Nov 16 00:31:32 2013 (r258203) +++ head/contrib/gcc/c-decl.c Sat Nov 16 01:03:56 2013 (r258204) @@ -3931,6 +3931,61 @@ check_bitfield_type_and_width (tree *typ } + +/* Print warning about variable length array if necessary. */ + +static void +warn_variable_length_array (const char *name, tree size) +{ + int ped = !flag_isoc99 && pedantic && warn_vla != 0; + int const_size = TREE_CONSTANT (size); + + if (ped) + { + if (const_size) + { + if (name) + pedwarn ("ISO C90 forbids array %qs whose size " + "can%'t be evaluated", + name); + else + pedwarn ("ISO C90 forbids array whose size " + "can%'t be evaluated"); + } + else + { + if (name) + pedwarn ("ISO C90 forbids variable length array %qs", + name); + else + pedwarn ("ISO C90 forbids variable length array"); + } + } + else if (warn_vla > 0) + { + if (const_size) + { + if (name) + warning (OPT_Wvla, + "the size of array %qs can" + "%'t be evaluated", name); + else + warning (OPT_Wvla, + "the size of array can %'t be evaluated"); + } + else + { + if (name) + warning (OPT_Wvla, + "variable length array %qs is used", + name); + else + warning (OPT_Wvla, + "variable length array is used"); + } + } +} + /* Given declspecs and a declarator, determine the name and type of the object declared and construct a ..._DECL node for it. @@ -4329,17 +4384,7 @@ grokdeclarator (const struct c_declarato nonconstant even if it is (eg) a const variable with known value. */ size_varies = 1; - - if (!flag_isoc99 && pedantic) - { - if (TREE_CONSTANT (size)) - pedwarn ("ISO C90 forbids array %qs whose size " - "can%'t be evaluated", - name); - else - pedwarn ("ISO C90 forbids variable-size array %qs", - name); - } + warn_variable_length_array (orig_name, size); if (warn_variable_decl) warning (0, "variable-sized array %qs", name); } Modified: head/contrib/gcc/c.opt ============================================================================== --- head/contrib/gcc/c.opt Sat Nov 16 00:31:32 2013 (r258203) +++ head/contrib/gcc/c.opt Sat Nov 16 01:03:56 2013 (r258204) @@ -432,6 +432,10 @@ Wvariadic-macros C ObjC C++ ObjC++ Do not warn about using variadic macros when -pedantic +Wvla +C ObjC C++ ObjC++ Var(warn_vla) Init(-1) Warning +Warn if a variable length array is used + Wwrite-strings C ObjC C++ ObjC++ Var(warn_write_strings) In C++, nonzero means warn about deprecated conversion from string literals to `char *'. In C, similar warning, except that the conversion is of course not deprecated by the ISO C standard. Modified: head/contrib/gcc/cp/decl.c ============================================================================== --- head/contrib/gcc/cp/decl.c Sat Nov 16 00:31:32 2013 (r258203) +++ head/contrib/gcc/cp/decl.c Sat Nov 16 01:03:56 2013 (r258204) @@ -6702,12 +6702,21 @@ compute_array_index_type (tree name, tre error ("size of array is not an integral constant-expression"); size = integer_one_node; } - else if (pedantic) + else if (pedantic && warn_vla != 0) { if (name) - pedwarn ("ISO C++ forbids variable-size array %qD", name); + pedwarn ("ISO C++ forbids variable length array %qD", name); else - pedwarn ("ISO C++ forbids variable-size array"); + pedwarn ("ISO C++ forbids variable length array"); + } + else if (warn_vla > 0) + { + if (name) + warning (OPT_Wvla, + "variable length array %qD is used", name); + else + warning (OPT_Wvla, + "variable length array is used"); } if (processing_template_decl && !TREE_CONSTANT (size)) Modified: head/contrib/gcc/doc/invoke.texi ============================================================================== --- head/contrib/gcc/doc/invoke.texi Sat Nov 16 00:31:32 2013 (r258203) +++ head/contrib/gcc/doc/invoke.texi Sat Nov 16 01:03:56 2013 (r258204) @@ -230,7 +230,8 @@ in the following sections. -Wsystem-headers -Wtrigraphs -Wundef -Wuninitialized @gol -Wunknown-pragmas -Wno-pragmas -Wunreachable-code @gol -Wunused -Wunused-function -Wunused-label -Wunused-parameter @gol --Wunused-value -Wunused-variable -Wvariadic-macros @gol +-Wunused-value -Wunused-variable @gol +-Wvariadic-macros -Wvla @gol -Wvolatile-register-var -Wwrite-strings} @item C-only Warning Options @@ -3201,6 +3202,13 @@ Warn if variadic macros are used in peda alternate syntax when in pedantic ISO C99 mode. This is default. To inhibit the warning messages, use @option{-Wno-variadic-macros}. +@item -Wvla +@opindex Wvla +@opindex Wno-vla +Warn if variable length array is used in the code. +@option{-Wno-vla} will prevent the @option{-pedantic} warning of +the variable length array. + @item -Wvolatile-register-var @opindex Wvolatile-register-var @opindex Wno-volatile-register-var