From patchwork Tue Dec 3 02:47:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 296053 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6BD1D2C0098 for ; Tue, 3 Dec 2013 13:49:27 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=vEXhVaDnroSSL5FT52HxLAqs9fYIgLnFKwRlM3i+RTE5DNFz6Xw/M Z25BfJCKTz87X2QgftxBswqggi6wrUudU0tysMy4K1UfoZ5NZ7f1FVlMn2d5hHEl VKcB+ZIbQGC5ls4wEs5ed6qo47WGfLBSZdwUNj3bu7TdDgdfZQlDEo= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=uw8WVh298h6FqJrXStSED38sf8s=; b=CvtExrJInxXV2R3MzfRI h84EINrZ8Yirt7k4Rh1FMOB/xzt4dWYGRxzmeTHEvcDMtvcOVwrR9yphF8assm70 Ivo04wvk5UEuSQqxUfi1KEzuTbbGnth6MGQwcbhIjccP0Q+xTE096u5VkhLuxcHG +Fu+bex+8g05Q1wavjsBLDg= Received: (qmail 25223 invoked by alias); 3 Dec 2013 02:49:15 -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 25200 invoked by uid 89); 3 Dec 2013 02:49:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL, BAYES_40, RDNS_NONE autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from Unknown (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Dec 2013 02:47:48 +0000 Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1Vng1N-0004O1-1T from joseph_myers@mentor.com for gcc-patches@gcc.gnu.org; Mon, 02 Dec 2013 18:47:33 -0800 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Mon, 2 Dec 2013 18:47:32 -0800 Received: from digraph.polyomino.org.uk (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Tue, 3 Dec 2013 02:47:30 +0000 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.76) (envelope-from ) id 1Vng1J-00008T-H4 for gcc-patches@gcc.gnu.org; Tue, 03 Dec 2013 02:47:29 +0000 Date: Tue, 3 Dec 2013 02:47:29 +0000 From: "Joseph S. Myers" To: Subject: Diagnose array assignment for C90 (PR 58235) Message-ID: MIME-Version: 1.0 This patch fixes bug 58235, a corner case with non-lvalue arrays in C90 where the assignment of a non-lvalue array to an expression with array type was not diagnosed. A specific check is added for assignments to arrays (which are never valid). Bootstrapped with no regressions on x86_64-unknown-linux-gnu. Applied to mainline. c: 2013-12-02 Joseph Myers PR c/58235 * c-typeck.c (build_modify_expr): Diagnose assignment to expression with array type. testsuite: 2013-12-02 Joseph Myers PR c/58235 * gcc.dg/c90-array-lval-8.c: New test. Index: testsuite/gcc.dg/c90-array-lval-8.c =================================================================== --- testsuite/gcc.dg/c90-array-lval-8.c (revision 0) +++ testsuite/gcc.dg/c90-array-lval-8.c (revision 0) @@ -0,0 +1,20 @@ +/* Test for non-lvalue arrays: test that they cannot be assigned to + array variables. PR 58235. */ +/* { dg-do compile } */ +/* { dg-options "-std=iso9899:1990 -pedantic-errors" } */ + +struct s { char c[1]; } x; +struct s f (void) { return x; } + +void +g (void) +{ + char c[1]; + c = f ().c; /* { dg-error "array" } */ +} + +void +h (void) +{ + char c[1] = f ().c; /* { dg-error "array" } */ +} Index: c/c-typeck.c =================================================================== --- c/c-typeck.c (revision 205585) +++ c/c-typeck.c (working copy) @@ -5205,6 +5205,14 @@ build_modify_expr (location_t location, tree lhs, if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK) return error_mark_node; + /* Ensure an error for assigning a non-lvalue array to an array in + C90. */ + if (TREE_CODE (lhstype) == ARRAY_TYPE) + { + error_at (location, "assignment to expression with array type"); + return error_mark_node; + } + /* For ObjC properties, defer this check. */ if (!objc_is_property_ref (lhs) && !lvalue_or_else (location, lhs, lv_assign)) return error_mark_node;