From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 100542 invoked by alias); 23 Aug 2018 15:14:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 100526 invoked by uid 89); 23 Aug 2018 15:14:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:sk:l11-v6m, misinterpreted X-HELO: mail-qt0-f196.google.com Received: from mail-qt0-f196.google.com (HELO mail-qt0-f196.google.com) (209.85.216.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Aug 2018 15:14:00 +0000 Received: by mail-qt0-f196.google.com with SMTP id t39-v6so5864095qtc.8 for ; Thu, 23 Aug 2018 08:14:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=INMEDE+g6U2MSDZOsn1a7Egv9ZpuuNd87fYmsc1uIEs=; b=gVaqOGnHkNlWBfl4ywg/97G+MGOFCaSK8BYVzjQwliuIGZvaI5qxnHoa8Ij9C5apzc cFJzTamr230XvDqaXf3lmCZrf5MjWcvCJRQP+o43+XWHq1k6k8nn3hBykxcSDL2+2Sm+ mAnasBamI5b/QL7tcUjYyxo+szN1T93zOQPNkUdtSGLiDl1p3x7XhOnuDuFbsdB3sAW8 vGEuJ0uiBbjBlS1S4ONhE4zlz7XEn5rNKoqupGw7Fuw2sgysQ1jZBHnmZV92zLYte5md cgN3vfBZGa0ERB/kU0eMK0sax/b/ka6aVhKGz1qDiaeAFnJePOPja9JgI5EMc4GiamKM 52WQ== Return-Path: Received: from localhost.localdomain (75-166-100-32.hlrn.qwest.net. [75.166.100.32]) by smtp.gmail.com with ESMTPSA id i85-v6sm3488204qkh.3.2018.08.23.08.13.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Aug 2018 08:13:57 -0700 (PDT) Subject: Re: [PATCH] print full STRING_CST in Gimple dumps (PR 87052) To: Michael Matz , Richard Biener References: <5ee56fe9-bf96-196f-6bd6-6ecbda2d1ca0@gmail.com> <95ad560d-2f0d-b102-d852-3284c8da685a@gmail.com> Cc: GCC Patches From: Martin Sebor Message-ID: Date: Thu, 23 Aug 2018 15:14:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-08/txt/msg01491.txt.bz2 On 08/23/2018 08:07 AM, Michael Matz wrote: > Hi, > > On Thu, 23 Aug 2018, Richard Biener wrote: > >>>> Can you write a not \0 terminated string literal in C? >>> >>> Yes: char a[2] = "12"; >> >> I thought they are fully defined in translation phase #1 ... > > No, you can't write a string literal which is not zero terminated, because > in translation phase 7 a zero code is appended to all character sequences > resulting from string literals, which is then used to allocate and > initialize a static (wide) character array of just the right size, > including the zero code. > > The above construct uses that static char[3] array from the string literal > to initialize a char[2] array (which is explicitely allowed), and _that_ > one is not zero terminated. But it's also no string literal. Yes, you're right. I misinterpreted Richard's question as asking if one could construct an unterminated array of chars using a string literal. The distinction that I thought would be useful to capture in Gimple is between "12" that initializes an array of two elements (and where the nul doesn't fit) vs "12" that initializes one of three elements (and where the nul does fit). It's probably not terribly important when the array type also appears in Gimple like in the case above but there are (perhaps corner) cases where it doesn't, as in the second one below: char a[2] = "12"; char *p = (char[2]){ "12" }; which ends up represented as: char a[2]; char * p; char D.1910[2]; try { a = "12"; D.1910 = "12"; p = &D.1910; } Martin