From patchwork Tue Oct 10 18:54:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 824023 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-463887-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.b="OGblqB+9"; 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 3yBR9b6mDjz9t6M for ; Wed, 11 Oct 2017 05:54:27 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=BB4g7FmcuNY3wq8Xmao5jCusrypMf4zYTWSfDnwXPKs5rs7BdW nAgLKr8dAzpTjso83E8xYC+D2L2hbDRtO0JEBJAHW5h6O0P9n8WWtjey5YF3K134 qkovZx7Sc4SOBAD4i+ujFUx/xQ/5Rdyr39669Sc7kIKudqY74Cmfr/1PI= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=fdCpI9oHcLhtfw2I9d1x1wDZKGw=; b=OGblqB+9Ty9vYTeHbHvy RGoOX4OH8JCCbNCY6eqpp9MpStlamG8RC/xpFTbRcP7V8aogXTBpY6NBmUHfmt01 +tDmGxNZNwlDyC5Lk/4WUMO4gvg8m9MSoaPRbbxz/UfKwp5ME9w3IUlnk+sYI9hD pj/FYDxlSC0lRP1r9mt3+os= Received: (qmail 82837 invoked by alias); 10 Oct 2017 18:54:19 -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 82827 invoked by uid 89); 10 Oct 2017 18:54:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=uch, Hx-languages-length:1520, H*M:7e3c, H*MI:7e3c X-HELO: mail-qt0-f176.google.com Received: from mail-qt0-f176.google.com (HELO mail-qt0-f176.google.com) (209.85.216.176) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 10 Oct 2017 18:54:18 +0000 Received: by mail-qt0-f176.google.com with SMTP id f15so54364070qtf.7 for ; Tue, 10 Oct 2017 11:54:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=kIB4MIgBcpMYs+E7orL9EH2sdb5RqnpYblAqOsaTbVs=; b=VfRpDOFyKBN07jzdWlGK1eI2fQTBmfu5XsU4wOVdsz8mqlaXaij6rww1y196v+72zZ 9YF8MpN8gXC69ROwIbThldHzhP+qa+guh90R2bqQzfLUtTTyMCdV7Z5/hu7Fj46X2Bvr J34hr+YUpe9+jMPQcibJnil1sVst/ExOjoL0RmpIxVDtocpGdDOCI4wbQofLE5xtrItw mh3egRPvqdIiDfgD666EvR8QzgtzmKYqV6XYsjb7UXSi0/zDZQKeh28N1gHEZqKjK4D5 oGxTBc28t00mIGptjw3mTFi/yGxf/b96lzFSSTLIkk7uJ1wBm0xiKzzHH5mNRRA3h//f vN3A== X-Gm-Message-State: AMCzsaX0YEcXmgDLrYn/TXIYachjDJ086jUtZ6lDsJMmk5JsnGOhAlj3 INIoyiopSXNqYM39xAodtbU= X-Google-Smtp-Source: AOwi7QDtwuMaIsE0+koDhhNOh+duhf5KO4BzYI+1wD3vAhGAjY5ajSC9mok2x6qN11+NTSs8h2hLtg== X-Received: by 10.129.172.19 with SMTP id k19mr2767066ywh.321.1507661656143; Tue, 10 Oct 2017 11:54:16 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::3:9bf7]) by smtp.googlemail.com with ESMTPSA id p3sm776890ywh.32.2017.10.10.11.54.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Oct 2017 11:54:15 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [PATCH] preprocessor stringizing raw strings Message-ID: <73e05bed-c871-7e3c-dc01-dbf1f2b2b9d8@acm.org> Date: Tue, 10 Oct 2017 14:54:14 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 This patch fixes PR 82506, where we fail to properly stringize a raw string literal, which can contain a raw LF character. When we're not just preprocessing, there isn't a problem. The string literal gets correctly escaped into the assembly file. This is just a problem with preprocessing. Applying to trunk. nathan 2017-10-10 Nathan Sidwell libcpp/ PR preprocessor/82506 * macro.c (cpp_quote_string): Escape raw LFs. gcc/testsuite/ PR preprocessor/82506 * g++.dg/cpp/string-3.C: New. Index: gcc/testsuite/g++.dg/cpp/string-3.C =================================================================== --- gcc/testsuite/g++.dg/cpp/string-3.C (revision 0) +++ gcc/testsuite/g++.dg/cpp/string-3.C (working copy) @@ -0,0 +1,9 @@ +// PR c++/82506 +// { dg-do preprocess { target c++11 } } + +#define STRINGIZE(A) #A + +BEGIN STRINGIZE(R"( +)") END + +// { dg-final { scan-file string-3.ii "BEGIN \"R\\\"(\\n)\\\"\"\n END" } } Index: libcpp/macro.c =================================================================== --- libcpp/macro.c (revision 253587) +++ libcpp/macro.c (working copy) @@ -502,13 +502,21 @@ cpp_quote_string (uchar *dest, const uch { uchar c = *src++; - if (c == '\\' || c == '"') + switch (c) { + case '\n': + /* Naked LF can appear in raw string literals */ + c = 'n'; + /* FALLTHROUGH */ + + case '\\': + case '"': *dest++ = '\\'; + /* FALLTHROUGH */ + + default: *dest++ = c; } - else - *dest++ = c; } return dest;