From patchwork Sat Oct 30 07:06:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 46815 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3239F3857800 for ; Sat, 30 Oct 2021 07:07:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3239F3857800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635577652; bh=LuBiAxdPu03xVK3DJTQMBhvU7F+HrPRxz4nNk9oSU6Q=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=rFoJewmwGR/3bkZzxMWSUEN0gTup7uBXywIy5UDJswQpKPuW/wngqfW7B8XRBrty2 cGZIoSxYQnPRfHGjkI8wWF8O2Gwd3K8FTUzpgJTWZavF0nshkM99tKhEggFtrUFg9U W9byHk8PcTXJzAJA4YZdkfcDwz+UhFWtMCHYqF0I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id CB7F23858407 for ; Sat, 30 Oct 2021 07:07:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB7F23858407 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-335-zqd23QN6NNGYv_o9FhGTxQ-1; Sat, 30 Oct 2021 03:06:57 -0400 X-MC-Unique: zqd23QN6NNGYv_o9FhGTxQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88E25801B01; Sat, 30 Oct 2021 07:06:56 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0153560936; Sat, 30 Oct 2021 07:06:55 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 19U76qjp4147946 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 30 Oct 2021 09:06:53 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 19U76q9G4147945; Sat, 30 Oct 2021 09:06:52 +0200 Date: Sat, 30 Oct 2021 09:06:51 +0200 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Diagnose threadprivate OpenMP loop iterators Message-ID: <20211030070651.GI304296@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: Tobias Burnus Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! We weren't diagnosing the The loop iteration variable may not appear in a threadprivate directive. restriction which used to be in 5.0 just among the Worksharing-Loop restrictions but in 5.1 it is among Canonical Loop Nest Form restrictions. This patch diagnoses those. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2021-10-30 Jakub Jelinek * gimplify.c (gimplify_omp_for): Diagnose threadprivate iterators. * c-c++-common/gomp/loop-10.c: New test. Jakub --- gcc/gimplify.c.jj 2021-10-07 12:52:35.195909331 +0200 +++ gcc/gimplify.c 2021-10-29 19:42:34.343358109 +0200 @@ -12298,6 +12298,24 @@ gimplify_omp_for (tree *expr_p, gimple_s gimplify_omp_ctxp->loop_iter_var.quick_push (decl); } + if (for_stmt == orig_for_stmt) + { + tree orig_decl = decl; + if (OMP_FOR_ORIG_DECLS (for_stmt)) + { + tree orig_decl = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i); + if (TREE_CODE (orig_decl) == TREE_LIST) + { + orig_decl = TREE_PURPOSE (orig_decl); + if (!orig_decl) + orig_decl = decl; + } + } + if (is_global_var (orig_decl) && DECL_THREAD_LOCAL_P (orig_decl)) + error_at (EXPR_LOCATION (for_stmt), + "threadprivate iteration variable %qD", orig_decl); + } + /* Make sure the iteration variable is private. */ tree c = NULL_TREE; tree c2 = NULL_TREE; --- gcc/testsuite/c-c++-common/gomp/loop-10.c.jj 2021-10-29 20:38:28.971214355 +0200 +++ gcc/testsuite/c-c++-common/gomp/loop-10.c 2021-10-29 20:42:40.637710320 +0200 @@ -0,0 +1,35 @@ +int a, b; +#pragma omp threadprivate (a, b) + +void +foo (void) +{ + #pragma omp for /* { dg-error "threadprivate iteration variable 'a'" } */ + for (a = 0; a < 32; a++) + ; + #pragma omp parallel for collapse(2) /* { dg-error "threadprivate iteration variable 'a'" "" { target c } } */ + for (a = 0; a < 32; a++) /* { dg-error "threadprivate iteration variable 'b'" "" { target c } .-1 } */ + for (b = 0; b < 32; b++) /* { dg-error "threadprivate iteration variable 'a'" "" { target c++ } .-1 } */ + ; /* { dg-error "threadprivate iteration variable 'b'" "" { target c++ } .-2 } */ + #pragma omp simd /* { dg-error "threadprivate iteration variable 'a'" } */ + for (a = 0; a < 32; a++) + ; + #pragma omp taskloop /* { dg-error "threadprivate iteration variable 'a'" } */ + for (a = 0; a < 32; a++) + ; + #pragma omp loop bind(thread) /* { dg-error "threadprivate iteration variable 'a'" } */ + for (a = 0; a < 32; a++) + ; +} + +void +bar (void) +{ + #pragma omp distribute collapse(2) /* { dg-error "threadprivate iteration variable 'a'" } */ + for (a = 0; a < 32; a++) /* { dg-error "threadprivate iteration variable 'b'" "" { target *-*-* } .-1 } */ + for (b = 0; b < a; b++) + ; + #pragma omp distribute parallel for simd /* { dg-error "threadprivate iteration variable 'a'" "" { target c } } */ + for (a = 0; a < 32; a++) /* { dg-error "threadprivate iteration variable 'a'" "" { target c++ } } */ + ; +}