From patchwork Tue Nov 19 23:29:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1197688 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514082-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="pCvaI7/J"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="bwfhmlxJ"; 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 47HhrK73Ndz9sPL for ; Wed, 20 Nov 2019 10:30:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=Qrd oMGRdUCq7ULHeIo5VjHkIT67vyCMlBBytmFTWP1IXvVVfmqVnCVT98WeGYevvOg6 77TpOl3lKM2VjkUg8MvCFzaRX5XLKb/DW6tyPPeKHdnXcOt28RM7UKIoeEePkexD egjCiEQMI1BjMGb91rGaW6h9+rUYCX6sXUFxgBZQ= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=default; bh=7H1nuTaDr TQ8rpqjeboOdHDEKHw=; b=pCvaI7/JIcXVh3I8UHb2r1LkH6vi5wnTmxNvMEF54 mGdbHeNdqahhFhU6Jl7k6hXA/bZoK8GQtTGgw8dyHDUcBeVVnr75NeeC++wNJF+Z z5bMKiHwx/cmieQfrtclgIGKts3AK7zwBVN11Ajb5hS4yd20n7zy7kYOhkfKmOSO iU= Received: (qmail 86702 invoked by alias); 19 Nov 2019 23:29:59 -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 86686 invoked by uid 89); 19 Nov 2019 23:29:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=4.7, 4.6 X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-2.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Nov 2019 23:29:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574206196; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Uk5uWywvKEIiHjcXUYjbs8O9UvBvxeEiEsWNi7sotHo=; b=bwfhmlxJidNGDTdZbDA5vB610VTLIOHOcJQJSj48w0pMUNS1avsIr5e+vlL5L0WK3/zuNM IOVRvVDKQyp87XTuvHSuZ5+kzlJJG0qJ1F7itWPmhqFL6fe79gYwQqvcYC7p+l589H6NJB 4IpNBxUtz9YfjpYkdrSmbSAwq9eFEqc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-95-EZP3DVTFN-2g0lWiTIcSCg-1; Tue, 19 Nov 2019 18:29:53 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5F85E18C35A1; Tue, 19 Nov 2019 23:29:51 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56B05691BE; Tue, 19 Nov 2019 23:29:48 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id xAJNTjgh029731; Wed, 20 Nov 2019 00:29:46 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xAJNThNi029730; Wed, 20 Nov 2019 00:29:43 +0100 Date: Wed, 20 Nov 2019 00:29:43 +0100 From: Jakub Jelinek To: "Joseph S. Myers" , Marek Polacek , Jason Merrill , Nathan Sidwell Cc: gcc-patches@gcc.gnu.org Subject: [C/C++ PATCH] Fix up build of GCC 4.6 and earlier with GCC 9+ (PR c/90677) Message-ID: <20191119232943.GN4650@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! The following patch fixes build of older GCC releases with newer ones. In GCC 4.6 and earlier, we had: struct cgraph_node; struct cgraph_node *cgraph_node (tree); and that is something on which GCC 9+ code errors on if it sees any __gcc_diag__ and similar attributes, because cgraph_node it wants to find is not a type. As older GCC releases don't have the __gcc_diag__ etc. attributes guarded on no newer GCC releases, only on minimum GCC version that does support it, I think we need to make sure we don't reject what older GCCs used to have. The following patch does that. In addition, get_pointer_to_named_type looked misnamed, because we actually aren't interested in getting gimple * etc. type, but gimple. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and eventually 9 too? 2019-11-19 Jakub Jelinek PR c/90677 * c-format.c (get_pointer_to_named_type): Renamed to ... (get_named_type): ... this. If result is FUNCTION_DECL for cgraph_node, return cgraph_node from pointee of return type if possible instead of emitting an error. (init_dynamic_diag_info): Adjust get_pointer_to_named_type callers to call get_named_type instead. Formatting fixes. * c-c++-common/pr90677.c: New test. Jakub --- gcc/c-family/c-format.c.jj 2019-10-05 09:35:12.917997709 +0200 +++ gcc/c-family/c-format.c 2019-11-19 13:05:10.113308578 +0100 @@ -4899,21 +4899,39 @@ init_dynamic_gfc_info (void) } } -/* Lookup the type named NAME and return a pointer-to-NAME type if found. - Otherwise, return void_type_node if NAME has not been used yet, or NULL_TREE if - NAME is not a type (issuing an error). */ +/* Lookup the type named NAME and return a NAME type if found. + Otherwise, return void_type_node if NAME has not been used yet, + or NULL_TREE if NAME is not a type (issuing an error). */ static tree -get_pointer_to_named_type (const char *name) +get_named_type (const char *name) { tree result; - if ((result = maybe_get_identifier (name))) + if (tree id = maybe_get_identifier (name)) { - result = identifier_global_value (result); + result = identifier_global_value (id); if (result) { if (TREE_CODE (result) != TYPE_DECL) { + if (TREE_CODE (result) == FUNCTION_DECL + && !strcmp (name, "cgraph_node") + && TREE_CODE (TREE_TYPE (result)) == FUNCTION_TYPE) + { + /* Before GCC 4.7, there used to be + struct cgraph_node; + struct cgraph_node *cgraph_node (tree); + Don't error in this case, so that GCC 9+ can still + compile GCC 4.6 and earlier. */ + tree res = TREE_TYPE (TREE_TYPE (result)); + if (TREE_CODE (res) == POINTER_TYPE + && (TYPE_NAME (TREE_TYPE (res)) == id + || (TREE_CODE (TYPE_NAME (TREE_TYPE (res))) + == TYPE_DECL + && (DECL_NAME (TYPE_NAME (TREE_TYPE (res))) + == id)))) + return TREE_TYPE (res); + } error ("%qs is not defined as a type", name); result = NULL_TREE; } @@ -4953,23 +4971,24 @@ init_dynamic_diag_info (void) an extra type level. */ if ((local_tree_type_node = maybe_get_identifier ("tree"))) { - local_tree_type_node = identifier_global_value (local_tree_type_node); + local_tree_type_node + = identifier_global_value (local_tree_type_node); if (local_tree_type_node) { if (TREE_CODE (local_tree_type_node) != TYPE_DECL) { error ("% is not defined as a type"); - local_tree_type_node = 0; + local_tree_type_node = NULL_TREE; } else if (TREE_CODE (TREE_TYPE (local_tree_type_node)) != POINTER_TYPE) { error ("% is not defined as a pointer type"); - local_tree_type_node = 0; + local_tree_type_node = NULL_TREE; } else - local_tree_type_node = - TREE_TYPE (TREE_TYPE (local_tree_type_node)); + local_tree_type_node + = TREE_TYPE (TREE_TYPE (local_tree_type_node)); } } else @@ -4979,12 +4998,12 @@ init_dynamic_diag_info (void) /* Similar to the above but for gimple*. */ if (!local_gimple_ptr_node || local_gimple_ptr_node == void_type_node) - local_gimple_ptr_node = get_pointer_to_named_type ("gimple"); + local_gimple_ptr_node = get_named_type ("gimple"); /* Similar to the above but for cgraph_node*. */ if (!local_cgraph_node_ptr_node || local_cgraph_node_ptr_node == void_type_node) - local_cgraph_node_ptr_node = get_pointer_to_named_type ("cgraph_node"); + local_cgraph_node_ptr_node = get_named_type ("cgraph_node"); static tree hwi; --- gcc/testsuite/c-c++-common/pr90677.c.jj 2019-11-19 13:02:45.709465310 +0100 +++ gcc/testsuite/c-c++-common/pr90677.c 2019-11-19 13:03:58.925371802 +0100 @@ -0,0 +1,11 @@ +/* PR c/90677 */ +/* { dg-do compile } */ +/* { dg-options "-W -Wall" } */ + +struct cgraph_node; +union tree_node; +typedef union tree_node *tree; +union gimple_statement_d; +typedef union gimple_statement_d *gimple; +struct cgraph_node *cgraph_node (tree); +void foo (int, const char *, ...) __attribute__((__format__(__gcc_diag__, 2, 3)));