From patchwork Thu Jan 21 22:55:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 571373 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 BFE5D140297 for ; Fri, 22 Jan 2016 09:55:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=kXB/6OsL; dkim-atps=neutral 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=v0F9GDkgg233RhNftoMgoLEhtZ0jrD9l9nxUH3JN0bsAX0 7ZatMpF9Ft6+H2Wt4Ss+xWRyPxsaabKOHqVed+LzK5rtbd07nmrlRyPF4sw2gCTV iRwYK5fDHNJAWQM4YnAiryAVhVNxhpdW4YuUf29Sn6B7gp2G3xLOl9uhyqZD4= 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=6Lvy26dFOMpMVNoUkO4KyWkTybs=; b=kXB/6OsLREdwWcjywhnh sdpU35GA/EgLwk6j5yy1FEe6lr+3zvrtSwaFwUv6KKTs2lKKrU4MJBFPVIVKffSJ 40+zZA4z1xV8iv0aXmOL9i9ZaNoUCUIz9q9qaJP3rjJUtTH+WEz3xWx8swVCZCAG sBMZ0OkKr0tT3m72zCRmdGM= Received: (qmail 45046 invoked by alias); 21 Jan 2016 22:55:38 -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 44579 invoked by uid 89); 21 Jan 2016 22:55:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 spammy=TYPE_MAX_VALUE, type_max_value, TYPE_DOMAIN, type_domain X-HELO: mail-qg0-f53.google.com Received: from mail-qg0-f53.google.com (HELO mail-qg0-f53.google.com) (209.85.192.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 21 Jan 2016 22:55:35 +0000 Received: by mail-qg0-f53.google.com with SMTP id e32so44910728qgf.3 for ; Thu, 21 Jan 2016 14:55:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:content-type; bh=+S0hl8RhKi/fGR4nZOVkJNSq7w7nejiElNuRA2EHHJU=; b=PmQ27UbwWXRBG2NWdLEtic6NdLbAo1/YGjbsvMybQKQtY+37qf7MuofMYDl16JX0M1 l+1qkXCsAHvTJO5gj2JhRtETqvaOOmT5MBoEye/17I9HEu5LBHcq5dEKki2/QZChBynU ZiIv/U0/sKGWNNZl8r8Sj1HG1kVw3cSDE1QuEuwE2N4NOX8ZmzRzCfUf1wuBTOUB7hW+ 8JQHcRUqBHHFpHSFJe+ZryBR75pL2kBND9qOZguA8PybTHs7RTVlyHnPBZ9ry1OeiqOE 80M4Qy9Q1RCALFOe+T/rQgd5tqXFRva+BOiFWWKuAV3xmNsXbDcsHnxjJ3sqEG51kdrG abVw== X-Gm-Message-State: ALoCoQlcrYZU0Q744NUDAtOk9gl/bEN9Xvjt6SKI/qVt6WBJUUdwIqjPc3VIdx4Wln+qekSWYlsF9NGZdR6DqHVO8bhyQwj8XQ== X-Received: by 10.140.101.201 with SMTP id u67mr55686585qge.33.1453416933323; Thu, 21 Jan 2016 14:55:33 -0800 (PST) Received: from [192.168.0.26] (71-212-229-169.hlrn.qwest.net. [71.212.229.169]) by smtp.gmail.com with ESMTPSA id p188sm1519706qhb.34.2016.01.21.14.55.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jan 2016 14:55:32 -0800 (PST) Message-ID: <56A161DD.3000101@gmail.com> Date: Thu, 21 Jan 2016 15:55:25 -0700 From: Martin Sebor User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Gcc Patch List , Jason Merrill Subject: [PATCH] #69290 - [6 Regression] ICE on invalid initialization of a flexible array member X-IsSubscribed: yes The attached patch fixes another ICE triggered by an invalid initialization of a flexible array member, and caused by making the upper bound of the TYPE_DOMAIN() of such arrays null. Martin PS Jason, when you have a chance, there are two other patches for similar P1 failures waiting for your review: [PATCH] fix #69251 - [6 Regression] ICE in unify_array_domain on a flexible array member https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01348.html [PATCH] fix #69253 - [6 Regression] ICE in cxx_incomplete_type_diagnostic initializing a flexible array member with empty string https://gcc.gnu.org/ml/gcc-patches/2016-01/msg01325.html PR c++/69290 - [6 Regression] ICE on invalid initialization of a flexible array member gcc/testsuite/ChangeLog: 2016-01-21 Martin Sebor PR c++/69290 * g++.dg/ext/flexary12.C: New test. gcc/cp/ChangeLog: 2016-01-21 Martin Sebor PR c++/69290 * tree.c (array_of_runtime_bound_p): Handle flexible array members. Index: gcc/cp/tree.c =================================================================== --- gcc/cp/tree.c (revision 232692) +++ gcc/cp/tree.c (working copy) @@ -937,9 +937,12 @@ array_of_runtime_bound_p (tree t) tree dom = TYPE_DOMAIN (t); if (!dom) return false; - tree max = TYPE_MAX_VALUE (dom); - return (!potential_rvalue_constant_expression (max) - || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max))); + if (tree max = TYPE_MAX_VALUE (dom)) + return (!potential_rvalue_constant_expression (max) + || (!value_dependent_expression_p (max) && !TREE_CONSTANT (max))); + + /* Flexible array members have no upper bound. */ + return false; } /* Return a reference type node referring to TO_TYPE. If RVAL is Index: gcc/testsuite/g++.dg/ext/flexary12.C =================================================================== --- gcc/testsuite/g++.dg/ext/flexary12.C (revision 0) +++ gcc/testsuite/g++.dg/ext/flexary12.C (working copy) @@ -0,0 +1,63 @@ +// PR c++/69290 - [6 Regression] g++ ICE on invalid initialization +// of a flexible array member +// { dg-do compile } + +// Suppress pedantic errors about initialization of a flexible array member. +// { dg-options "-Wno-pedantic" } + +struct A { + int a []; // { dg-error "flexible array member .A::a. in an otherwise empty .struct A." } +}; + +void f1 () +{ + // This is the meat of the test from c++/69290: + struct A a + = { "c" }; // { dg-error "invalid conversion from .const char\\*. to .int." } + + (void)&a; +} + + +// Exercise other forms of invalid initialization besides the one in the bug. +struct B { + int n; + int a []; +}; + +void f2 () +{ + struct B b1 + = { 0, "c" }; // { dg-error "invalid conversion from .const char\\*. to .int." } + + (void)&b1; + + const char s[] = "c"; + struct B b2 + = { 0, s }; // { dg-error "invalid conversion from .const char\\*. to .int." } + + (void)&b2; +} + +struct D { + int a []; // { dg-error "flexible array member .D::a. in an otherwise empty .struct D." } + D (); +}; + +D::D (): + a ("c") // { dg-error "incompatible types in assignment of .const char \\\[2\\\]. to .int \\\[\\\]." } +{ } + + +template +struct C { + T a []; // { dg-error "flexible array member" } +}; + +void f3 () +{ + struct C cd + = { "c" }; // { dg-error "cannot convert .const char\\*. to .double." } + + (void)&cd; +}