public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3004] c: _Generic should not warn in non-active branches [PR68193, PR97100, PR110703]
@ 2023-08-05  8:40 Martin Uecker
  0 siblings, 0 replies; only message in thread
From: Martin Uecker @ 2023-08-05  8:40 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:54be338589ea93ad4ff53d22adde476a0582537b

commit r14-3004-g54be338589ea93ad4ff53d22adde476a0582537b
Author: Martin Uecker <uecker@tugraz.at>
Date:   Fri Aug 4 07:48:21 2023 +0200

    c: _Generic should not warn in non-active branches [PR68193,PR97100,PR110703]
    
    To avoid false diagnostics, use c_inhibit_evaluation_warnings when
    a generic association is known to not match during parsing.  We may
    still generate false positives if the default branch comes earler than
    a specific association that matches.
    
    PR c/68193
    PR c/97100
    PR c/110703
    
    gcc/c/:
            * c-parser.cc (c_parser_generic_selection): Inhibit evaluation
            warnings branches that are known not be taken during parsing.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/pr68193.c: New test.

Diff:
---
 gcc/c/c-parser.cc              | 12 +++++++++++-
 gcc/testsuite/gcc.dg/pr68193.c | 15 +++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 7a9fdda6c88..57a01dc2fa3 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -9392,7 +9392,17 @@ c_parser_generic_selection (c_parser *parser)
 	  return error_expr;
 	}
 
+      bool match = assoc.type == NULL_TREE
+		   || comptypes (assoc.type, selector_type);
+
+      if (!match)
+	c_inhibit_evaluation_warnings++;
+
       assoc.expression = c_parser_expr_no_commas (parser, NULL);
+
+      if (!match)
+	  c_inhibit_evaluation_warnings--;
+
       if (assoc.expression.value == error_mark_node)
 	{
 	  c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL);
@@ -9429,7 +9439,7 @@ c_parser_generic_selection (c_parser *parser)
 	      match_found = associations.length ();
 	    }
 	}
-      else if (comptypes (assoc.type, selector_type))
+      else if (match)
 	{
 	  if (match_found < 0 || matched_assoc.type == NULL_TREE)
 	    {
diff --git a/gcc/testsuite/gcc.dg/pr68193.c b/gcc/testsuite/gcc.dg/pr68193.c
new file mode 100644
index 00000000000..2267593e363
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr68193.c
@@ -0,0 +1,15 @@
+/*  pr69193 */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+int
+main (void)
+{
+  int i = 0;
+  int j = _Generic (i,
+		    int: 0,
+		    long int: (i = (long int) 9223372036854775808UL));
+  return i + j;
+}
+
+

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-05  8:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-05  8:40 [gcc r14-3004] c: _Generic should not warn in non-active branches [PR68193, PR97100, PR110703] Martin Uecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).