From patchwork Thu Sep 7 20:44:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 811168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461694-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="yCXQUA0U"; dkim-atps=neutral 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 3xpCB844P4z9sBW for ; Fri, 8 Sep 2017 06:44:47 +1000 (AEST) 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:reply-to:mime-version:content-type; q=dns; s=default; b=Avd39E5vYBTFjUPZB5iE5CkHl281kBXKDspNg3EfSgY /KZyCdpJkYQPTO41ARS5lVbbUmSM140LtB7f/UOJ9LvxDyheYEF+dWl9Bo9J9oao tXetZ18wUmuTks8esYtjKSyK1QA8iXQrNqjUoenTCJwt95B5slGb3K2u37x2JNaI = 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:reply-to:mime-version:content-type; s=default; bh=1q5KNC8AHXuv1lvmoZOmHB+43I4=; b=yCXQUA0UH0M5bqMbt d6DJszAO422gJjdsPgfVdKNsQQXqQcOJzFgbzwzrktZjGqq4hDh2/DrBa/cJxXIj 8Oc2T64gkFWjeOzl7wm4d5jQOw9M+DqpZyDIm1EnqpZklhSt9mjMVw4yGkzjtA2o i9XJx6FEP4XeiVqJ0rHj2enHzM= Received: (qmail 52486 invoked by alias); 7 Sep 2017 20:44:35 -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 51465 invoked by uid 89); 7 Sep 2017 20:44:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Sep 2017 20:44:28 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BD2C37E88 for ; Thu, 7 Sep 2017 20:44:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3BD2C37E88 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub@redhat.com Received: from tucnak.zalov.cz (ovpn-116-33.ams2.redhat.com [10.36.116.33]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A362760241 for ; Thu, 7 Sep 2017 20:44:26 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v87KiNiR027971 for ; Thu, 7 Sep 2017 22:44:24 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v87KiMqd027970 for gcc-patches@gcc.gnu.org; Thu, 7 Sep 2017 22:44:22 +0200 Date: Thu, 7 Sep 2017 22:44:22 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: Backports to 7.x Message-ID: <20170907204422.GW2323@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! I've bootstrapped/regtested and committed to gcc-7-branch backports of 10 trunk commits. Jakub 2017-09-07 Jakub Jelinek Backported from mainline 2017-07-27 Jakub Jelinek PR c/45784 * c-omp.c (c_finish_omp_for): If the condition is wrapped in rhs of COMPOUND_EXPR(s), skip them and readd their lhs into new COMPOUND_EXPRs around the rhs of the comparison. * testsuite/libgomp.c/pr45784.c: New test. * testsuite/libgomp.c++/pr45784.C: New test. 2017-09-07 Jakub Jelinek Backported from mainline 2017-08-03 Jakub Jelinek PR middle-end/81052 * omp-low.c (diagnose_sb_0): Handle flag_openmp_simd like flag_openmp. (pass_diagnose_omp_blocks::gate): Enable also for flag_openmp_simd. * c-c++-common/pr81052.c: New test. --- gcc/omp-low.c (revision 250846) +++ gcc/omp-low.c (revision 250847) @@ -9083,7 +9083,7 @@ diagnose_sb_0 (gimple_stmt_iterator *gsi } if (kind == NULL) { - gcc_checking_assert (flag_openmp); + gcc_checking_assert (flag_openmp || flag_openmp_simd); kind = "OpenMP"; } @@ -9343,7 +9343,7 @@ public: /* opt_pass methods: */ virtual bool gate (function *) { - return flag_cilkplus || flag_openacc || flag_openmp; + return flag_cilkplus || flag_openacc || flag_openmp || flag_openmp_simd; } virtual unsigned int execute (function *) { --- gcc/testsuite/c-c++-common/pr81052.c (nonexistent) +++ gcc/testsuite/c-c++-common/pr81052.c (revision 250847) @@ -0,0 +1,28 @@ +/* PR middle-end/81052 */ +/* { dg-do compile } */ +/* { dg-options "-fopenmp-simd -O2" } */ + +int +foo (int x, int y) +{ + int i; +#pragma omp simd + for (i = x; i < y; ++i) + return 0; /* { dg-error "invalid branch to/from OpenMP structured block" } */ + return 1; +} + +#ifdef __cplusplus +template +T +bar (T x, T y) +{ + T i; +#pragma omp simd + for (i = x; i < y; ++i) + return 0; /* { dg-error "invalid branch to/from OpenMP structured block" "" { target c++ } } */ + return 1; +} + +int x = bar (1, 7); +#endif 2017-09-07 Jakub Jelinek Backported from mainline 2017-08-03 Jakub Jelinek PR driver/81650 * calls.c (alloc_max_size): Use HOST_WIDE_INT_UC (10??) instead of 10??LU, perform unit multiplication in wide_int, don't change alloc_object_size_limit if the limit is larger than SSIZE_MAX. * gcc.dg/pr81650.c: New test. --- gcc/calls.c (revision 250849) +++ gcc/calls.c (revision 250850) @@ -1222,32 +1222,38 @@ alloc_max_size (void) else if (!strcasecmp (end, "KiB") || strcmp (end, "KB")) unit = 1024; else if (!strcmp (end, "MB")) - unit = 1000LU * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000; else if (!strcasecmp (end, "MiB")) - unit = 1024LU * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024; else if (!strcasecmp (end, "GB")) - unit = 1000LU * 1000 * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000; else if (!strcasecmp (end, "GiB")) - unit = 1024LU * 1024 * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024; else if (!strcasecmp (end, "TB")) - unit = 1000LU * 1000 * 1000 * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000; else if (!strcasecmp (end, "TiB")) - unit = 1024LU * 1024 * 1024 * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024; else if (!strcasecmp (end, "PB")) - unit = 1000LU * 1000 * 1000 * 1000 * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000 * 1000; else if (!strcasecmp (end, "PiB")) - unit = 1024LU * 1024 * 1024 * 1024 * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024 * 1024; else if (!strcasecmp (end, "EB")) - unit = 1000LU * 1000 * 1000 * 1000 * 1000 * 1000; + unit = HOST_WIDE_INT_UC (1000) * 1000 * 1000 * 1000 * 1000 + * 1000; else if (!strcasecmp (end, "EiB")) - unit = 1024LU * 1024 * 1024 * 1024 * 1024 * 1024; + unit = HOST_WIDE_INT_UC (1024) * 1024 * 1024 * 1024 * 1024 + * 1024; else unit = 0; } if (unit) - alloc_object_size_limit - = build_int_cst (ssizetype, limit * unit); + { + wide_int w = wi::uhwi (limit, HOST_BITS_PER_WIDE_INT + 64); + w *= unit; + if (wi::ltu_p (w, alloc_object_size_limit)) + alloc_object_size_limit = wide_int_to_tree (ssizetype, w); + } } } } --- gcc/testsuite/gcc.dg/pr81650.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr81650.c (revision 250850) @@ -0,0 +1,9 @@ +/* PR driver/81650 */ +/* { dg-do compile } */ +/* { dg-options "-Walloc-size-larger-than=9223372036854775807" } */ + +void * +foo (void) +{ + return __builtin_malloc (5); +} 2017-09-07 Jakub Jelinek Backported from mainline 2017-08-03 Jakub Jelinek PR target/81621 * bb-reorder.c (pass_partition_blocks::execute): Return TODO_df_finish after setting changeable df flags. * gcc.dg/pr81621.c: New test. --- gcc/bb-reorder.c (revision 250856) +++ gcc/bb-reorder.c (revision 250857) @@ -2904,7 +2904,8 @@ pass_partition_blocks::execute (function crossing_edges = find_rarely_executed_basic_blocks_and_crossing_edges (); if (!crossing_edges.exists ()) - return 0; + /* Make sure to process deferred rescans and clear changeable df flags. */ + return TODO_df_finish; crtl->has_bb_partition = true; @@ -2970,7 +2971,8 @@ pass_partition_blocks::execute (function df_analyze (); } - return 0; + /* Make sure to process deferred rescans and clear changeable df flags. */ + return TODO_df_finish; } } // anon namespace --- gcc/testsuite/gcc.dg/pr81621.c (nonexistent) +++ gcc/testsuite/gcc.dg/pr81621.c (revision 250857) @@ -0,0 +1,5 @@ +/* PR target/81621 */ +/* { dg-do compile { target freorder } } */ +/* { dg-options "-Og -fno-split-wide-types -freorder-blocks-and-partition" } */ + +#include "graphite/scop-10.c" 2017-09-07 Jakub Jelinek Backported from mainline 2017-08-07 Jakub Jelinek * include/system/sys/ptrace.h: New file. --- libsanitizer/include/system/sys/ptrace.h (nonexistent) +++ libsanitizer/include/system/sys/ptrace.h (revision 250910) @@ -0,0 +1,7 @@ +#include_next +#ifndef PTRACE_GETREGSET +/* glibc before + https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=cbff0d9689c4d68578b6a4f0a17807232506ea27 + doesn't define PTRACE_GETREGSET. */ +#define PTRACE_GETREGSET 0x4204 +#endif 2017-09-07 Jakub Jelinek Backported from mainline 2017-08-09 Jakub Jelinek PR c/81687 * omp-low.c (omp_copy_decl): Don't remap FORCED_LABEL or DECL_NONLOCAL LABEL_DECLs. * tree-cfg.c (move_stmt_op): Don't adjust DECL_CONTEXT of FORCED_LABEL or DECL_NONLOCAL labels. (move_stmt_r) : Adjust DECL_CONTEXT of FORCED_LABEL or DECL_NONLOCAL labels here. * testsuite/libgomp.c/pr81687-1.c: New test. * testsuite/libgomp.c/pr81687-2.c: New test. --- gcc/omp-low.c (revision 251018) +++ gcc/omp-low.c (revision 251019) @@ -798,6 +798,8 @@ omp_copy_decl (tree var, copy_body_data if (TREE_CODE (var) == LABEL_DECL) { + if (FORCED_LABEL (var) || DECL_NONLOCAL (var)) + return var; new_var = create_artificial_label (DECL_SOURCE_LOCATION (var)); DECL_CONTEXT (new_var) = current_function_decl; insert_decl_map (&ctx->cb, var, new_var); --- gcc/tree-cfg.c (revision 251018) +++ gcc/tree-cfg.c (revision 251019) @@ -6718,7 +6718,15 @@ move_stmt_op (tree *tp, int *walk_subtre *tp = t = out->to; } - DECL_CONTEXT (t) = p->to_context; + /* For FORCED_LABELs we can end up with references from other + functions if some SESE regions are outlined. It is UB to + jump in between them, but they could be used just for printing + addresses etc. In that case, DECL_CONTEXT on the label should + be the function containing the glabel stmt with that LABEL_DECL, + rather than whatever function a reference to the label was seen + last time. */ + if (!FORCED_LABEL (t) && !DECL_NONLOCAL (t)) + DECL_CONTEXT (t) = p->to_context; } else if (p->remap_decls_p) { @@ -6836,6 +6844,21 @@ move_stmt_r (gimple_stmt_iterator *gsi_p case GIMPLE_OMP_RETURN: case GIMPLE_OMP_CONTINUE: break; + + case GIMPLE_LABEL: + { + /* For FORCED_LABEL, move_stmt_op doesn't adjust DECL_CONTEXT, + so that such labels can be referenced from other regions. + Make sure to update it when seeing a GIMPLE_LABEL though, + that is the owner of the label. */ + walk_gimple_op (stmt, move_stmt_op, wi); + *handled_ops_p = true; + tree label = gimple_label_label (as_a (stmt)); + if (FORCED_LABEL (label) || DECL_NONLOCAL (label)) + DECL_CONTEXT (label) = p->to_context; + } + break; + default: if (is_gimple_omp (stmt)) { --- libgomp/testsuite/libgomp.c/pr81687-1.c (nonexistent) +++ libgomp/testsuite/libgomp.c/pr81687-1.c (revision 251019) @@ -0,0 +1,23 @@ +/* PR c/81687 */ +/* { dg-do link } */ +/* { dg-additional-options "-O2" } */ + +extern int printf (const char *, ...); + +int +main () +{ + #pragma omp parallel + { + lab1: + printf ("lab1=%p\n", (void *)(&&lab1)); + } + lab2: + #pragma omp parallel + { + lab3: + printf ("lab2=%p\n", (void *)(&&lab2)); + } + printf ("lab3=%p\n", (void *)(&&lab3)); + return 0; +} --- libgomp/testsuite/libgomp.c/pr81687-2.c (nonexistent) +++ libgomp/testsuite/libgomp.c/pr81687-2.c (revision 251019) @@ -0,0 +1,27 @@ +/* PR c/81687 */ +/* { dg-do link } */ +/* { dg-additional-options "-O2" } */ + +int +main () +{ + __label__ lab4, lab5, lab6; + volatile int l = 0; + int m = l; + void foo (int x) { if (x == 1) goto lab4; } + void bar (int x) { if (x == 2) goto lab5; } + void baz (int x) { if (x == 3) goto lab6; } + #pragma omp parallel + { + foo (m + 1); + lab4:; + } + #pragma omp task + { + bar (m + 2); + lab5:; + } + baz (m + 3); + lab6:; + return 0; +} 2017-09-07 Jakub Jelinek Backported from mainline 2017-09-01 Jakub Jelinek PR sanitizer/81923 * asan.c (create_odr_indicator): Strip name encoding from assembler name before appending it after __odr_asan_. * gcc.dg/asan/pr81923.c: New test. --- gcc/asan.c (revision 251594) +++ gcc/asan.c (revision 251595) @@ -2527,9 +2527,12 @@ create_odr_indicator (tree decl, tree ty /* DECL_NAME theoretically might be NULL. Bail out with 0 in this case. */ if (decl_name == NULL_TREE) return build_int_cst (uptr, 0); - size_t len = strlen (IDENTIFIER_POINTER (decl_name)) + sizeof ("__odr_asan_"); + const char *dname = IDENTIFIER_POINTER (decl_name); + if (HAS_DECL_ASSEMBLER_NAME_P (decl)) + dname = targetm.strip_name_encoding (dname); + size_t len = strlen (dname) + sizeof ("__odr_asan_"); name = XALLOCAVEC (char, len); - snprintf (name, len, "__odr_asan_%s", IDENTIFIER_POINTER (decl_name)); + snprintf (name, len, "__odr_asan_%s", dname); #ifndef NO_DOT_IN_LABEL name[sizeof ("__odr_asan") - 1] = '.'; #elif !defined(NO_DOLLAR_IN_LABEL) --- gcc/testsuite/gcc.dg/asan/pr81923.c (nonexistent) +++ gcc/testsuite/gcc.dg/asan/pr81923.c (revision 251595) @@ -0,0 +1,10 @@ +/* PR sanitizer/81923 */ +/* { dg-do link } */ + +int foobar __asm (__USER_LABEL_PREFIX__ "barbaz") = 34; + +int +main () +{ + return 0; +} 2017-09-07 Jakub Jelinek Backported from mainline 2017-09-04 Jakub Jelinek * lra-remat.c (reg_overlap_for_remat_p): Fix a pasto. --- gcc/lra-remat.c (revision 251638) +++ gcc/lra-remat.c (revision 251639) @@ -684,7 +684,7 @@ reg_overlap_for_remat_p (lra_insn_reg *r if (regno2 >= FIRST_PSEUDO_REGISTER && reg_renumber[regno2] >= 0) regno2 = reg_renumber[regno2]; - if (regno >= FIRST_PSEUDO_REGISTER) + if (regno2 >= FIRST_PSEUDO_REGISTER) nregs2 = 1; else nregs2 = hard_regno_nregs[regno2][reg->biggest_mode]; 2017-09-07 Jakub Jelinek Backported from mainline 2017-09-05 Jakub Jelinek PR middle-end/81768 * omp-expand.c (expand_omp_simd): Force second operands of COND_EXPR into gimple val before gimplification fo the COND_EXPR. * gcc.dg/gomp/pr81768-1.c: New test. --- gcc/omp-expand.c (revision 251740) +++ gcc/omp-expand.c (revision 251741) @@ -4730,24 +4730,28 @@ expand_omp_simd (struct omp_region *regi tree itype2 = TREE_TYPE (fd->loops[i - 1].v); if (POINTER_TYPE_P (itype2)) itype2 = signed_type_for (itype2); + t = fold_convert (itype2, fd->loops[i - 1].step); + t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, true, + GSI_SAME_STMT); t = build3 (COND_EXPR, itype2, build2 (fd->loops[i].cond_code, boolean_type_node, fd->loops[i].v, fold_convert (itype, fd->loops[i].n2)), - build_int_cst (itype2, 0), - fold_convert (itype2, fd->loops[i - 1].step)); + build_int_cst (itype2, 0), t); if (POINTER_TYPE_P (TREE_TYPE (fd->loops[i - 1].v))) t = fold_build_pointer_plus (fd->loops[i - 1].v, t); else t = fold_build2 (PLUS_EXPR, itype2, fd->loops[i - 1].v, t); expand_omp_build_assign (&gsi, fd->loops[i - 1].v, t); + t = fold_convert (itype, fd->loops[i].n1); + t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE, true, + GSI_SAME_STMT); t = build3 (COND_EXPR, itype, build2 (fd->loops[i].cond_code, boolean_type_node, fd->loops[i].v, fold_convert (itype, fd->loops[i].n2)), - fd->loops[i].v, - fold_convert (itype, fd->loops[i].n1)); + fd->loops[i].v, t); expand_omp_build_assign (&gsi, fd->loops[i].v, t); } } --- gcc/testsuite/gcc.dg/gomp/pr81768-1.c (nonexistent) +++ gcc/testsuite/gcc.dg/gomp/pr81768-1.c (revision 251741) @@ -0,0 +1,15 @@ +/* PR middle-end/81768 */ +/* { dg-do compile } */ + +float b[10][15][10]; + +void +foo (void) +{ + float *i; +#pragma omp target parallel for simd schedule(static, 32) collapse(3) + for (i = &b[0][0][0]; i < &b[0][0][10]; i++) + for (float *j = &b[0][15][0]; j > &b[0][0][0]; j -= 10) + for (float *k = &b[0][0][10]; k > &b[0][0][0]; --k) + b[i - &b[0][0][0]][(j - &b[0][0][0]) / 10 - 1][(k - &b[0][0][0]) - 1] -= 3.5; +} 2017-09-07 Jakub Jelinek Backported from mainline 2017-09-05 Jakub Jelinek PR middle-end/81768 * omp-low.c (lower_omp_for): Recompute tree invariant if gimple_omp_for_initial/final is ADDR_EXPR. * gcc.dg/gomp/pr81768-2.c: New test. --- gcc/omp-low.c (revision 251741) +++ gcc/omp-low.c (revision 251742) @@ -6923,10 +6923,14 @@ lower_omp_for (gimple_stmt_iterator *gsi rhs_p = gimple_omp_for_initial_ptr (stmt, i); if (!is_gimple_min_invariant (*rhs_p)) *rhs_p = get_formal_tmp_var (*rhs_p, &body); + else if (TREE_CODE (*rhs_p) == ADDR_EXPR) + recompute_tree_invariant_for_addr_expr (*rhs_p); rhs_p = gimple_omp_for_final_ptr (stmt, i); if (!is_gimple_min_invariant (*rhs_p)) *rhs_p = get_formal_tmp_var (*rhs_p, &body); + else if (TREE_CODE (*rhs_p) == ADDR_EXPR) + recompute_tree_invariant_for_addr_expr (*rhs_p); rhs_p = &TREE_OPERAND (gimple_omp_for_incr (stmt, i), 1); if (!is_gimple_min_invariant (*rhs_p)) --- gcc/testsuite/gcc.dg/gomp/pr81768-2.c (nonexistent) +++ gcc/testsuite/gcc.dg/gomp/pr81768-2.c (revision 251742) @@ -0,0 +1,15 @@ +/* PR middle-end/81768 */ +/* { dg-do compile } */ + +float b[10][15][10]; + +void +foo (void) +{ + float *i; +#pragma omp target parallel for schedule(static, 32) collapse(3) + for (i = &b[0][0][0]; i < &b[0][0][10]; i++) + for (float *j = &b[0][15][0]; j > &b[0][0][0]; j -= 10) + for (float *k = &b[0][0][10]; k > &b[0][0][0]; --k) + b[i - &b[0][0][0]][(j - &b[0][0][0]) / 10 - 1][(k - &b[0][0][0]) - 1] -= 3.5; +} --- gcc/c-family/c-omp.c (revision 250634) +++ gcc/c-family/c-omp.c (revision 250635) @@ -531,6 +531,12 @@ c_finish_omp_for (location_t locus, enum { bool cond_ok = false; + /* E.g. C sizeof (vla) could add COMPOUND_EXPRs with + evaluation of the vla VAR_DECL. We need to readd + them to the non-decl operand. See PR45784. */ + while (TREE_CODE (cond) == COMPOUND_EXPR) + cond = TREE_OPERAND (cond, 1); + if (EXPR_HAS_LOCATION (cond)) elocus = EXPR_LOCATION (cond); @@ -605,6 +611,21 @@ c_finish_omp_for (location_t locus, enum else if (code != CILK_SIMD && code != CILK_FOR) cond_ok = false; } + + if (cond_ok && TREE_VEC_ELT (condv, i) != cond) + { + tree ce = NULL_TREE, *pce = &ce; + tree type = TREE_TYPE (TREE_OPERAND (cond, 1)); + for (tree c = TREE_VEC_ELT (condv, i); c != cond; + c = TREE_OPERAND (c, 1)) + { + *pce = build2 (COMPOUND_EXPR, type, TREE_OPERAND (c, 0), + TREE_OPERAND (cond, 1)); + pce = &TREE_OPERAND (*pce, 1); + } + TREE_OPERAND (cond, 1) = ce; + TREE_VEC_ELT (condv, i) = cond; + } } if (!cond_ok) --- libgomp/testsuite/libgomp.c/pr45784.c (nonexistent) +++ libgomp/testsuite/libgomp.c/pr45784.c (revision 250635) @@ -0,0 +1,41 @@ +/* PR c/45784 */ +/* { dg-do run } */ + +void +foo (int n) +{ + char *p, vla[2 * n]; + int i; + #pragma omp parallel for + for (p = vla; p < vla + (sizeof (vla) / sizeof (vla[0])); p++) + *p = ' '; + #pragma omp parallel for + for (i = 0; i < 2 * n; i++) + if (vla[i] != ' ') + __builtin_abort (); +} + +void +bar (int n) +{ + char *p, vla1[n], vla2[n * 2], vla3[n * 3], vla4[n * 4]; + int i; + __builtin_memset (vla4, ' ', n * 4); + #pragma omp parallel for + for (p = vla4 + sizeof (vla1); p < vla4 + sizeof (vla3) - sizeof (vla2) + sizeof (vla1); p += sizeof (vla4) / sizeof (vla4)) + p[0] = '!'; + #pragma omp parallel for + for (i = 0; i < n * 4; i++) + if (vla4[i] != ((i >= n && i < 2 * n) ? '!' : ' ')) + __builtin_abort (); +} + +int +main () +{ + volatile int n; + n = 128; + foo (n); + bar (n); + return 0; +} --- libgomp/testsuite/libgomp.c++/pr45784.C (nonexistent) +++ libgomp/testsuite/libgomp.c++/pr45784.C (revision 250635) @@ -0,0 +1,5 @@ +// PR c/45784 +// { dg-do run } + +#include "../libgomp.c/pr45784.c" +