Commit a2bec818 by Daniel Jacobowitz Committed by Daniel Jacobowitz

Makefile.in (c-format.o): Depend on c-format.h.

gcc/
	* Makefile.in (c-format.o): Depend on c-format.h.
	* c-format.h: New file.
	(struct format_char_info): Add CHAIN member.
	* c-format.c: Move some types and constants to c-format.h.
	(format_type_error): Set to -1.
	(struct function_format_info): Use an int for format_type.
	(decode_format_type): Return an int.  Return format_type_error
	on error.
	(print_char_table, asm_fprintf_char_table, gcc_diag_char_table)
	(gcc_diag_char_table, gcc_cdiag_char_table, gcc_cxxdiag_char_table)
	(scan_char_table, time_char_table, monetary_char_table): Initialize
	CHAIN to NULL.
	(n_format_types): New variable.
	(check_format_info_main): Handle CHAIN in format_char_info.
	(handle_format_attribute): Handle TARGET_FORMAT_TYPES and
	TARGET_N_FORMAT_TYPES.
	* config.gcc (i[34567]86-*-solaris2*, sparc64-*-solaris2*)
	(sparc-*-solaris2*): Include config/t-sol2 and config/sol2-c.c.
	* config/sol2-c.c: New file.
	* config/t-sol2: New file.
	* config/sol2.h (TARGET_N_FORMAT_TYPES, TARGET_FORMAT_TYPES): Define.
	* config/sparc/elf.h, config/sparc/sp64-elf.h: Undefine
	TARGET_N_FORMAT_TYPES and TARGET_FORMAT_TYPES.

	* doc/extend.texi (Target Format Checks): New section.
	(Function Attributes): Mention it.
	* doc/invoke.texi: Mention target format checks.
	* doc/sourcebuild.texi: Mention target format checks.
	* dc/tm.texi (Misc): Document TARGET_N_FORMAT_TYPES and
	TARGET_FORMAT_TYPES.
testsuite/
	* gcc.dg/format/cmn-err-1.c: New test.

