diff -u b/gcc/gimplify.cc b/gcc/gimplify.cc --- b/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -1400,13 +1400,10 @@ "region must specify an % clause", t); /* Skip for omp_default_mem_alloc (= 1), unless align is present. */ - else if (errorcount - || (align == NULL_TREE - && alloc != NULL_TREE - && integer_onep (alloc))) - DECL_ATTRIBUTES (t) = remove_attribute ("omp allocate", - DECL_ATTRIBUTES (t)); - else + else if (!errorcount + && (align != NULL_TREE + || alloc == NULL_TREE + || !integer_onep (alloc))) { /* Fortran might already use a pointer type internally; use that pointer except for type(C_ptr) and type(C_funptr); @@ -1426,10 +1423,10 @@ tmp = build_pointer_type (type); v = create_tmp_var (tmp, get_name (t)); DECL_IGNORED_P (v) = 0; - tmp = remove_attribute ("omp allocate", DECL_ATTRIBUTES (t)); DECL_ATTRIBUTES (v) = tree_cons (get_identifier ("omp allocate var"), - build_tree_list (NULL_TREE, t), tmp); + build_tree_list (NULL_TREE, t), + DECL_ATTRIBUTES (t)); tmp = build_fold_indirect_ref (v); TREE_THIS_NOTRAP (tmp) = 1; SET_DECL_VALUE_EXPR (t, tmp); @@ -1461,6 +1458,11 @@ tmp = fold_build2_loc (loc, MODIFY_EXPR, TREE_TYPE (v), v, fold_convert (TREE_TYPE (v), tmp)); gcc_assert (BIND_EXPR_BODY (bind_expr) != NULL_TREE); + /* Ensure that either TREE_CHAIN (TREE_VALUE (attr) is set + and GOMP_FREE added here or that DECL_HAS_VALUE_EXPR_P (t) + is set, using in a condition much further below. */ + gcc_assert (DECL_HAS_VALUE_EXPR_P (t) + || TREE_CHAIN (TREE_VALUE (attr))); if (TREE_CHAIN (TREE_VALUE (attr))) { /* Fortran is special as it does not have properly nest @@ -1631,14 +1633,15 @@ { tree attr; if (flag_openmp + && DECL_HAS_VALUE_EXPR_P (t) && TREE_USED (t) && ((attr = lookup_attribute ("omp allocate", DECL_ATTRIBUTES (t))) != NULL_TREE) && TREE_CHAIN (TREE_VALUE (attr)) == NULL_TREE) { - /* For Fortran, the GOMP_free has already been added above. */ - tree v = (DECL_HAS_VALUE_EXPR_P (t) - ? TREE_OPERAND (DECL_VALUE_EXPR (t), 0) : t); + /* For Fortran, TREE_CHAIN (TREE_VALUE (attr)) is set, which + causes that the GOMP_free call is already added above. */ + tree v = TREE_OPERAND (DECL_VALUE_EXPR (t), 0); tree tmp = builtin_decl_explicit (BUILT_IN_GOMP_FREE); tmp = build_call_expr_loc (end_locus, tmp, 2, v, build_zero_cst (ptr_type_node));