From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 79877 invoked by alias); 18 Mar 2016 16:02:17 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 79820 invoked by uid 89); 18 Mar 2016 16:02:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=BAYES_00,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=UD:value, identified X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 18 Mar 2016 16:02:14 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 1FAD2C050067 for ; Fri, 18 Mar 2016 16:02:13 +0000 (UTC) Received: from c64.redhat.com (vpn-230-214.phx2.redhat.com [10.3.230.214]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2IG2COK031562; Fri, 18 Mar 2016 12:02:12 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [PATCH] PR c/70281: C FE: fix uninitialized range for __builtin_types_compatible_p Date: Fri, 18 Mar 2016 16:19:00 -0000 Message-Id: <1458318324-42797-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg01100.txt.bz2 PR c/70281 reports another case where Valgrind identified an uninitialized src_range in a c_expr in the C frontend, this time in the parsing of __builtin_types_compatible_p. For gcc 7 I hope to fix this more robustly (via poisoning the values in a c_expr ctor), but for now, this patch fixes the specific issue found. Successfully bootstrapped on x86_64-pc-linux-gnu; adds 7 PASS results to gcc.sum. OK for trunk? gcc/c/ChangeLog: PR c/70281 * c-parser.c (c_parser_postfix_expression): Set the source range for uses of "__builtin_types_compatible_p". gcc/testsuite/ChangeLog: PR c/70281 * gcc.dg/plugin/diagnostic-test-expressions-1.c (test_builtin_types_compatible_p): New test function. * gcc.dg/pr70281.c: New test case. --- gcc/c/c-parser.c | 6 ++++-- .../gcc.dg/plugin/diagnostic-test-expressions-1.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/pr70281.c | 9 +++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr70281.c diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 60ec996..b80b279 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -7782,9 +7782,10 @@ c_parser_postfix_expression (c_parser *parser) expr.value = error_mark_node; break; } - c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, - "expected %<)%>"); { + location_t close_paren_loc = c_parser_peek_token (parser)->location; + c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, + "expected %<)%>"); tree e1, e2; e1 = groktypename (t1, NULL, NULL); e2 = groktypename (t2, NULL, NULL); @@ -7799,6 +7800,7 @@ c_parser_postfix_expression (c_parser *parser) expr.value = comptypes (e1, e2) ? integer_one_node : integer_zero_node; + set_c_expr_source_range (&expr, loc, close_paren_loc); } break; case RID_BUILTIN_CALL_WITH_STATIC_CHAIN: diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c index 49ad670..c2d27d7 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-expressions-1.c @@ -534,6 +534,24 @@ void test_builtin_choose_expr (int i) } extern int f (int); + +void test_builtin_types_compatible_p (unsigned long i) +{ + __emit_expression_range (0, + f (i) + __builtin_types_compatible_p (long, int)); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + f (i) + __builtin_types_compatible_p (long, int)); + ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ + + __emit_expression_range (0, + __builtin_types_compatible_p (long, int) + f (i)); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __builtin_types_compatible_p (long, int) + f (i)); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ + { dg-end-multiline-output "" } */ +} + void test_builtin_call_with_static_chain (int i, void *ptr) { __emit_expression_range (0, __builtin_call_with_static_chain (f (i), ptr)); /* { dg-warning "range" } */ diff --git a/gcc/testsuite/gcc.dg/pr70281.c b/gcc/testsuite/gcc.dg/pr70281.c new file mode 100644 index 0000000..9447fb1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr70281.c @@ -0,0 +1,9 @@ +/* { dg-options "-Wall -fdiagnostics-show-caret" } */ +int bch_stats_show () +{ + return __builtin_types_compatible_p (unsigned, int) ? "" : ""; /* { dg-warning "cast" } */ +/* { dg-begin-multiline-output "" } + return __builtin_types_compatible_p (unsigned, int) ? "" : ""; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ + { dg-end-multiline-output "" } */ +} -- 1.8.5.3