From patchwork Thu Nov 13 18:07:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ed Smith-Rowland <3dw4rd@verizon.net> X-Patchwork-Id: 410534 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 1100A140120 for ; Fri, 14 Nov 2014 05:08:14 +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 :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=Ah2A0byseLYRl1X6T8dAopLnnfkEl9KtNc46oZhb/QTH3Z lnyrXTSwIQ2+F7V7F2173z6BDwm6WWKeVEOCCqiqxj3QOxzYWFNANIcw32K+ywgw 2JsVPF5yWgkkGMagfMXO3WBeEf0gWLiL/1UCh+VE7Bqv72Iwl1jb3+e1siLlc= 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:date:from:mime-version:to:subject:content-type; s= default; bh=XE1A3Bya2BJ6dZYcDp/004dNYsc=; b=ljPF04vkEOtTJKAHKZeD oxzqW1LIAfjX1LSbvYsF4PrfpQkg9vcv8wbJKZAXux4BQHJMIiNlT0nXuHBz11tf xUhDkDoEEq6f3Tk5Gl8nv3Li6aDrMX0qSPMQCoVoe+Zb3ZW7OZ5C13gFiLHLHq83 U5mVN6/OGewPcXobZ20cklI= Received: (qmail 20615 invoked by alias); 13 Nov 2014 18:08:07 -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 20596 invoked by uid 89); 13 Nov 2014 18:08:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: vms173009pub.verizon.net Received: from vms173009pub.verizon.net (HELO vms173009pub.verizon.net) (206.46.173.9) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 13 Nov 2014 18:08:03 +0000 Received: from [192.168.1.4] ([173.69.187.187]) by vms173009.mailsrvcs.net (Oracle Communications Messaging Server 7.0.5.32.0 64bit (built Jul 16 2014)) with ESMTPA id <0NEZ007KJP17EV80@vms173009.mailsrvcs.net> for gcc-patches@gcc.gnu.org; Thu, 13 Nov 2014 12:07:57 -0600 (CST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=c/scmq5g c=1 sm=1 tr=0 a=HL81GjYeqzsqUVf3d/2DhQ==:117 a=rkJuIV0pGx0A:10 a=o1OHuDzbAAAA:8 a=oR5dmqMzAAAA:8 a=hTZS6uLwhHpx5LOQAS/v3KalXBI=:19 a=-9mUelKeXuEA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=9iDbn-4jx3cA:10 a=cKsnjEOsciEA:10 a=aMyE6gdl0bA0yqxT5lAA:9 a=QEXdDO2ut3YA:10 a=x74zWDBbMbDHqPF56CIA:9 a=f2259HPKLo6bgi3po8YA:9 Message-id: <5464F37B.8060903@verizon.net> Date: Thu, 13 Nov 2014 13:07:55 -0500 From: Ed Smith-Rowland <3dw4rd@verizon.net> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-version: 1.0 To: gcc-patches , Jason Merrill Subject: [PATCH PC preprocessor/63831] - [5 Regression] r217292 causes segfaults with -MM Content-type: multipart/mixed; boundary=------------000707070109080804010002 There were segfaults on preprocess-only involving __has_attribute. -MM and -E both bombed with __has_attribute. Several codebases use __has_attribute this (because of clang). This problem would have been found with the SD-6 macro __has_cpp_attribute as well so just taking out the extra macro is not the answer. The answer is to provide the preprocessor pretty printer with a callback for has_attribute to match that of the lexer. I don't know how "pretty" the output is but the thing doesn't crash and we can fix the output if needs be later on. This patch builds and tests clean on x86_64-linux. OK? Ed libcpp: 2014-11-13 Edward Smith-Rowland <3dw4rd@verizon.net> * expr.c (parse_has_attribute): Only call pfile->cb.has_attribute if it is non-null. gcc/c-family: 2014-11-13 Edward Smith-Rowland <3dw4rd@verizon.net> * c-lex.c (cb_has_attribute): Remove old comment. * c-cppbuiltin.c (cb_has_attribute): New callback; (init_pp_output): Set it. gcc/testsuite: 2014-11-13 Edward Smith-Rowland <3dw4rd@verizon.net> * g++.dg/cpp1y/pr63831.C: New. * g++.dg/cpp1y/pr63831.h: New. Index: libcpp/expr.c =================================================================== --- libcpp/expr.c (revision 217482) +++ libcpp/expr.c (working copy) @@ -2162,7 +2162,10 @@ result.high = 0; result.overflow = false; - result.low = pfile->cb.has_attribute (pfile); + if (pfile->cb.has_attribute) + result.low = pfile->cb.has_attribute (pfile); + else + result.low = 0; pfile->state.in__has_attribute__--; Index: gcc/c-family/c-lex.c =================================================================== --- gcc/c-family/c-lex.c (revision 217482) +++ gcc/c-family/c-lex.c (working copy) @@ -306,7 +306,6 @@ if (token->type == CPP_NAME) { - //node = token->val.node.node; const cpp_token *nxt_token = cpp_peek_token (pfile, 0); if (c_dialect_cxx() && nxt_token->type == CPP_SCOPE) { Index: gcc/c-family/c-ppoutput.c =================================================================== --- gcc/c-family/c-ppoutput.c (revision 217482) +++ gcc/c-family/c-ppoutput.c (working copy) @@ -80,6 +80,7 @@ static void cb_def_pragma (cpp_reader *, source_location); static void cb_read_pch (cpp_reader *pfile, const char *name, int fd, const char *orig_name); +static int cb_has_attribute (cpp_reader *); /* Preprocess and output. */ void @@ -129,6 +130,8 @@ } } + cb->has_attribute = cb_has_attribute; + if (flag_dump_includes) cb->include = cb_include; @@ -510,6 +513,48 @@ print.src_line++; } +static int +cb_has_attribute (cpp_reader * pfile) +{ + bool paren = false; + const cpp_token * token = cpp_get_token (pfile); + + fputs ("__has_attribute__ ", print.outf); + + if (token->type == CPP_OPEN_PAREN) + { + paren = true; + token = cpp_get_token (pfile); + putc ('(', print.outf); + } + if (token->type == CPP_NAME) + { + const cpp_token *nxt_token = cpp_peek_token (pfile, 0); + if (c_dialect_cxx() && nxt_token->type == CPP_SCOPE) + { + nxt_token = cpp_get_token (pfile); // Eat scope. + nxt_token = cpp_get_token (pfile); + if (nxt_token->type == CPP_NAME) + { + fprintf (print.outf, "%s::%s", + cpp_token_as_text (pfile, token), + cpp_token_as_text (pfile, nxt_token)); + } + } + else + { + fprintf (print.outf, "%s", cpp_token_as_text (pfile, token)); + } + } + if (paren) + { + cpp_get_token (pfile); + putc (')', print.outf); + } + + return 0; +} + static void cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line, cpp_hashnode *node) Index: gcc/testsuite/g++.dg/cpp1y/pr63831.C =================================================================== --- gcc/testsuite/g++.dg/cpp1y/pr63831.C (revision 0) +++ gcc/testsuite/g++.dg/cpp1y/pr63831.C (working copy) @@ -0,0 +1,4 @@ +// { dg-do compile } +// { dg-options "-I${srcdir}/g++.dg/cpp1y -MM" } + +#include Index: gcc/testsuite/g++.dg/cpp1y/pr63831.h =================================================================== --- gcc/testsuite/g++.dg/cpp1y/pr63831.h (revision 0) +++ gcc/testsuite/g++.dg/cpp1y/pr63831.h (working copy) @@ -0,0 +1,7 @@ +#ifndef __has_attribute +# define __has_attribute(x) 0 +#endif + +#if __has_attribute(alloc_size) +# define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X))) +#endif