From patchwork Thu Aug 12 07:57:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1516165 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=omQTJO9F; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GlfFg2Gjdz9sX3 for ; Thu, 12 Aug 2021 17:58:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E4533835815 for ; Thu, 12 Aug 2021 07:58:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E4533835815 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1628755107; bh=ETxfcp75DcSjeud/KeUJ7HeaKh844F3t9sGCQn0mcmQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=omQTJO9FbzOqD/WvC0wpij81Ws9cUw4eQ3EG4RLiCmL0+RwozD0iLDS79tDmJLwO4 gWYHw2BbX+QbPPjOpHAD0FYE5+uPWFQNTrzSzzbwukZb1QZtRlnGDxVW5q0GP3Zj7U 2nK4972LhRubghHbLNzX8lx/JQJI+Hp784/Oj+Uk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 881F23861881 for ; Thu, 12 Aug 2021 07:58:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 881F23861881 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-213-qQSE55W6PmKnvTiuTHSF9Q-1; Thu, 12 Aug 2021 03:58:05 -0400 X-MC-Unique: qQSE55W6PmKnvTiuTHSF9Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E613D100A61D; Thu, 12 Aug 2021 07:58:03 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.120]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ED99660BF1; Thu, 12 Aug 2021 07:57:59 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 17C7vtf01041787 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 12 Aug 2021 09:57:55 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 17C7vp9v1041786; Thu, 12 Aug 2021 09:57:51 +0200 Date: Thu, 12 Aug 2021 09:57:51 +0200 To: "Joseph S. Myers" , Marek Polacek , Jason Merrill Subject: [PATCH] libcpp: Fix ICE with -Wtraditional preprocessing [PR101638] Message-ID: <20210812075751.GX2380545@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase ICEs in cpp_sys_macro_p, because cpp_sys_macro_p is called for a builtin macro which doesn't use node->value.macro union member but a different one and so dereferencing it ICEs. As the testcase is distilled from contemporary glibc headers, it means basically -Wtraditional now ICEs on almost everything. The fix can be either the patch below, return false for builtin macros, or we could instead return true for builtin macros and adjust the function comment, or the fix could be also (untested): Jakub --- libcpp/expr.c 2021-05-07 10:34:46.345122608 +0200 +++ libcpp/expr.c 2021-08-12 09:54:01.837556365 +0200 @@ -783,13 +783,13 @@ cpp_classify_number (cpp_reader *pfile, /* Traditional C only accepted the 'L' suffix. Suppress warning about 'LL' with -Wno-long-long. */ - if (CPP_WTRADITIONAL (pfile) && ! cpp_sys_macro_p (pfile)) + if (CPP_WTRADITIONAL (pfile)) { int u_or_i = (result & (CPP_N_UNSIGNED|CPP_N_IMAGINARY)); int large = (result & CPP_N_WIDTH) == CPP_N_LARGE && CPP_OPTION (pfile, cpp_warn_long_long); - if (u_or_i || large) + if ((u_or_i || large) && ! cpp_sys_macro_p (pfile)) cpp_warning_with_line (pfile, large ? CPP_W_LONG_LONG : CPP_W_TRADITIONAL, virtual_location, 0, "traditional C rejects the \"%.*s\" suffix", The builtin macros at least currently don't add any suffixes or numbers -Wtraditional would like to warn about. For floating point suffixes, -Wtraditional calls cpp_sys_macro_p only right away before emitting the warning, but in the above case the ICE is because cpp_sys_macro_p is called even if the number doesn't have any suffixes (that is I think always for builtin macros right now). Bootstrapped/regtested on x86_64-linux and i686-linux. Ok for trunk, or do you prefer to return true for builtin macros from cpp_sys_macro_p instead, and/or do you want the above cpp_classify_number change (which can be done either alone or in addition to some cpp_sys_macro_p change)? 2021-08-12 Jakub Jelinek PR preprocessor/101638 * macro.c (cpp_sys_macro_p): Return false instead of crashing on builtin macros. * gcc.dg/cpp/pr101638.c: New test. --- libcpp/macro.c.jj 2021-07-20 17:03:08.036449892 +0200 +++ libcpp/macro.c 2021-08-11 20:50:11.212662720 +0200 @@ -3127,7 +3127,10 @@ cpp_sys_macro_p (cpp_reader *pfile) else node = pfile->context->c.macro; - return node && node->value.macro && node->value.macro->syshdr; + return (node + && cpp_user_macro_p (node) + && node->value.macro + && node->value.macro->syshdr); } /* Read each token in, until end of the current file. Directives are --- gcc/testsuite/gcc.dg/cpp/pr101638.c.jj 2021-08-11 20:53:04.785289640 +0200 +++ gcc/testsuite/gcc.dg/cpp/pr101638.c 2021-08-11 20:52:36.086682006 +0200 @@ -0,0 +1,7 @@ +/* PR preprocessor/101638 */ +/* { dg-do preprocess } */ +/* { dg-options "-Wtraditional" } */ + +#define foo(attr) __has_attribute(attr) +#if foo(__deprecated__) +#endif