From patchwork Fri Dec 14 19:39:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Iyer, Balaji V" X-Patchwork-Id: 206550 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]) by ozlabs.org (Postfix) with SMTP id 280172C0089 for ; Sat, 15 Dec 2012 06:39:32 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1356118773; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:Content-Type: MIME-Version:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=c7R2vSw PxFoCDIX3WycPM4w9NkE=; b=cyZ8d/vnAjlSfeGp1ZtShFFNuFiH8wAg3HSx5CU Nk0EufbxYDKWS2whZrfjfJ89u1gmQZw6GwPWXn5PrzTwuJ1rTo/ejyDc9qRG/i9y zMtTZIAcQlv5QmYCm8W7/q2sCnH4eS3+j0Omhrs2sd3Y17rA+I0sH91X1foVuDSo WNBE= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-ExtLoop1:Received:Received:Received:From:To:Subject:Date:Message-ID:Content-Type:MIME-Version:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=eavnjlyJJ7gghUbU5RqaS9za9UNG52oN23Vhqm7qzVdCov7fD/Bvj0R9baHbM1 ipT80Tgpx3Q1p35sZKcPg/2UlU2gfaUpahCxc8LwLw/fWg11ptylK8ZEPTurAs1c molbaDs72n+vgRhnYnGUIvB3VJtQQ80B5ZeoyNxJc3RUs=; Received: (qmail 1942 invoked by alias); 14 Dec 2012 19:39:19 -0000 Received: (qmail 1877 invoked by uid 22791); 14 Dec 2012 19:39:17 -0000 X-SWARE-Spam-Status: No, hits=-7.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, TW_TM X-Spam-Check-By: sourceware.org Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 14 Dec 2012 19:39:12 +0000 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 14 Dec 2012 11:39:03 -0800 X-ExtLoop1: 1 Received: from fmsmsx108.amr.corp.intel.com ([10.19.9.228]) by orsmga002.jf.intel.com with ESMTP; 14 Dec 2012 11:39:02 -0800 Received: from fmsmsx153.amr.corp.intel.com (10.19.17.7) by FMSMSX108.amr.corp.intel.com (10.19.9.228) with Microsoft SMTP Server (TLS) id 14.1.355.2; Fri, 14 Dec 2012 11:39:02 -0800 Received: from fmsmsx102.amr.corp.intel.com ([169.254.2.188]) by FMSMSX153.amr.corp.intel.com ([169.254.11.130]) with mapi id 14.01.0355.002; Fri, 14 Dec 2012 11:39:02 -0800 From: "Iyer, Balaji V" To: "gcc-patches@gcc.gnu.org" Subject: [PATCH][Cilkplus] Cilk_for: Reject certain induction vars and comparision Date: Fri, 14 Dec 2012 19:39:01 +0000 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes 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 Hello Everyone, This patch is for the Cilk Plus branch mainly affecting the C compiler. It will reject certain type of comparisons (e.g. ==) and complain about volatile or const induction variables all in _Cilk_for. Thanks, Balaji V. Iyer. Index: gcc/c/c-parser.c =================================================================== --- gcc/c/c-parser.c (revision 194496) +++ gcc/c/c-parser.c (working copy) @@ -11918,7 +11918,7 @@ c_cont_label = NULL_TREE; body = c_parser_c99_block_statement (parser); c_finish_cilk_loop (loc, cvar, cond, incr, body, c_cont_label, grain); - add_stmt (c_end_compound_stmt (UNKNOWN_LOCATION, block, true)); + add_stmt (c_end_compound_stmt (loc, block, true)); c_break_label = save_break; c_cont_label = save_cont; } Index: gcc/c/c-typeck.c =================================================================== --- gcc/c/c-typeck.c (revision 194496) +++ gcc/c/c-typeck.c (working copy) @@ -10970,7 +10970,7 @@ } void -c_finish_cilk_loop (location_t start_locus ATTRIBUTE_UNUSED, tree cvar, +c_finish_cilk_loop (location_t start_locus, tree cvar, tree cond, tree incr, tree body, tree clab, tree grain) { tree init; @@ -10982,12 +10982,12 @@ if (!cond) { - error ("_Cilk_for missing condition"); + error_at (start_locus, "_Cilk_for missing condition"); return; } if (!incr) { - error ("_Cilk_for missing increment"); + error_at (start_locus, "_Cilk_for missing increment"); return; } @@ -10999,7 +10999,7 @@ } if (!cvar) { - error ("missing control variable"); + error_at (start_locus, "missing control variable"); return; } if (clab) @@ -11007,7 +11007,31 @@ error_at (EXPR_LOCATION (clab), "_Cilk_for has continue"); return; } + + /* Checks if cond expr is one of the following: !=, <=, <, >=, or >. */ + if (TREE_CODE (cond) != NE_EXPR + && TREE_CODE (cond) != LT_EXPR + && TREE_CODE (cond) != LE_EXPR + && TREE_CODE (cond) != GT_EXPR + && TREE_CODE (cond) != GE_EXPR) + { + error_at (EXPR_LOCATION (cond), "_Cilk_for condition must be one of the " + "following: !=, <=, <, >= or >"); + return; + } + /* Checks if the induction variable is volatile or constant. */ + if (TREE_THIS_VOLATILE (cvar)) + { + error_at (start_locus, "_Cilk_for induction variable cannot be volatile"); + return; + } + else if (TREE_CONSTANT (cvar) || TREE_READONLY (cvar)) + { + error_at (start_locus, "_Cilk_for induction variable cannot be constant or " + "readonly"); + return; + } init = DECL_INITIAL (cvar); c_tree = build_stmt (UNKNOWN_LOCATION, CILK_FOR_STMT, NULL_TREE, NULL_TREE, Index: gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c =================================================================== --- gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c (revision 0) +++ gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c (revision 0) @@ -0,0 +1,20 @@ +/* + The variable may not be const or volatile + +*/ + +#include "controls.h" + +int a[SMALL_INT_ARRAY_SIZE]; + +int main (void) +{ + volatile int ii; + const int jj; + + + _Cilk_for(ii = 0; ii < SMALL_INT_ARRAY_SIZE; ii++) /* { dg-error "_Cilk_for induction variable cannot be volatile." } */ + { + a[ii] = ii; + } +} Index: gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c =================================================================== --- gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c (revision 0) +++ gcc/testsuite/gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c (revision 0) @@ -0,0 +1,17 @@ +/* + The operator denoted OP shall be one of !=, <=, <, >=, or > + +*/ + +#define ARRAY_SIZE 10000 + +int a[ARRAY_SIZE]; + +int main (void) +{ + int ii; + _Cilk_for(ii = 0; ii == ARRAY_SIZE; ii++) /* { dg-error "_Cilk_for condition must be one of the following." */ + { + a[ii] = ii; + } +} Index: gcc/testsuite/ChangeLog.cilkplus =================================================================== --- gcc/testsuite/ChangeLog.cilkplus (revision 194496) +++ gcc/testsuite/ChangeLog.cilkplus (working copy) @@ -1,3 +1,10 @@ +2012-12-14 Balaji V. Iyer + + * gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_invalid_compares.c: + New test. + * gcc.dg/cilk-plus/cilk_keywords_test/errors/cilk_for_volatile_var.c: + Likewise. + 2012-12-12 Balaji V. Iyer * gcc.dg/cilk-plus/cilk_keywords_test/errors/goto_inside_cilkfor.c: Index: gcc/ChangeLog.cilkplus =================================================================== --- gcc/ChangeLog.cilkplus (revision 194496) +++ gcc/ChangeLog.cilkplus (working copy) @@ -1,3 +1,11 @@ +2012-12-14 Balaji V. Iyer + + * c/c-parser.c (c_parser_cilk_for_statement): Replaced unknown location with the + correct location value. + * c/c-typeck.c (c_finish_cilk_loop): Checked if the increment is one of + the following: !=, <=, <, >=, or >. Report error otherwise. Also + report error if the induction variable is constant or volatile. + 2012-12-13 Balaji V. Iyer * tree-vect-loop.c (vect_determine_vectorization_factor): Added a