From patchwork Tue Mar 13 20:17:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 885466 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-474681-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="stET43o7"; 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 4016762nk4z9sRG for ; Wed, 14 Mar 2018 07:35:29 +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; q=dns; s=default; b=RQLExRaVl2W4fqPtyl081yiXuIe3M XrRjmQJUoasL8h4A34giU4zSuvEd5Jc7AgdMNG1LtJq7M2KC657SesZBJOWPEEt2 Kfr5npbXoxX3+8nIgbCnXjCLdPuw8mQAhHQePdOtbiFAIy0htTu7ztaHHwz/NK8X mYPW3m1bYHp2uU= 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; s=default; bh=bd1wQiwcYwFmPRox7rlW5MD9SnA=; b=stE T43o7BkOI/H4IT1fokPQr8umxqxY5fXn9xGnt+9QVFP+6Ldz3/7rw+6Nl3Vjjr1s /sJ+//R/txt4ti/kfYy3ZcHnNGhTU/7Xe/x69Ex+qPbMP6KnSpTzONxLc0Dph+G0 Bs46qoNwjCQZnPGKVaB7AP2nfDy4WhszYiHHyFVQ= Received: (qmail 5007 invoked by alias); 13 Mar 2018 20:35:21 -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 4996 invoked by uid 89); 13 Mar 2018 20:35:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Mar 2018 20:35:20 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2DEE4068040 for ; Tue, 13 Mar 2018 20:35:18 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.36.118.110]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91E3A1102E2C for ; Tue, 13 Mar 2018 20:35:18 +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 w2DKHlrF001585; Tue, 13 Mar 2018 21:17:48 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w2DKHkju001584; Tue, 13 Mar 2018 21:17:46 +0100 Date: Tue, 13 Mar 2018 21:17:46 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix ICE with builtin redefinition (PR c++/84843) Message-ID: <20180313201746.GC8577@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! If we return olddecl on an (invalid) builtin function redefinition rather than redeclaration, we ICE shortly afterwards, because we assume we have non-NULL DECL_INITIAL on whatever is returned (except for error_mark_node). The following patch errors unconditionally for definitions of builtin functions, and also makes sure to return error_mark_node if we've emitted an error from the permerror. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-03-13 Jakub Jelinek PR c++/84843 * decl.c (duplicate_decls): For redefinition of built-in, use error and return error_mark_node. For redeclaration, return error_mark_node rather than olddecl if !flag_permissive. * g++.dg/ext/pr84843-1.C: New test. * g++.dg/ext/pr84843-2.C: New test. Jakub --- gcc/cp/decl.c.jj 2018-03-09 19:00:44.350969146 +0100 +++ gcc/cp/decl.c 2018-03-13 14:56:45.244872506 +0100 @@ -1583,13 +1583,20 @@ next_arg:; || memcmp (name + len - strlen ("_chk"), "_chk", strlen ("_chk") + 1) != 0)) { + if (DECL_INITIAL (newdecl)) + { + error_at (DECL_SOURCE_LOCATION (newdecl), + "definition of %q#D ambiguates built-in " + "declaration %q#D", newdecl, olddecl); + return error_mark_node; + } if (permerror (DECL_SOURCE_LOCATION (newdecl), "new declaration %q#D ambiguates built-in" " declaration %q#D", newdecl, olddecl) && flag_permissive) inform (DECL_SOURCE_LOCATION (newdecl), "ignoring the %q#D declaration", newdecl); - return olddecl; + return flag_permissive ? olddecl : error_mark_node; } } --- gcc/testsuite/g++.dg/ext/pr84843-1.C.jj 2018-03-13 14:55:15.927831678 +0100 +++ gcc/testsuite/g++.dg/ext/pr84843-1.C 2018-03-13 14:57:51.652902862 +0100 @@ -0,0 +1,9 @@ +// PR c++/84843 +// { dg-do compile } +// { dg-options "-fpermissive" } + +extern "C" int +__atomic_compare_exchange (int x, int y) // { dg-error "ambiguates built-in declaration" } +{ + return x + y; +} --- gcc/testsuite/g++.dg/ext/pr84843-2.C.jj 2018-03-13 14:55:19.349833246 +0100 +++ gcc/testsuite/g++.dg/ext/pr84843-2.C 2018-03-13 14:57:58.205905859 +0100 @@ -0,0 +1,9 @@ +// PR c++/84843 +// { dg-do compile } +// { dg-options "" } + +extern "C" int +__atomic_compare_exchange (int x, int y) // { dg-error "ambiguates built-in declaration" } +{ + return x + y; +}