From 6ec637a4b85abeee6570e4cb7786df53eadbaa40 Mon Sep 17 00:00:00 2001 From: Janis Johnson Date: Thu, 7 May 2009 22:34:08 +0000 Subject: re PR c/39037 (FLOAT_CONST_DECIMAL64 pragma not supported) gcc/ PR c/39037 * c-common.h (mark_valid_location_for_stdc_pragma, valid_location_for_stdc_pragma_p, set_float_const_decimal64, clear_float_const_decimal64, float_const_decimal64_p): New. * c.opt (Wunsuffixed-float-constants): New. * c-lex.c (interpret_float): Use pragma FLOAT_CONST_DECIMAL64 for unsuffixed float constant, handle new warning. * c-cppbuiltin.c (c_cpp_builtins): Use cast for double constants. * c-decl.c (c_scope): New flag float_const_decimal64. (set_float_const_decimal64, clear_float_const_decimal64, float_const_decimal64_p): New. (push_scope): Set new flag. * c-parser.c (c_parser_translation_unit): Mark when it's valid to use STDC pragmas. (c_parser_external_declaration): Ditto. (c_parser_compound_statement_nostart): Ditto. * c-pragma.c (valid_location_for_stdc_pragma, mark_valid_location_for_stdc_pragma, valid_location_for_stdc_pragma_p, handle_stdc_pragma, handle_pragma_float_const_decimal64): New. (init_pragma): Register new pragma FLOAT_CONST_DECIMAL64. * cp/semantics.c (valid_location_for_stdc_pragma_p, set_float_const_decimal64, clear_float_const_decimal64, float_const_decimal64_p): New dummy functions. * doc/extend.texi (Decimal Float): Remove statement that the pragma, and suffix for double constants, are not supported. * doc/invoke.texi (Warning Options): List new option. (-Wunsuffixed-float-constants): New. gcc/testsuite PR c/39037 * gcc.dg/Wunsuffixed-float-constants-1.c: New test. * gcc.dg/cpp/pragma-float-const-decimal64-1.c: New test. * gcc.dg/dfp/float-constant-double.c: New test. * gcc.dg/dfp/pragma-float-const-decimal64-1.c: New test. * gcc.dg/dfp/pragma-float-const-decimal64-2.c: New test. * gcc.dg/dfp/pragma-float-const-decimal64-3.c: New test. * gcc.dg/dfp/pragma-float-const-decimal64-4.c: New test. * gcc.dg/dfp/pragma-float-const-decimal64-5.c: New test. * gcc.dg/dfp/pragma-float-const-decimal64-6.c: New test. * gcc.dg/dfp/pragma-float-const-decimal64-7.c: New test. * gcc.dg/dfp/pragma-float-const-decimal64-8.c: New test. * g++.dg/cpp/pragma-float-const-decimal64-1.C: New test. From-SVN: r147259 --- gcc/c-pragma.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'gcc/c-pragma.c') diff --git a/gcc/c-pragma.c b/gcc/c-pragma.c index 64a224f..bd71d1d 100644 --- a/gcc/c-pragma.c +++ b/gcc/c-pragma.c @@ -1162,6 +1162,116 @@ handle_pragma_message (cpp_reader *ARG_UNUSED(dummy)) inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message)); } +/* Mark whether the current location is valid for a STDC pragma. */ + +static bool valid_location_for_stdc_pragma; + +void +mark_valid_location_for_stdc_pragma (bool flag) +{ + valid_location_for_stdc_pragma = flag; +} + +/* Return true if the current location is valid for a STDC pragma. */ + +bool +valid_location_for_stdc_pragma_p (void) +{ + return valid_location_for_stdc_pragma; +} + +enum pragma_switch_t { ON, OFF, DEFAULT, BAD }; + +/* A STDC pragma must appear outside of external declarations or + preceding all explicit declarations and statements inside a compound + statement; its behavior is undefined if used in any other context. + It takes a switch of ON, OFF, or DEFAULT. */ + +static enum pragma_switch_t +handle_stdc_pragma (const char *pname) +{ + const char *arg; + tree t; + enum pragma_switch_t ret; + + if (!valid_location_for_stdc_pragma_p ()) + { + warning (OPT_Wpragmas, "invalid location for %, ignored", + pname); + return BAD; + } + + if (pragma_lex (&t) != CPP_NAME) + { + warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname); + return BAD; + } + + arg = IDENTIFIER_POINTER (t); + + if (!strcmp (arg, "ON")) + ret = ON; + else if (!strcmp (arg, "OFF")) + ret = OFF; + else if (!strcmp (arg, "DEFAULT")) + ret = DEFAULT; + else + { + warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname); + return BAD; + } + + if (pragma_lex (&t) != CPP_EOF) + { + warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname); + return BAD; + } + + return ret; +} + +/* #pragma STDC FLOAT_CONST_DECIMAL64 ON + #pragma STDC FLOAT_CONST_DECIMAL64 OFF + #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */ + +static void +handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy)) +{ + if (c_dialect_cxx ()) + { + if (warn_unknown_pragmas > in_system_header) + warning (OPT_Wunknown_pragmas, + "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported" + " for C++"); + return; + } + + if (!targetm.decimal_float_supported_p ()) + { + if (warn_unknown_pragmas > in_system_header) + warning (OPT_Wunknown_pragmas, + "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported" + " on this target"); + return; + } + + pedwarn (input_location, OPT_pedantic, + "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>"); + + switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64")) + { + case ON: + set_float_const_decimal64 (); + break; + case OFF: + case DEFAULT: + clear_float_const_decimal64 (); + break; + case BAD: + break; + } +} + /* A vector of registered pragma callbacks. */ DEF_VEC_O (pragma_handler); @@ -1330,6 +1440,9 @@ init_pragma (void) c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options); c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options); + c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64", + handle_pragma_float_const_decimal64); + c_register_pragma_with_expansion (0, "redefine_extname", handle_pragma_redefine_extname); c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix); -- cgit v1.1