From-SVN: r84920
parent a38e09bc
2004-07-19 Daniel Jacobowitz <dan@debian.org>
* Makefile.in (c-format.o): Depend on c-format.h.
* c-format.h: New file.
(struct format_char_info): Add CHAIN member.
* c-format.c: Move some types and constants to c-format.h.
(format_type_error): Set to -1.
(struct function_format_info): Use an int for format_type.
(decode_format_type): Return an int. Return format_type_error
on error.
(print_char_table, asm_fprintf_char_table, gcc_diag_char_table)
(gcc_diag_char_table, gcc_cdiag_char_table, gcc_cxxdiag_char_table)
(scan_char_table, time_char_table, monetary_char_table): Initialize
CHAIN to NULL.
(n_format_types): New variable.
(check_format_info_main): Handle CHAIN in format_char_info.
(handle_format_attribute): Handle TARGET_FORMAT_TYPES and
TARGET_N_FORMAT_TYPES.
* config.gcc (i[34567]86-*-solaris2*, sparc64-*-solaris2*)
(sparc-*-solaris2*): Include config/t-sol2 and config/sol2-c.c.
* config/sol2-c.c: New file.
* config/t-sol2: New file.
* config/sol2.h (TARGET_N_FORMAT_TYPES, TARGET_FORMAT_TYPES): Define.
* config/sparc/elf.h, config/sparc/sp64-elf.h: Undefine
TARGET_N_FORMAT_TYPES and TARGET_FORMAT_TYPES.
* doc/extend.texi (Target Format Checks): New section.
(Function Attributes): Mention it.
* doc/invoke.texi: Mention target format checks.
* doc/sourcebuild.texi: Mention target format checks.
* dc/tm.texi (Misc): Document TARGET_N_FORMAT_TYPES and
TARGET_FORMAT_TYPES.
2004-07-19 Andreas Krebbel <krebbel1@de.ibm.com> 2004-07-19 Andreas Krebbel <krebbel1@de.ibm.com>
* config/s390/s390-protos.h (s390_return_address_offset): Prototype * config/s390/s390-protos.h (s390_return_address_offset): Prototype
......
...@@ -1440,7 +1440,7 @@ attribs.o : attribs.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(FL ...@@ -1440,7 +1440,7 @@ attribs.o : attribs.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(FL
builtin-types.def $(TARGET_H) langhooks.h builtin-types.def $(TARGET_H) langhooks.h
c-format.o : c-format.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) langhooks.h \ c-format.o : c-format.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) langhooks.h \
$(C_COMMON_H) $(FLAGS_H) toplev.h intl.h $(DIAGNOSTIC_H) $(C_COMMON_H) $(FLAGS_H) toplev.h intl.h $(DIAGNOSTIC_H) c-format.h
c-semantics.o : c-semantics.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ c-semantics.o : c-semantics.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
$(C_TREE_H) $(FLAGS_H) toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \ $(C_TREE_H) $(FLAGS_H) toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) \
......
This diff is collapsed. Click to expand it.
...@@ -972,7 +972,9 @@ i[34567]86-*-sco3.2v5*) # 80386 running SCO Open Server 5 ...@@ -972,7 +972,9 @@ i[34567]86-*-sco3.2v5*) # 80386 running SCO Open Server 5
i[34567]86-*-solaris2*) i[34567]86-*-solaris2*)
xm_defines="SMALL_ARG_MAX" xm_defines="SMALL_ARG_MAX"
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h svr4.h i386/sysv4.h sol2.h i386/sol2.h" tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h svr4.h i386/sysv4.h sol2.h i386/sol2.h"
tmake_file="i386/t-sol2 t-svr4" tmake_file="t-sol2 i386/t-sol2 t-svr4"
c_target_objs="sol2-c.o"
cxx_target_objs="sol2-c.o"
if test x$gnu_ld = xyes; then if test x$gnu_ld = xyes; then
tmake_file="$tmake_file t-slibgcc-elf-ver" tmake_file="$tmake_file t-slibgcc-elf-ver"
else else
...@@ -1851,12 +1853,14 @@ sparc64-*-solaris2* | sparcv9-*-solaris2*) ...@@ -1851,12 +1853,14 @@ sparc64-*-solaris2* | sparcv9-*-solaris2*)
if test x$gas = xyes; then if test x$gas = xyes; then
tm_file="${tm_file} sparc/sol2-gas-bi.h" tm_file="${tm_file} sparc/sol2-gas-bi.h"
fi fi
tmake_file="sparc/t-sol2 sparc/t-sol2-64 sparc/t-crtfm" tmake_file="t-sol2 sparc/t-sol2 sparc/t-sol2-64 sparc/t-crtfm"
if test x$gnu_ld = xyes; then if test x$gnu_ld = xyes; then
tmake_file="$tmake_file t-slibgcc-elf-ver" tmake_file="$tmake_file t-slibgcc-elf-ver"
else else
tmake_file="$tmake_file t-slibgcc-sld" tmake_file="$tmake_file t-slibgcc-sld"
fi fi
c_target_objs="sol2-c.o"
cxx_target_objs="sol2-c.o"
extra_parts="crt1.o crti.o crtn.o gcrt1.o crtbegin.o crtend.o" extra_parts="crt1.o crti.o crtn.o gcrt1.o crtbegin.o crtend.o"
case ${enable_threads}:${have_pthread_h}:${have_thread_h} in case ${enable_threads}:${have_pthread_h}:${have_thread_h} in
no:*:*) ;; no:*:*) ;;
...@@ -1870,7 +1874,7 @@ sparc-*-solaris2*) ...@@ -1870,7 +1874,7 @@ sparc-*-solaris2*)
if test x$gnu_ld = xyes; then if test x$gnu_ld = xyes; then
tm_file="${tm_file} sparc/sol2-gld.h" tm_file="${tm_file} sparc/sol2-gld.h"
fi fi
tmake_file="sparc/t-sol2 sparc/t-crtfm" tmake_file="t-sol2 sparc/t-sol2 sparc/t-crtfm"
if test x$gnu_ld = xyes; then if test x$gnu_ld = xyes; then
tmake_file="$tmake_file t-slibgcc-elf-ver" tmake_file="$tmake_file t-slibgcc-elf-ver"
else else
...@@ -1894,6 +1898,8 @@ sparc-*-solaris2*) ...@@ -1894,6 +1898,8 @@ sparc-*-solaris2*)
need_64bit_hwint=yes need_64bit_hwint=yes
;; ;;
esac esac
c_target_objs="sol2-c.o"
cxx_target_objs="sol2-c.o"
extra_parts="crt1.o crti.o crtn.o gcrt1.o gmon.o crtbegin.o crtend.o" extra_parts="crt1.o crti.o crtn.o gcrt1.o gmon.o crtbegin.o crtend.o"
case ${enable_threads}:${have_pthread_h}:${have_thread_h} in case ${enable_threads}:${have_pthread_h}:${have_thread_h} in
no:*:*) ;; no:*:*) ;;
......
/* Solaris support needed only by C/C++ frontends.
Copyright (C) 2004 Free Software Foundation, Inc.
Contributed by CodeSourcery, LLC.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tree.h"
#include "c-format.h"
#include "intl.h"
/* cmn_err only accepts "l" and "ll". */
static const format_length_info cmn_err_length_specs[] =
{
{ "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89 },
{ NULL, 0, 0, NULL, 0, 0 }
};
static const format_flag_spec cmn_err_flag_specs[] =
{
{ 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89 },
{ 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
{ 0, 0, 0, NULL, NULL, 0 }
};
static const format_flag_pair cmn_err_flag_pairs[] =
{
{ 0, 0, 0, 0 }
};
static const format_char_info bitfield_string_type =
{ "b", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL };
static const format_char_info cmn_err_char_table[] =
{
/* C89 conversion specifiers. */
{ "dD", 0, STD_C89, { T89_I, BADLEN, BADLEN, T89_L, T9L_LL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
{ "oOxX",0, STD_C89, { T89_UI, BADLEN, BADLEN, T89_UL, T9L_ULL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
{ "u", 0, STD_C89, { T89_UI, BADLEN, BADLEN, T89_UL, T9L_ULL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
{ "c", 0, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
{ "s", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "cR", NULL },
{ "b", 0, STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "", &bitfield_string_type },
{ NULL, 0, 0, NOLENGTHS, NULL, NULL, NULL }
};
const format_kind_info solaris_format_types[] = {
{ "cmn_err", cmn_err_length_specs, cmn_err_char_table, "", NULL,
cmn_err_flag_specs, cmn_err_flag_pairs,
FMT_FLAG_ARG_CONVERT|FMT_FLAG_EMPTY_PREC_OK,
'w', 0, 0, 0, 'L',
&integer_type_node, &integer_type_node
}
};
...@@ -205,3 +205,6 @@ __enable_execute_stack (void *addr) \ ...@@ -205,3 +205,6 @@ __enable_execute_stack (void *addr) \
perror ("mprotect of trampoline code"); \ perror ("mprotect of trampoline code"); \
} \ } \
} }
#define TARGET_N_FORMAT_TYPES 1
#define TARGET_FORMAT_TYPES solaris_format_types
...@@ -48,3 +48,7 @@ Boston, MA 02111-1307, USA. */ ...@@ -48,3 +48,7 @@ Boston, MA 02111-1307, USA. */
#undef SUN_INTEGER_MULTIPLY_64 #undef SUN_INTEGER_MULTIPLY_64
#define SUN_INTEGER_MULTIPLY_64 0 #define SUN_INTEGER_MULTIPLY_64 0
/* Don't include Solaris-specific format checks. */
#undef TARGET_N_FORMAT_TYPES
#undef TARGET_FORMAT_TYPES
...@@ -122,3 +122,7 @@ crtbegin.o%s \ ...@@ -122,3 +122,7 @@ crtbegin.o%s \
#undef PREFERRED_DEBUGGING_TYPE #undef PREFERRED_DEBUGGING_TYPE
#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
/* Don't include Solaris-specific format checks. */
#undef TARGET_N_FORMAT_TYPES
#undef TARGET_FORMAT_TYPES
# Solaris-specific format checking
sol2-c.o: $(srcdir)/config/sol2-c.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
tree.h c-format.h intl.h
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
$(srcdir)/config/sol2-c.c
...@@ -472,6 +472,7 @@ extensions, accepted by GCC in C89 mode and in C++. ...@@ -472,6 +472,7 @@ extensions, accepted by GCC in C89 mode and in C++.
* Offsetof:: Special syntax for implementing @code{offsetof}. * Offsetof:: Special syntax for implementing @code{offsetof}.
* Other Builtins:: Other built-in functions. * Other Builtins:: Other built-in functions.
* Target Builtins:: Built-in functions specific to particular targets. * Target Builtins:: Built-in functions specific to particular targets.
* Target Format Checks:: Format checks specific to particular targets.
* Pragmas:: Pragmas accepted by GCC. * Pragmas:: Pragmas accepted by GCC.
* Unnamed Fields:: Unnamed struct/union fields within structs/unions. * Unnamed Fields:: Unnamed struct/union fields within structs/unions.
* Thread-Local:: Per-thread variables. * Thread-Local:: Per-thread variables.
...@@ -2173,6 +2174,10 @@ standard modes, the X/Open function @code{strfmon} is also checked as ...@@ -2173,6 +2174,10 @@ standard modes, the X/Open function @code{strfmon} is also checked as
are @code{printf_unlocked} and @code{fprintf_unlocked}. are @code{printf_unlocked} and @code{fprintf_unlocked}.
@xref{C Dialect Options,,Options Controlling C Dialect}. @xref{C Dialect Options,,Options Controlling C Dialect}.
The target may provide additional types of format checks.
@xref{Target Format Checks,,Format Checks Specific to Particular
Target Machines}.
@item format_arg (@var{string-index}) @item format_arg (@var{string-index})
@cindex @code{format_arg} function attribute @cindex @code{format_arg} function attribute
@opindex Wformat-nonliteral @opindex Wformat-nonliteral
...@@ -7209,6 +7214,25 @@ vector signed int vec_any_numeric (vector float); ...@@ -7209,6 +7214,25 @@ vector signed int vec_any_numeric (vector float);
vector signed int vec_any_out (vector float, vector float); vector signed int vec_any_out (vector float, vector float);
@end smallexample @end smallexample
@node Target Format Checks
@section Format Checks Specific to Particular Target Machines
For some target machines, GCC supports additional options to the
format attribute
(@pxref{Function Attributes,,Declaring Attributes of Functions}).
@menu
* Solaris Format Checks::
@end menu
@node Solaris Format Checks
@subsection Solaris Format Checks
Solaris targets support the @code{cmn_err} (or @code{__cmn_err__}) format
check. @code{cmn_err} accepts a subset of the standard @code{printf}
conversions, and the two-argument @code{%b} conversion for displaying
bit-fields. See the Solaris man page for @code{cmn_err} for more information.
@node Pragmas @node Pragmas
@section Pragmas Accepted by GCC @section Pragmas Accepted by GCC
@cindex pragmas @cindex pragmas
......
...@@ -2113,7 +2113,7 @@ specified, and that the conversions specified in the format string make ...@@ -2113,7 +2113,7 @@ specified, and that the conversions specified in the format string make
sense. This includes standard functions, and others specified by format sense. This includes standard functions, and others specified by format
attributes (@pxref{Function Attributes}), in the @code{printf}, attributes (@pxref{Function Attributes}), in the @code{printf},
@code{scanf}, @code{strftime} and @code{strfmon} (an X/Open extension, @code{scanf}, @code{strftime} and @code{strfmon} (an X/Open extension,
not in the C standard) families. not in the C standard) families (or other target-specific families).
The formats are checked against the format features supported by GNU The formats are checked against the format features supported by GNU
libc version 2.2. These include all ISO C90 and C99 features, as well libc version 2.2. These include all ISO C90 and C99 features, as well
......
...@@ -766,6 +766,9 @@ pragmas supported. ...@@ -766,6 +766,9 @@ pragmas supported.
Documentation in @file{gcc/doc/extend.texi} of any target-specific Documentation in @file{gcc/doc/extend.texi} of any target-specific
built-in functions supported. built-in functions supported.
@item @item
Documentation in @file{gcc/doc/extend.texi} of any target-specific
format checking styles supported.
@item
Documentation in @file{gcc/doc/md.texi} of any target-specific Documentation in @file{gcc/doc/md.texi} of any target-specific
constraint letters (@pxref{Machine Constraints, , Constraints for constraint letters (@pxref{Machine Constraints, , Constraints for
Particular Machines}). Particular Machines}).
......
...@@ -9278,3 +9278,14 @@ for a virtual function @var{fndecl} when constructing thunks, ...@@ -9278,3 +9278,14 @@ for a virtual function @var{fndecl} when constructing thunks,
functions, if a target supports aliases (ie. defines functions, if a target supports aliases (ie. defines
@code{ASM_OUTPUT_DEF}), @code{false} otherwise, @code{ASM_OUTPUT_DEF}), @code{false} otherwise,
@end deftypefn @end deftypefn
@defmac TARGET_FORMAT_TYPES
If defined, this macro is the name of a global variable containing
target-specific format checking information for the @option{-Wformat}
option. The default is to have no target-specific format checks.
@end defmac
@defmac TARGET_N_FORMAT_TYPES
If defined, this macro is the number of entries in
@code{TARGET_FORMAT_TYPES}.
@end defmac
2004-07-19 Daniel Jacobowitz <dan@debian.org>
* gcc.dg/format/cmn-err-1.c: New test.
2004-07-19 Joseph S. Myers <jsm@polyomino.org.uk> 2004-07-19 Joseph S. Myers <jsm@polyomino.org.uk>
* g++.dg/warn/Wparentheses-1.C, g++.dg/warn/Wparentheses-2.C, * g++.dg/warn/Wparentheses-1.C, g++.dg/warn/Wparentheses-2.C,
......
/* { dg-do compile { target *-*-solaris2.* } } */
/* { dg-options "-Wformat" } */
#include "format.h"
void cmn_err_func (int level, char * format, ...)
__attribute__((format (cmn_err, 2, 3)));
void cmn_err_func (int level, char * format, ...)
{
}
const char *string = "foo";
int main()
{
int i = 1;
long l = 2;
llong ll = 3;
cmn_err_func (0, "%s", string);
cmn_err_func (0, "%d %D %o %O %x %X %u", i, i, i, i, i, i, i);
cmn_err_func (0, "%ld %lD %lo %lO %lx %lX %lu", l, l, l, l, l, l, l);
cmn_err_func (0, "%lld %llD %llo %llO %llx %llX %llu",
ll, ll, ll, ll, ll, ll, ll);
cmn_err_func (0, "%b %s", i, "\01Foo", string);
cmn_err_func (0, "%i", i); /* { dg-error "unknown|too many" } */
cmn_err_func (0, "%d", l); /* { dg-error "expects type" } */
cmn_err_func (0, "%b"); /* { dg-error "too few" } */
cmn_err_func (0, "%b", i); /* { dg-error "too few" } */
cmn_err_func (0, "%b", i, i); /* { dg-error "expects type" } */
cmn_err_func (0, "%b", string, i); /* { dg-error "expects type" } */
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment