From 02b7dd7f8233eb83f660cc021857be36cab2b846 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 7 Mar 2022 15:16:56 +0100 Subject: Add missing space in various string literals After more than 2 years I've run my https://gcc.gnu.org/ml/gcc-patches/2017-02/msg00844.html script again. While it has lots of false positives, it discovered two bugs. 2022-03-07 Jakub Jelinek gcc/c/ * c-parser.cc (c_parser_omp_clause_map): Add missing space in string literal. gcc/cp/ * parser.cc (cp_parser_omp_clause_map): Add missing space in string literal. --- gcc/c/c-parser.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/c') diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 84deac0..129dd72 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -16230,8 +16230,8 @@ c_parser_omp_clause_map (c_parser *parser, tree list) else { c_parser_error (parser, "%<#pragma omp target%> with " - "modifier other than % or %" - "on % clause"); + "modifier other than % or " + "% on % clause"); parens.skip_until_found_close (parser); return list; } -- cgit v1.1 From e6533e2ebec964e77d3a2462abbabd214d677552 Mon Sep 17 00:00:00 2001 From: GCC Administrator Date: Tue, 8 Mar 2022 00:16:32 +0000 Subject: Daily bump. --- gcc/c/ChangeLog | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gcc/c') diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index b177355..8f6bf71 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2022-03-07 Jakub Jelinek + + * c-parser.cc (c_parser_omp_clause_map): Add missing space in string + literal. + 2022-02-23 Richard Biener * gimple-parser.cc (c_parser_parse_gimple_body): Diagnose -- cgit v1.1 From d76511138dc816ef66fd16f71531f48c37dac3b4 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 9 Mar 2022 09:15:28 +0100 Subject: c, c++, c-family: -Wshift-negative-value and -Wshift-overflow* tweaks for -fwrapv and C++20+ [PR104711] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As mentioned in the PR, different standards have different definition on what is an UB left shift. They all agree on out of bounds (including negative) shift count. The rules used by ubsan are: C99-C2x ((unsigned) x >> (uprecm1 - y)) != 0 then UB C++11-C++17 x < 0 || ((unsigned) x >> (uprecm1 - y)) > 1 then UB C++20 and later everything is well defined Now, for C++20, I've in the P1236R1 implementation added an early exit for -Wshift-overflow* warning so that it never warns, but apparently -Wshift-negative-value remained as is. As it is well defined in C++20, the following patch doesn't enable -Wshift-negative-value from -Wextra anymore for C++20 and later, if users want for compatibility with C++17 and earlier get the warning, they still can by using -Wshift-negative-value explicitly. Another thing is -fwrapv, that is an extension to the standards, so it is up to us how exactly we define that case. Our ubsan code treats TYPE_OVERFLOW_WRAPS (type0) and cxx_dialect >= cxx20 the same as only diagnosing out of bounds shift count and nothing else and IMHO it is most sensical to treat -fwrapv signed left shifts the same as C++20 treats them, https://eel.is/c++draft/expr.shift#2 "The value of E1 << E2 is the unique value congruent to E1×2^E2 modulo 2^N, where N is the width of the type of the result. [Note 1: E1 is left-shifted E2 bit positions; vacated bits are zero-filled. — end note]" with no UB dependent on the E1 values. The UB is only "The behavior is undefined if the right operand is negative, or greater than or equal to the width of the promoted left operand." Under the hood (except for FEs and ubsan from FEs) GCC middle-end doesn't consider UB in left shifts dependent on the first operand's value, only the out of bounds shifts. While this change isn't a regression, I'd think it is useful for GCC 12, it doesn't add new warnings, but just removes warnings that aren't appropriate. 2022-03-09 Jakub Jelinek PR c/104711 gcc/ * doc/invoke.texi (-Wextra): Document that -Wshift-negative-value is enabled by it only for C++11 to C++17 rather than for C++03 or later. (-Wshift-negative-value): Similarly (except here we stated that it is enabled for C++11 or later). gcc/c-family/ * c-opts.cc (c_common_post_options): Don't enable -Wshift-negative-value from -Wextra for C++20 or later. * c-ubsan.cc (ubsan_instrument_shift): Adjust comments. * c-warn.cc (maybe_warn_shift_overflow): Use TYPE_OVERFLOW_WRAPS instead of TYPE_UNSIGNED. gcc/c/ * c-fold.cc (c_fully_fold_internal): Don't emit -Wshift-negative-value warning if TYPE_OVERFLOW_WRAPS. * c-typeck.cc (build_binary_op): Likewise. gcc/cp/ * constexpr.cc (cxx_eval_check_shift_p): Use TYPE_OVERFLOW_WRAPS instead of TYPE_UNSIGNED. * typeck.cc (cp_build_binary_op): Don't emit -Wshift-negative-value warning if TYPE_OVERFLOW_WRAPS. gcc/testsuite/ * c-c++-common/Wshift-negative-value-1.c: Remove dg-additional-options, instead in target selectors of each diagnostic check for exact C++ versions where it should be diagnosed. * c-c++-common/Wshift-negative-value-2.c: Likewise. * c-c++-common/Wshift-negative-value-3.c: Likewise. * c-c++-common/Wshift-negative-value-4.c: Likewise. * c-c++-common/Wshift-negative-value-7.c: New test. * c-c++-common/Wshift-negative-value-8.c: New test. * c-c++-common/Wshift-negative-value-9.c: New test. * c-c++-common/Wshift-negative-value-10.c: New test. * c-c++-common/Wshift-overflow-1.c: Remove dg-additional-options, instead in target selectors of each diagnostic check for exact C++ versions where it should be diagnosed. * c-c++-common/Wshift-overflow-2.c: Likewise. * c-c++-common/Wshift-overflow-5.c: Likewise. * c-c++-common/Wshift-overflow-6.c: Likewise. * c-c++-common/Wshift-overflow-7.c: Likewise. * c-c++-common/Wshift-overflow-8.c: New test. * c-c++-common/Wshift-overflow-9.c: New test. * c-c++-common/Wshift-overflow-10.c: New test. * c-c++-common/Wshift-overflow-11.c: New test. * c-c++-common/Wshift-overflow-12.c: New test. --- gcc/c/c-fold.cc | 1 + gcc/c/c-typeck.cc | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/c') diff --git a/gcc/c/c-fold.cc b/gcc/c/c-fold.cc index 76ea25b..ac4ceaa 100644 --- a/gcc/c/c-fold.cc +++ b/gcc/c/c-fold.cc @@ -382,6 +382,7 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands, && TREE_CODE (TREE_TYPE (orig_op0)) == INTEGER_TYPE && TREE_CODE (op0) == INTEGER_CST && c_inhibit_evaluation_warnings == 0 + && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (orig_op0)) && tree_int_cst_sgn (op0) < 0) warning_at (loc, OPT_Wshift_negative_value, "left shift of negative value"); diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 3075c88..b37f3cf 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -12213,7 +12213,8 @@ build_binary_op (location_t location, enum tree_code code, { doing_shift = true; if (TREE_CODE (op0) == INTEGER_CST - && tree_int_cst_sgn (op0) < 0) + && tree_int_cst_sgn (op0) < 0 + && !TYPE_OVERFLOW_WRAPS (type0)) { /* Don't reject a left shift of a negative value in a context where a constant expression is needed in C90. */ -- cgit v1.1 From 4ea128d5c740e4e8c2e7b70de3a90435035eb863 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 9 Mar 2022 22:51:23 +0000 Subject: c: Revert C2x changes to function type compatibility In commit cc806126215c3f4dc187eff3bf923458d8cc6b4f, I implemented changes that C2x had made to compatibility of unprototyped and prototyped function types. C2x has since completely removed unprototyped function types, making () in a function declaration mean (void) as in C++. While that change isn't appropriate at the current development stage for GCC 12, it does mean that it doesn't make sense for GCC 12 to have different rules for unprototyped functions in C2x mode than in other modes or previous and subsequent GCC versions. Thus, revert the previous change to avoid it getting into a GCC release, and update the corresponding tests to expect the same behavior with -std=c2x as with -std=c11 (they will of course need to change again after implementing () as meaning (void)). Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c/ * c-typeck.cc (function_types_compatible_p): Do not handle C2X differently from earlier standards for unprototyped function type compatibility. gcc/testsuite/ * gcc.dg/c11-unproto-1.c, gcc.dg/c11-unproto-2.c: Update comments. * gcc.dg/c2x-unproto-1.c, gcc.dg/c2x-unproto-2.c: Expect same results as in C11 mode. Update comments. --- gcc/c/c-typeck.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gcc/c') diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index b37f3cf..54b0b0d 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -1693,7 +1693,7 @@ function_types_compatible_p (const_tree f1, const_tree f2, if (args1 == NULL_TREE) { - if (flag_isoc2x ? stdarg_p (f2) : !self_promoting_args_p (args2)) + if (!self_promoting_args_p (args2)) return 0; /* If one of these types comes from a non-prototype fn definition, compare that with the other type's arglist. @@ -1706,7 +1706,7 @@ function_types_compatible_p (const_tree f1, const_tree f2, } if (args2 == NULL_TREE) { - if (flag_isoc2x ? stdarg_p (f1) : !self_promoting_args_p (args1)) + if (!self_promoting_args_p (args1)) return 0; if (TYPE_ACTUAL_ARG_TYPES (f2) && type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2), -- cgit v1.1 From 8cc4f9cd824d195178632569c749f96b306475f9 Mon Sep 17 00:00:00 2001 From: GCC Administrator Date: Thu, 10 Mar 2022 00:16:28 +0000 Subject: Daily bump. --- gcc/c/ChangeLog | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gcc/c') diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 8f6bf71..e97a42b 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,16 @@ +2022-03-09 Joseph Myers + + * c-typeck.cc (function_types_compatible_p): Do not handle C2X + differently from earlier standards for unprototyped function type + compatibility. + +2022-03-09 Jakub Jelinek + + PR c/104711 + * c-fold.cc (c_fully_fold_internal): Don't emit + -Wshift-negative-value warning if TYPE_OVERFLOW_WRAPS. + * c-typeck.cc (build_binary_op): Likewise. + 2022-03-07 Jakub Jelinek * c-parser.cc (c_parser_omp_clause_map): Add missing space in string -- cgit v1.1