From patchwork Mon Nov 23 19:50:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 547735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2AD481402A9 for ; Tue, 24 Nov 2015 06:51:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=MRlwH2l3; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:subject:from:to:cc:date:in-reply-to:references :content-type:mime-version; q=dns; s=default; b=ENgQDJs5FPlUnsN2 so6e1Ay/Vj+/SC/iEVeN/kzyuaMOV4zmoBmzb2j0liaJXK9Tkp1d70XmziFxZ720 UZQNQXes4OfUQuwSQm+j4WlwMgje+6997QSF6UEcWvQkHHy4429teyxPs7bdycZE ZDggcF67rOPT6yDPWuniXdYL5cI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:subject:from:to:cc:date:in-reply-to:references :content-type:mime-version; s=default; bh=3Bz6T+EC0wxBUv9tzOwdDQ dk7oI=; b=MRlwH2l3R0DEHG+CmFjHNGmBy8FkYmI0+DKCh74hI6hyPsLdRLkfwj ub3yRJTRvjRgR85ZUccNLsXa/d5m0FWwX1kUbPz2p0TWhM4jKwC5B0Bb9PWhICyx 0vhcEJmDCKNRvz7QIb0aGVdhI+p+OcP3/6R1QF8fvygq3Eb2WC7Og= Received: (qmail 129554 invoked by alias); 23 Nov 2015 19:51:05 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 129539 invoked by uid 89); 23 Nov 2015 19:51:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 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; Mon, 23 Nov 2015 19:51:03 +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 0796D37FF64; Mon, 23 Nov 2015 19:51:00 +0000 (UTC) Received: from [10.3.233.130] (vpn-233-130.phx2.redhat.com [10.3.233.130]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tANJoxaH026407; Mon, 23 Nov 2015 14:51:00 -0500 Message-ID: <1448308259.19594.187.camel@surprise> Subject: Re: [PATCH] Fix PR objc/68438 (uninitialized source ranges) From: David Malcolm To: Jeff Law Cc: Joseph Myers , "gcc-patches@gcc.gnu.org" Date: Mon, 23 Nov 2015 14:50:59 -0500 In-Reply-To: <56534C24.9090303@redhat.com> References: <1448051277.19594.160.camel@surprise> <1448208819.19594.165.camel@surprise> <56534C24.9090303@redhat.com> Mime-Version: 1.0 X-IsSubscribed: yes On Mon, 2015-11-23 at 10:25 -0700, Jeff Law wrote: > On 11/23/2015 04:13 AM, Joseph Myers wrote: > > On Sun, 22 Nov 2015, David Malcolm wrote: > > > >> Is there (or could there be) a precanned dg- directive to ask if ObjC is > >> available? > > > > I don't think so. Normal practice is that each language's tests are in > > appropriate directories for that language, with runtest never called with > > a --tool option for that language if it wasn't built. > Right. Which argues that we really want to create a new test directory > for objc plugin tests. Attached is a revised version of the patch which creates an objc.dg/plugin subdirectory, and builds the plugin that way (directly reusing the plugin src from the gcc.dg subdir). Successfully bootstrapped®rtested on x86_64-pc-linux-gnu; adds 16 PASS results to objc.sum. OK for trunk? From f09c48b2ac55b2f9b5c3688e76fb4b91c3325fbb Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 20 Nov 2015 11:12:47 -0500 Subject: [PATCH] Fix PR objc/68438 (uninitialized source ranges) gcc/c/ChangeLog: PR objc/68438 * c-parser.c (c_parser_postfix_expression): Set up source ranges for various Objective-C constructs: Class.name syntax, @selector(), @protocol, @encode(), and [] message syntax. gcc/testsuite/ChangeLog: PR objc/68438 * objc.dg/plugin/diagnostic-test-expressions-1.m: New test file. * objc.dg/plugin/plugin.exp: New file, based on gcc.dg/plugin/plugin.exp. --- gcc/c/c-parser.c | 17 +++- .../objc.dg/plugin/diagnostic-test-expressions-1.m | 94 ++++++++++++++++++++++ gcc/testsuite/objc.dg/plugin/plugin.exp | 90 +++++++++++++++++++++ 3 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m create mode 100644 gcc/testsuite/objc.dg/plugin/plugin.exp diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 7b10764..18e9957 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -7338,10 +7338,13 @@ c_parser_postfix_expression (c_parser *parser) expr.value = error_mark_node; break; } - component = c_parser_peek_token (parser)->value; + c_token *component_tok = c_parser_peek_token (parser); + component = component_tok->value; + location_t end_loc = component_tok->get_finish (); c_parser_consume_token (parser); expr.value = objc_build_class_component_ref (class_name, component); + set_c_expr_source_range (&expr, loc, end_loc); break; } default: @@ -7816,9 +7819,11 @@ c_parser_postfix_expression (c_parser *parser) } { tree sel = c_parser_objc_selector_arg (parser); + location_t close_loc = c_parser_peek_token (parser)->location; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); expr.value = objc_build_selector_expr (loc, sel); + set_c_expr_source_range (&expr, loc, close_loc); } break; case RID_AT_PROTOCOL: @@ -7839,9 +7844,11 @@ c_parser_postfix_expression (c_parser *parser) { tree id = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); + location_t close_loc = c_parser_peek_token (parser)->location; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); expr.value = objc_build_protocol_expr (id); + set_c_expr_source_range (&expr, loc, close_loc); } break; case RID_AT_ENCODE: @@ -7860,11 +7867,13 @@ c_parser_postfix_expression (c_parser *parser) c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); break; } - c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, - "expected %<)%>"); { + location_t close_loc = c_parser_peek_token (parser)->location; + c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, + "expected %<)%>"); tree type = groktypename (t1, NULL, NULL); expr.value = objc_build_encode_expr (type); + set_c_expr_source_range (&expr, loc, close_loc); } break; case RID_GENERIC: @@ -7907,9 +7916,11 @@ c_parser_postfix_expression (c_parser *parser) c_parser_consume_token (parser); receiver = c_parser_objc_receiver (parser); args = c_parser_objc_message_args (parser); + location_t close_loc = c_parser_peek_token (parser)->location; c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); expr.value = objc_build_message_expr (receiver, args); + set_c_expr_source_range (&expr, loc, close_loc); break; } /* Else fall through to report error. */ diff --git a/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m b/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m new file mode 100644 index 0000000..ed7aca3 --- /dev/null +++ b/gcc/testsuite/objc.dg/plugin/diagnostic-test-expressions-1.m @@ -0,0 +1,94 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdiagnostics-show-caret" } */ + +/* This file is similar to diagnostic-test-expressions-1.c + (see the notes in that file); this file adds test + coverage for various Objective C constructs. */ + +extern void __emit_expression_range (int dummy, ...); + +@protocol prot +@end + +@interface tests +- (int) func0; +- (int) func1:(int)i; ++ (int) func2; +- (void) test_sending_messages; ++ (void) test_class_dot_name; +- (void) test_at_selector; +- (void) test_at_protocol; +- (void) test_at_encode:(int)i; +@end + +@implementation tests +- (int) func0 +{ + return 42; +} +- (int) func1:(int)i +{ + return i * i; +} ++ (int) func2 +{ + return 0; +} +- (void) test_sending_messages +{ + __emit_expression_range ( 0, [self func0] ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range ( 0, [self func0] ); + ~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ + __emit_expression_range ( 0, [self func1:5] ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range ( 0, [self func1:5] ); + ~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} ++ (void) test_class_dot_name +{ + __emit_expression_range ( 0, tests.func2 ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range ( 0, tests.func2 ); + ~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} +- (void) test_at_selector +{ + __emit_expression_range ( 0, @selector(func0) ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range ( 0, @selector(func0) ); + ^~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} +- (void) test_at_protocol +{ + __emit_expression_range ( 0, @protocol(prot) ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range ( 0, @protocol(prot) ); + ~~~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} +- (void) test_at_encode:(int)i +{ + /* @encode() generates a STRING_CST which doesn't retain a location + after parsing, so we need to access it via compound expressions + that can't be folded away. */ + + /* Verify start. */ + __emit_expression_range ( 0, @encode(int) + i ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range ( 0, @encode(int) + i ); + ~~~~~~~~~~~~~^~~ + { dg-end-multiline-output "" } */ + + /* Verify finish. */ + __emit_expression_range ( 0, i + @encode(int) ); /* { dg-warning "range" } */ +/* { dg-begin-multiline-output "" } + __emit_expression_range ( 0, i + @encode(int) ); + ~~^~~~~~~~~~~~~~ + { dg-end-multiline-output "" } */ +} +@end diff --git a/gcc/testsuite/objc.dg/plugin/plugin.exp b/gcc/testsuite/objc.dg/plugin/plugin.exp new file mode 100644 index 0000000..f98dff5 --- /dev/null +++ b/gcc/testsuite/objc.dg/plugin/plugin.exp @@ -0,0 +1,90 @@ +# Copyright (C) 2009-2015 Free Software Foundation, Inc. + +# This program 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 3 of the License, or +# (at your option) any later version. +# +# This program 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 COPYING3. If not see +# . + +# Test the functionality of the GCC plugin support + +load_lib target-supports.exp +load_lib objc-dg.exp + +global TESTING_IN_BUILD_TREE +global ENABLE_PLUGIN + +# The plugin testcases currently only work when the build tree is available. +# Also check whether the host supports plugins. +if { ![info exists TESTING_IN_BUILD_TREE] || ![info exists ENABLE_PLUGIN] } { + return +} + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS " -ansi -pedantic-errors" +} + +# The procedures in plugin-support.exp need these parameters. +set default_flags $DEFAULT_CFLAGS + +if $tracelevel then { + strace $tracelevel +} + +# Load support procs. +load_lib plugin-support.exp + +# These tests don't run runtest_file_p consistently if it +# doesn't return the same values, so disable parallelization +# of this *.exp file. The first parallel runtest to reach +# this will run all the tests serially. +if ![gcc_parallel_test_run_p plugin] { + return +} +gcc_parallel_test_enable 0 + +# Specify the plugin source file and the associated test files in a list. +# plugin_test_list={ {plugin1 test1 test2 ...} {plugin2 test1 ...} ... } +set plugin_test_list [list \ + { ../../gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c \ + diagnostic-test-expressions-1.m } \ +] + +foreach plugin_test $plugin_test_list { + # Replace each source file with its full-path name + for {set i 0} {$i < [llength $plugin_test]} {incr i} { + set basename [lindex $plugin_test $i] + set plugin_test [lreplace $plugin_test $i $i $srcdir/$subdir/$basename] + } + set plugin_src [lindex $plugin_test 0] + # If we're only testing specific files and this isn't one of them, skip it. + if ![runtest_file_p $runtests $plugin_src] then { + continue + } + set plugin_input_tests [lreplace $plugin_test 0 0] + plugin-test-execute $plugin_src $plugin_input_tests +} + +# run the plugindir tests + +# Initialize `dg'. +dg-init + +# Main loop. +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/plugindir*.m]] \ + "" $DEFAULT_CFLAGS + +# All done. +dg-finish + +gcc_parallel_test_enable 1 -- 1.8.5.3