From patchwork Wed Aug 21 09:54:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1150760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-507435-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="tS4lRmEL"; dkim-atps=neutral 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 46D30r3bZBz9sN4 for ; Wed, 21 Aug 2019 19:54:34 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=uQnH+72qHjKGrLzY 4w9r2Oh/HMP0qdQU6Ucu7PdlR3aX1j2wY5mLstpkV1YKkQ+mZI4Ik5xEoTQhuqaM sLR5dBJAkT6IZcO37dJwmUeDpjikVeUEwXnMinkKtgXPnXDYW05p/f6ENHamOseq VCdLQNZDOG1jCYhNtGyreLnWRSE= 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:from :to:cc:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=BkrD9BUnty3MaV5Cp3dcXV zBRuw=; b=tS4lRmELuk34x/mjXj1TYX7GWuOglA/WPcrv0dEaVYi/samu7QWY1u BpnctGu1qshBjh3EYfb6mnDZRRwd9/iZiZjJ+QkPEncVEVKXyTpJJcuKy0gOhHKe YAUs7itVEBbTwBkwJcojfzpSx1vPUlY+CbsgNWvYJAArGWPpFH09k= Received: (qmail 83131 invoked by alias); 21 Aug 2019 09:54:27 -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 82772 invoked by uid 89); 21 Aug 2019 09:54:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=differentiate X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Aug 2019 09:54:25 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id DE8B58150F; Wed, 21 Aug 2019 11:54:22 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 74iCq-CQrBrb; Wed, 21 Aug 2019 11:54:22 +0200 (CEST) Received: from arcturus.home (adijon-653-1-66-235.w90-33.abo.wanadoo.fr [90.33.137.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 26A1A8137C; Wed, 21 Aug 2019 11:54:22 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Cc: Joseph Myers Subject: Fix crash with -fdump-ada-spec Date: Wed, 21 Aug 2019 11:54:32 +0200 Message-ID: <2508992.5cBtdV5qiJ@arcturus.home> MIME-Version: 1.0 This fixes a crash of the C compiler when -fdump-ada-spec is passed for: extern void (*signal (int __sig, void (*__handler)(int)))(int); It appears that the C parser is somewhat confused by this declaration and builds a FUNCTION_DECL whose type has got 2 arguments (TYPE_ARG_TYPES list) but which itself has got only 1 argument (DECL_ARGUMENTS list) corresponding to the anonymous (int) at the end. The C++ parser doesn't have the issue. Joseph, is that a known issue of the C parser? The attached patch changes -fdump-ada-spec to using TYPE_ARG_TYPES for it. 2019-08-21 Eric Botcazou c-family/ * c-ada-spec.c (dump_ada_function_declaration): Be prepared for broken function declarations where arguments are missing. Rename variables. 2019-08-21 Eric Botcazou * c-c++-common/dump-ada-spec-15.c: New test. Index: c-family/c-ada-spec.c =================================================================== --- c-family/c-ada-spec.c (revision 274744) +++ c-family/c-ada-spec.c (working copy) @@ -1589,14 +1589,13 @@ dump_ada_function_declaration (pretty_printer *buf bool is_method, bool is_constructor, bool is_destructor, int spc) { - tree arg; - const tree node = TREE_TYPE (func); + tree type = TREE_TYPE (func); + tree arg = TYPE_ARG_TYPES (type); + tree t; char buf[17]; - int num = 0, num_args = 0, have_args = true, have_ellipsis = false; + int num, num_args = 0, have_args = true, have_ellipsis = false; /* Compute number of arguments. */ - arg = TYPE_ARG_TYPES (node); - if (arg) { while (TREE_CHAIN (arg) && arg != error_mark_node) @@ -1627,25 +1626,29 @@ dump_ada_function_declaration (pretty_printer *buf pp_left_paren (buffer); } + /* For a function, see if we have the corresponding arguments. */ if (TREE_CODE (func) == FUNCTION_DECL) - arg = DECL_ARGUMENTS (func); + { + arg = DECL_ARGUMENTS (func); + for (t = arg, num = 0; t; t = DECL_CHAIN (t)) + num++; + if (num < num_args) + arg = NULL_TREE; + } else arg = NULL_TREE; - if (arg == NULL_TREE) + /* Otherwise, only print the types. */ + if (!arg) { have_args = false; - arg = TYPE_ARG_TYPES (node); - - if (arg && TREE_CODE (TREE_VALUE (arg)) == VOID_TYPE) - arg = NULL_TREE; + arg = TYPE_ARG_TYPES (type); } if (is_constructor) arg = TREE_CHAIN (arg); - /* Print the argument names (if available) & types. */ - + /* Print the argument names (if available) and types. */ for (num = 1; num <= num_args; num++) { if (have_args) @@ -1663,13 +1666,13 @@ dump_ada_function_declaration (pretty_printer *buf pp_string (buffer, buf); } - dump_ada_node (buffer, TREE_TYPE (arg), node, spc, false, true); + dump_ada_node (buffer, TREE_TYPE (arg), type, spc, false, true); } else { sprintf (buf, "arg%d : ", num); pp_string (buffer, buf); - dump_ada_node (buffer, TREE_VALUE (arg), node, spc, false, true); + dump_ada_node (buffer, TREE_VALUE (arg), type, spc, false, true); } /* If the type is a pointer to a tagged type, we need to differentiate @@ -1707,11 +1710,11 @@ dump_ada_function_declaration (pretty_printer *buf if (num_args > 0) pp_right_paren (buffer); - if (is_constructor || !VOID_TYPE_P (TREE_TYPE (node))) + if (is_constructor || !VOID_TYPE_P (TREE_TYPE (type))) { pp_string (buffer, " return "); - tree type = is_constructor ? DECL_CONTEXT (func) : TREE_TYPE (node); - dump_ada_node (buffer, type, type, spc, false, true); + tree rtype = is_constructor ? DECL_CONTEXT (func) : TREE_TYPE (type); + dump_ada_node (buffer, rtype, rtype, spc, false, true); } }