comparison gcc/fortran/expr.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Routines for manipulation of expression nodes. 1 /* Routines for manipulation of expression nodes.
2 Copyright (C) 2000-2017 Free Software Foundation, Inc. 2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
3 Contributed by Andy Vaught 3 Contributed by Andy Vaught
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
25 #include "gfortran.h" 25 #include "gfortran.h"
26 #include "arith.h" 26 #include "arith.h"
27 #include "match.h" 27 #include "match.h"
28 #include "target-memory.h" /* for gfc_convert_boz */ 28 #include "target-memory.h" /* for gfc_convert_boz */
29 #include "constructor.h" 29 #include "constructor.h"
30 #include "tree.h"
30 31
31 32
32 /* The following set of functions provide access to gfc_expr* of 33 /* The following set of functions provide access to gfc_expr* of
33 various types - actual all but EXPR_FUNCTION and EXPR_VARIABLE. 34 various types - actual all but EXPR_FUNCTION and EXPR_VARIABLE.
34 35
182 /* Get a new expression node that is an string constant. 183 /* Get a new expression node that is an string constant.
183 If no string is passed, a string of len is allocated, 184 If no string is passed, a string of len is allocated,
184 blanked and null-terminated. */ 185 blanked and null-terminated. */
185 186
186 gfc_expr * 187 gfc_expr *
187 gfc_get_character_expr (int kind, locus *where, const char *src, int len) 188 gfc_get_character_expr (int kind, locus *where, const char *src, gfc_charlen_t len)
188 { 189 {
189 gfc_expr *e; 190 gfc_expr *e;
190 gfc_char_t *dest; 191 gfc_char_t *dest;
191 192
192 if (!src) 193 if (!src)
208 209
209 210
210 /* Get a new expression node that is an integer constant. */ 211 /* Get a new expression node that is an integer constant. */
211 212
212 gfc_expr * 213 gfc_expr *
213 gfc_get_int_expr (int kind, locus *where, int value) 214 gfc_get_int_expr (int kind, locus *where, HOST_WIDE_INT value)
214 { 215 {
215 gfc_expr *p; 216 gfc_expr *p;
216 p = gfc_get_constant_expr (BT_INTEGER, kind, 217 p = gfc_get_constant_expr (BT_INTEGER, kind,
217 where ? where : &gfc_current_locus); 218 where ? where : &gfc_current_locus);
218 219
219 mpz_set_si (p->value.integer, value); 220 const wide_int w = wi::shwi (value, kind * BITS_PER_UNIT);
221 wi::to_mpz (w, p->value.integer, SIGNED);
220 222
221 return p; 223 return p;
222 } 224 }
223 225
224 226
670 672
671 return false; 673 return false;
672 } 674 }
673 675
674 676
677 /* Same as gfc_extract_int, but use a HWI. */
678
679 bool
680 gfc_extract_hwi (gfc_expr *expr, HOST_WIDE_INT *result, int report_error)
681 {
682 gfc_ref *ref;
683
684 /* A KIND component is a parameter too. The expression for it is
685 stored in the initializer and should be consistent with the tests
686 below. */
687 if (gfc_expr_attr(expr).pdt_kind)
688 {
689 for (ref = expr->ref; ref; ref = ref->next)
690 {
691 if (ref->u.c.component->attr.pdt_kind)
692 expr = ref->u.c.component->initializer;
693 }
694 }
695
696 if (expr->expr_type != EXPR_CONSTANT)
697 {
698 if (report_error > 0)
699 gfc_error ("Constant expression required at %C");
700 else if (report_error < 0)
701 gfc_error_now ("Constant expression required at %C");
702 return true;
703 }
704
705 if (expr->ts.type != BT_INTEGER)
706 {
707 if (report_error > 0)
708 gfc_error ("Integer expression required at %C");
709 else if (report_error < 0)
710 gfc_error_now ("Integer expression required at %C");
711 return true;
712 }
713
714 /* Use long_long_integer_type_node to determine when to saturate. */
715 const wide_int val = wi::from_mpz (long_long_integer_type_node,
716 expr->value.integer, false);
717
718 if (!wi::fits_shwi_p (val))
719 {
720 if (report_error > 0)
721 gfc_error ("Integer value too large in expression at %C");
722 else if (report_error < 0)
723 gfc_error_now ("Integer value too large in expression at %C");
724 return true;
725 }
726
727 *result = val.to_shwi ();
728
729 return false;
730 }
731
732
675 /* Recursively copy a list of reference structures. */ 733 /* Recursively copy a list of reference structures. */
676 734
677 gfc_ref * 735 gfc_ref *
678 gfc_copy_ref (gfc_ref *src) 736 gfc_copy_ref (gfc_ref *src)
679 { 737 {
1009 if (e->symtree->n.sym->attr.subref_array_pointer) 1067 if (e->symtree->n.sym->attr.subref_array_pointer)
1010 return true; 1068 return true;
1011 1069
1012 if (e->symtree->n.sym->ts.type == BT_CLASS 1070 if (e->symtree->n.sym->ts.type == BT_CLASS
1013 && e->symtree->n.sym->attr.dummy 1071 && e->symtree->n.sym->attr.dummy
1072 && CLASS_DATA (e->symtree->n.sym)->attr.dimension
1014 && CLASS_DATA (e->symtree->n.sym)->attr.class_pointer) 1073 && CLASS_DATA (e->symtree->n.sym)->attr.class_pointer)
1015 return true; 1074 return true;
1016 1075
1017 seen_array = false; 1076 seen_array = false;
1018 for (ref = e->ref; ref; ref = ref->next) 1077 for (ref = e->ref; ref; ref = ref->next)
1602 /* Pull a substring out of an expression. */ 1661 /* Pull a substring out of an expression. */
1603 1662
1604 static bool 1663 static bool
1605 find_substring_ref (gfc_expr *p, gfc_expr **newp) 1664 find_substring_ref (gfc_expr *p, gfc_expr **newp)
1606 { 1665 {
1607 int end; 1666 gfc_charlen_t end;
1608 int start; 1667 gfc_charlen_t start;
1609 int length; 1668 gfc_charlen_t length;
1610 gfc_char_t *chr; 1669 gfc_char_t *chr;
1611 1670
1612 if (p->ref->u.ss.start->expr_type != EXPR_CONSTANT 1671 if (p->ref->u.ss.start->expr_type != EXPR_CONSTANT
1613 || p->ref->u.ss.end->expr_type != EXPR_CONSTANT) 1672 || p->ref->u.ss.end->expr_type != EXPR_CONSTANT)
1614 return false; 1673 return false;
1615 1674
1616 *newp = gfc_copy_expr (p); 1675 *newp = gfc_copy_expr (p);
1617 free ((*newp)->value.character.string); 1676 free ((*newp)->value.character.string);
1618 1677
1619 end = (int) mpz_get_ui (p->ref->u.ss.end->value.integer); 1678 end = (gfc_charlen_t) mpz_get_ui (p->ref->u.ss.end->value.integer);
1620 start = (int) mpz_get_ui (p->ref->u.ss.start->value.integer); 1679 start = (gfc_charlen_t) mpz_get_ui (p->ref->u.ss.start->value.integer);
1621 length = end - start + 1; 1680 if (end >= start)
1681 length = end - start + 1;
1682 else
1683 length = 0;
1622 1684
1623 chr = (*newp)->value.character.string = gfc_get_wide_string (length + 1); 1685 chr = (*newp)->value.character.string = gfc_get_wide_string (length + 1);
1624 (*newp)->value.character.length = length; 1686 (*newp)->value.character.length = length;
1625 memcpy (chr, &p->value.character.string[start - 1], 1687 memcpy (chr, &p->value.character.string[start - 1],
1626 length * sizeof (gfc_char_t)); 1688 length * sizeof (gfc_char_t));
1699 { 1761 {
1700 /* If this is a CHARACTER array and we possibly took 1762 /* If this is a CHARACTER array and we possibly took
1701 a substring out of it, update the type-spec's 1763 a substring out of it, update the type-spec's
1702 character length according to the first element 1764 character length according to the first element
1703 (as all should have the same length). */ 1765 (as all should have the same length). */
1704 int string_len; 1766 gfc_charlen_t string_len;
1705 if ((c = gfc_constructor_first (p->value.constructor))) 1767 if ((c = gfc_constructor_first (p->value.constructor)))
1706 { 1768 {
1707 const gfc_expr* first = c->expr; 1769 const gfc_expr* first = c->expr;
1708 gcc_assert (first->expr_type == EXPR_CONSTANT); 1770 gcc_assert (first->expr_type == EXPR_CONSTANT);
1709 gcc_assert (first->ts.type == BT_CHARACTER); 1771 gcc_assert (first->ts.type == BT_CHARACTER);
1717 NULL); 1779 NULL);
1718 else 1780 else
1719 gfc_free_expr (p->ts.u.cl->length); 1781 gfc_free_expr (p->ts.u.cl->length);
1720 1782
1721 p->ts.u.cl->length 1783 p->ts.u.cl->length
1722 = gfc_get_int_expr (gfc_default_integer_kind, 1784 = gfc_get_int_expr (gfc_charlen_int_kind,
1723 NULL, string_len); 1785 NULL, string_len);
1724 } 1786 }
1725 } 1787 }
1726 gfc_free_ref_list (p->ref); 1788 gfc_free_ref_list (p->ref);
1727 p->ref = NULL; 1789 p->ref = NULL;
1797 simplify_parameter_variable (gfc_expr *p, int type) 1859 simplify_parameter_variable (gfc_expr *p, int type)
1798 { 1860 {
1799 gfc_expr *e; 1861 gfc_expr *e;
1800 bool t; 1862 bool t;
1801 1863
1864 if (gfc_is_size_zero_array (p))
1865 {
1866 if (p->expr_type == EXPR_ARRAY)
1867 return true;
1868
1869 e = gfc_get_expr ();
1870 e->expr_type = EXPR_ARRAY;
1871 e->ts = p->ts;
1872 e->rank = p->rank;
1873 e->value.constructor = NULL;
1874 e->shape = gfc_copy_shape (p->shape, p->rank);
1875 e->where = p->where;
1876 gfc_replace_expr (p, e);
1877 return true;
1878 }
1879
1802 e = gfc_copy_expr (p->symtree->n.sym->value); 1880 e = gfc_copy_expr (p->symtree->n.sym->value);
1803 if (e == NULL) 1881 if (e == NULL)
1804 return false; 1882 return false;
1805 1883
1806 e->rank = p->rank; 1884 e->rank = p->rank;
1816 else 1894 else
1817 gfc_free_expr (e); 1895 gfc_free_expr (e);
1818 1896
1819 return t; 1897 return t;
1820 } 1898 }
1899
1900
1901 static bool
1902 scalarize_intrinsic_call (gfc_expr *, bool init_flag);
1821 1903
1822 /* Given an expression, simplify it by collapsing constant 1904 /* Given an expression, simplify it by collapsing constant
1823 expressions. Most simplification takes place when the expression 1905 expressions. Most simplification takes place when the expression
1824 tree is being constructed. If an intrinsic function is simplified 1906 tree is being constructed. If an intrinsic function is simplified
1825 at some point, we get called again to collapse the result against 1907 at some point, we get called again to collapse the result against
1840 1922
1841 bool 1923 bool
1842 gfc_simplify_expr (gfc_expr *p, int type) 1924 gfc_simplify_expr (gfc_expr *p, int type)
1843 { 1925 {
1844 gfc_actual_arglist *ap; 1926 gfc_actual_arglist *ap;
1927 gfc_intrinsic_sym* isym = NULL;
1928
1845 1929
1846 if (p == NULL) 1930 if (p == NULL)
1847 return true; 1931 return true;
1848 1932
1849 switch (p->expr_type) 1933 switch (p->expr_type)
1851 case EXPR_CONSTANT: 1935 case EXPR_CONSTANT:
1852 case EXPR_NULL: 1936 case EXPR_NULL:
1853 break; 1937 break;
1854 1938
1855 case EXPR_FUNCTION: 1939 case EXPR_FUNCTION:
1856 for (ap = p->value.function.actual; ap; ap = ap->next) 1940 // For array-bound functions, we don't need to optimize
1941 // the 'array' argument. In particular, if the argument
1942 // is a PARAMETER, simplifying might convert an EXPR_VARIABLE
1943 // into an EXPR_ARRAY; the latter has lbound = 1, the former
1944 // can have any lbound.
1945 ap = p->value.function.actual;
1946 if (p->value.function.isym &&
1947 (p->value.function.isym->id == GFC_ISYM_LBOUND
1948 || p->value.function.isym->id == GFC_ISYM_UBOUND
1949 || p->value.function.isym->id == GFC_ISYM_LCOBOUND
1950 || p->value.function.isym->id == GFC_ISYM_UCOBOUND))
1951 ap = ap->next;
1952
1953 for ( ; ap; ap = ap->next)
1857 if (!gfc_simplify_expr (ap->expr, type)) 1954 if (!gfc_simplify_expr (ap->expr, type))
1858 return false; 1955 return false;
1859 1956
1860 if (p->value.function.isym != NULL 1957 if (p->value.function.isym != NULL
1861 && gfc_intrinsic_func_interface (p, 1) == MATCH_ERROR) 1958 && gfc_intrinsic_func_interface (p, 1) == MATCH_ERROR)
1862 return false; 1959 return false;
1863 1960
1961 if (p->expr_type == EXPR_FUNCTION)
1962 {
1963 if (p->symtree)
1964 isym = gfc_find_function (p->symtree->n.sym->name);
1965 if (isym && isym->elemental)
1966 scalarize_intrinsic_call (p, false);
1967 }
1968
1864 break; 1969 break;
1865 1970
1866 case EXPR_SUBSTRING: 1971 case EXPR_SUBSTRING:
1867 if (!simplify_ref_chain (p->ref, type)) 1972 if (!simplify_ref_chain (p->ref, type))
1868 return false; 1973 return false;
1869 1974
1870 if (gfc_is_constant_expr (p)) 1975 if (gfc_is_constant_expr (p))
1871 { 1976 {
1872 gfc_char_t *s; 1977 gfc_char_t *s;
1873 int start, end; 1978 HOST_WIDE_INT start, end;
1874 1979
1875 start = 0; 1980 start = 0;
1876 if (p->ref && p->ref->u.ss.start) 1981 if (p->ref && p->ref->u.ss.start)
1877 { 1982 {
1878 gfc_extract_int (p->ref->u.ss.start, &start); 1983 gfc_extract_hwi (p->ref->u.ss.start, &start);
1879 start--; /* Convert from one-based to zero-based. */ 1984 start--; /* Convert from one-based to zero-based. */
1880 } 1985 }
1881 1986
1882 end = p->value.character.length; 1987 end = p->value.character.length;
1883 if (p->ref && p->ref->u.ss.end) 1988 if (p->ref && p->ref->u.ss.end)
1884 gfc_extract_int (p->ref->u.ss.end, &end); 1989 gfc_extract_hwi (p->ref->u.ss.end, &end);
1885 1990
1886 if (end < start) 1991 if (end < start)
1887 end = start; 1992 end = start;
1888 1993
1889 s = gfc_get_wide_string (end - start + 2); 1994 s = gfc_get_wide_string (end - start + 2);
1892 s[end - start + 1] = '\0'; /* TODO: C-style string. */ 1997 s[end - start + 1] = '\0'; /* TODO: C-style string. */
1893 free (p->value.character.string); 1998 free (p->value.character.string);
1894 p->value.character.string = s; 1999 p->value.character.string = s;
1895 p->value.character.length = end - start; 2000 p->value.character.length = end - start;
1896 p->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL); 2001 p->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
1897 p->ts.u.cl->length = gfc_get_int_expr (gfc_default_integer_kind, 2002 p->ts.u.cl->length = gfc_get_int_expr (gfc_charlen_int_kind,
1898 NULL, 2003 NULL,
1899 p->value.character.length); 2004 p->value.character.length);
1900 gfc_free_ref_list (p->ref); 2005 gfc_free_ref_list (p->ref);
1901 p->ref = NULL; 2006 p->ref = NULL;
1902 p->expr_type = EXPR_CONSTANT; 2007 p->expr_type = EXPR_CONSTANT;
1972 2077
1973 2078
1974 /* Scalarize an expression for an elemental intrinsic call. */ 2079 /* Scalarize an expression for an elemental intrinsic call. */
1975 2080
1976 static bool 2081 static bool
1977 scalarize_intrinsic_call (gfc_expr *e) 2082 scalarize_intrinsic_call (gfc_expr *e, bool init_flag)
1978 { 2083 {
1979 gfc_actual_arglist *a, *b; 2084 gfc_actual_arglist *a, *b;
1980 gfc_constructor_base ctor; 2085 gfc_constructor_base ctor;
1981 gfc_constructor *args[5] = {}; /* Avoid uninitialized warnings. */ 2086 gfc_constructor *args[5] = {}; /* Avoid uninitialized warnings. */
1982 gfc_constructor *ci, *new_ctor; 2087 gfc_constructor *ci, *new_ctor;
1983 gfc_expr *expr, *old; 2088 gfc_expr *expr, *old;
1984 int n, i, rank[5], array_arg; 2089 int n, i, rank[5], array_arg;
2090 int errors = 0;
2091
2092 if (e == NULL)
2093 return false;
2094
2095 a = e->value.function.actual;
2096 for (; a; a = a->next)
2097 if (a->expr && !gfc_is_constant_expr (a->expr))
2098 return false;
1985 2099
1986 /* Find which, if any, arguments are arrays. Assume that the old 2100 /* Find which, if any, arguments are arrays. Assume that the old
1987 expression carries the type information and that the first arg 2101 expression carries the type information and that the first arg
1988 that is an array expression carries all the shape information.*/ 2102 that is an array expression carries all the shape information.*/
1989 n = array_arg = 0; 2103 n = array_arg = 0;
2014 n = 0; 2128 n = 0;
2015 a = old->value.function.actual; 2129 a = old->value.function.actual;
2016 for (; a; a = a->next) 2130 for (; a; a = a->next)
2017 { 2131 {
2018 /* Check that this is OK for an initialization expression. */ 2132 /* Check that this is OK for an initialization expression. */
2019 if (a->expr && !gfc_check_init_expr (a->expr)) 2133 if (a->expr && init_flag && !gfc_check_init_expr (a->expr))
2020 goto cleanup; 2134 goto cleanup;
2021 2135
2022 rank[n] = 0; 2136 rank[n] = 0;
2023 if (a->expr && a->expr->rank && a->expr->expr_type == EXPR_VARIABLE) 2137 if (a->expr && a->expr->rank && a->expr->expr_type == EXPR_VARIABLE)
2024 { 2138 {
2039 args[n] = NULL; 2153 args[n] = NULL;
2040 2154
2041 n++; 2155 n++;
2042 } 2156 }
2043 2157
2158 gfc_get_errors (NULL, &errors);
2044 2159
2045 /* Using the array argument as the master, step through the array 2160 /* Using the array argument as the master, step through the array
2046 calling the function for each element and advancing the array 2161 calling the function for each element and advancing the array
2047 constructors together. */ 2162 constructors together. */
2048 for (ci = args[array_arg - 1]; ci; ci = gfc_constructor_next (ci)) 2163 for (ci = args[array_arg - 1]; ci; ci = gfc_constructor_next (ci))
2073 } 2188 }
2074 2189
2075 /* Simplify the function calls. If the simplification fails, the 2190 /* Simplify the function calls. If the simplification fails, the
2076 error will be flagged up down-stream or the library will deal 2191 error will be flagged up down-stream or the library will deal
2077 with it. */ 2192 with it. */
2078 gfc_simplify_expr (new_ctor->expr, 0); 2193 if (errors == 0)
2194 gfc_simplify_expr (new_ctor->expr, 0);
2079 2195
2080 for (i = 0; i < n; i++) 2196 for (i = 0; i < n; i++)
2081 if (args[i]) 2197 if (args[i])
2082 args[i] = gfc_constructor_next (args[i]); 2198 args[i] = gfc_constructor_next (args[i]);
2083 2199
2343 ap->expr->ts = ap->expr->symtree->n.sym->ts; 2459 ap->expr->ts = ap->expr->symtree->n.sym->ts;
2344 } 2460 }
2345 2461
2346 /* Assumed character length will not reduce to a constant expression 2462 /* Assumed character length will not reduce to a constant expression
2347 with LEN, as required by the standard. */ 2463 with LEN, as required by the standard. */
2348 if (i == 5 && not_restricted 2464 if (i == 5 && not_restricted && ap->expr->symtree
2349 && ap->expr->symtree->n.sym->ts.type == BT_CHARACTER 2465 && ap->expr->symtree->n.sym->ts.type == BT_CHARACTER
2350 && (ap->expr->symtree->n.sym->ts.u.cl->length == NULL 2466 && (ap->expr->symtree->n.sym->ts.u.cl->length == NULL
2351 || ap->expr->symtree->n.sym->ts.deferred)) 2467 || ap->expr->symtree->n.sym->ts.deferred))
2352 { 2468 {
2353 gfc_error ("Assumed or deferred character length variable %qs " 2469 gfc_error ("Assumed or deferred character length variable %qs "
2547 2663
2548 /* Try to scalarize an elemental intrinsic function that has an 2664 /* Try to scalarize an elemental intrinsic function that has an
2549 array argument. */ 2665 array argument. */
2550 isym = gfc_find_function (e->symtree->n.sym->name); 2666 isym = gfc_find_function (e->symtree->n.sym->name);
2551 if (isym && isym->elemental 2667 if (isym && isym->elemental
2552 && (t = scalarize_intrinsic_call (e))) 2668 && (t = scalarize_intrinsic_call (e, true)))
2553 break; 2669 break;
2554 } 2670 }
2555 2671
2556 if (m == MATCH_YES) 2672 if (m == MATCH_YES)
2557 t = gfc_simplify_expr (e, 0); 2673 t = gfc_simplify_expr (e, 0);
3335 return true; 3451 return true;
3336 3452
3337 /* Only DATA Statements come here. */ 3453 /* Only DATA Statements come here. */
3338 if (!conform) 3454 if (!conform)
3339 { 3455 {
3456 locus *where;
3457
3340 /* Numeric can be converted to any other numeric. And Hollerith can be 3458 /* Numeric can be converted to any other numeric. And Hollerith can be
3341 converted to any other type. */ 3459 converted to any other type. */
3342 if ((gfc_numeric_ts (&lvalue->ts) && gfc_numeric_ts (&rvalue->ts)) 3460 if ((gfc_numeric_ts (&lvalue->ts) && gfc_numeric_ts (&rvalue->ts))
3343 || rvalue->ts.type == BT_HOLLERITH) 3461 || rvalue->ts.type == BT_HOLLERITH)
3344 return true; 3462 return true;
3345 3463
3346 if (lvalue->ts.type == BT_LOGICAL && rvalue->ts.type == BT_LOGICAL) 3464 if (lvalue->ts.type == BT_LOGICAL && rvalue->ts.type == BT_LOGICAL)
3347 return true; 3465 return true;
3348 3466
3467 where = lvalue->where.lb ? &lvalue->where : &rvalue->where;
3349 gfc_error ("Incompatible types in DATA statement at %L; attempted " 3468 gfc_error ("Incompatible types in DATA statement at %L; attempted "
3350 "conversion of %s to %s", &lvalue->where, 3469 "conversion of %s to %s", where,
3351 gfc_typename (&rvalue->ts), gfc_typename (&lvalue->ts)); 3470 gfc_typename (&rvalue->ts), gfc_typename (&lvalue->ts));
3352 3471
3353 return false; 3472 return false;
3354 } 3473 }
3355 3474
3849 &rvalue->where); 3968 &rvalue->where);
3850 return false; 3969 return false;
3851 } 3970 }
3852 } 3971 }
3853 3972
3854 /* Error for assignments of contiguous pointers to targets which is not 3973 /* Warn for assignments of contiguous pointers to targets which is not
3855 contiguous. Be lenient in the definition of what counts as 3974 contiguous. Be lenient in the definition of what counts as
3856 congiguous. */ 3975 contiguous. */
3857 3976
3858 if (lhs_attr.contiguous && !gfc_is_simply_contiguous (rvalue, false, true)) 3977 if (lhs_attr.contiguous && !gfc_is_simply_contiguous (rvalue, false, true))
3859 gfc_error ("Assignment to contiguous pointer from non-contiguous " 3978 gfc_warning (OPT_Wextra, "Assignment to contiguous pointer from "
3860 "target at %L", &rvalue->where); 3979 "non-contiguous target at %L", &rvalue->where);
3861 3980
3862 /* Warn if it is the LHS pointer may lives longer than the RHS target. */ 3981 /* Warn if it is the LHS pointer may lives longer than the RHS target. */
3863 if (warn_target_lifetime 3982 if (warn_target_lifetime
3864 && rvalue->expr_type == EXPR_VARIABLE 3983 && rvalue->expr_type == EXPR_VARIABLE
3865 && !rvalue->symtree->n.sym->attr.save 3984 && !rvalue->symtree->n.sym->attr.save
4011 } 4130 }
4012 4131
4013 return true; 4132 return true;
4014 } 4133 }
4015 4134
4135 /* Invoke gfc_build_init_expr to create an initializer expression, but do not
4136 * require that an expression be built. */
4137
4138 gfc_expr *
4139 gfc_build_default_init_expr (gfc_typespec *ts, locus *where)
4140 {
4141 return gfc_build_init_expr (ts, where, false);
4142 }
4016 4143
4017 /* Build an initializer for a local integer, real, complex, logical, or 4144 /* Build an initializer for a local integer, real, complex, logical, or
4018 character variable, based on the command line flags finit-local-zero, 4145 character variable, based on the command line flags finit-local-zero,
4019 finit-integer=, finit-real=, finit-logical=, and finit-character=. */ 4146 finit-integer=, finit-real=, finit-logical=, and finit-character=.
4147 With force, an initializer is ALWAYS generated. */
4020 4148
4021 gfc_expr * 4149 gfc_expr *
4022 gfc_build_default_init_expr (gfc_typespec *ts, locus *where) 4150 gfc_build_init_expr (gfc_typespec *ts, locus *where, bool force)
4023 { 4151 {
4024 int char_len;
4025 gfc_expr *init_expr; 4152 gfc_expr *init_expr;
4026 int i;
4027 4153
4028 /* Try to build an initializer expression. */ 4154 /* Try to build an initializer expression. */
4029 init_expr = gfc_get_constant_expr (ts->type, ts->kind, where); 4155 init_expr = gfc_get_constant_expr (ts->type, ts->kind, where);
4156
4157 /* If we want to force generation, make sure we default to zero. */
4158 gfc_init_local_real init_real = flag_init_real;
4159 int init_logical = gfc_option.flag_init_logical;
4160 if (force)
4161 {
4162 if (init_real == GFC_INIT_REAL_OFF)
4163 init_real = GFC_INIT_REAL_ZERO;
4164 if (init_logical == GFC_INIT_LOGICAL_OFF)
4165 init_logical = GFC_INIT_LOGICAL_FALSE;
4166 }
4030 4167
4031 /* We will only initialize integers, reals, complex, logicals, and 4168 /* We will only initialize integers, reals, complex, logicals, and
4032 characters, and only if the corresponding command-line flags 4169 characters, and only if the corresponding command-line flags
4033 were set. Otherwise, we free init_expr and return null. */ 4170 were set. Otherwise, we free init_expr and return null. */
4034 switch (ts->type) 4171 switch (ts->type)
4035 { 4172 {
4036 case BT_INTEGER: 4173 case BT_INTEGER:
4037 if (gfc_option.flag_init_integer != GFC_INIT_INTEGER_OFF) 4174 if (force || gfc_option.flag_init_integer != GFC_INIT_INTEGER_OFF)
4038 mpz_set_si (init_expr->value.integer, 4175 mpz_set_si (init_expr->value.integer,
4039 gfc_option.flag_init_integer_value); 4176 gfc_option.flag_init_integer_value);
4040 else 4177 else
4041 { 4178 {
4042 gfc_free_expr (init_expr); 4179 gfc_free_expr (init_expr);
4043 init_expr = NULL; 4180 init_expr = NULL;
4044 } 4181 }
4045 break; 4182 break;
4046 4183
4047 case BT_REAL: 4184 case BT_REAL:
4048 switch (flag_init_real) 4185 switch (init_real)
4049 { 4186 {
4050 case GFC_INIT_REAL_SNAN: 4187 case GFC_INIT_REAL_SNAN:
4051 init_expr->is_snan = 1; 4188 init_expr->is_snan = 1;
4052 /* Fall through. */ 4189 /* Fall through. */
4053 case GFC_INIT_REAL_NAN: 4190 case GFC_INIT_REAL_NAN:
4072 break; 4209 break;
4073 } 4210 }
4074 break; 4211 break;
4075 4212
4076 case BT_COMPLEX: 4213 case BT_COMPLEX:
4077 switch (flag_init_real) 4214 switch (init_real)
4078 { 4215 {
4079 case GFC_INIT_REAL_SNAN: 4216 case GFC_INIT_REAL_SNAN:
4080 init_expr->is_snan = 1; 4217 init_expr->is_snan = 1;
4081 /* Fall through. */ 4218 /* Fall through. */
4082 case GFC_INIT_REAL_NAN: 4219 case GFC_INIT_REAL_NAN:
4104 break; 4241 break;
4105 } 4242 }
4106 break; 4243 break;
4107 4244
4108 case BT_LOGICAL: 4245 case BT_LOGICAL:
4109 if (gfc_option.flag_init_logical == GFC_INIT_LOGICAL_FALSE) 4246 if (init_logical == GFC_INIT_LOGICAL_FALSE)
4110 init_expr->value.logical = 0; 4247 init_expr->value.logical = 0;
4111 else if (gfc_option.flag_init_logical == GFC_INIT_LOGICAL_TRUE) 4248 else if (init_logical == GFC_INIT_LOGICAL_TRUE)
4112 init_expr->value.logical = 1; 4249 init_expr->value.logical = 1;
4113 else 4250 else
4114 { 4251 {
4115 gfc_free_expr (init_expr); 4252 gfc_free_expr (init_expr);
4116 init_expr = NULL; 4253 init_expr = NULL;
4118 break; 4255 break;
4119 4256
4120 case BT_CHARACTER: 4257 case BT_CHARACTER:
4121 /* For characters, the length must be constant in order to 4258 /* For characters, the length must be constant in order to
4122 create a default initializer. */ 4259 create a default initializer. */
4123 if (gfc_option.flag_init_character == GFC_INIT_CHARACTER_ON 4260 if ((force || gfc_option.flag_init_character == GFC_INIT_CHARACTER_ON)
4124 && ts->u.cl->length 4261 && ts->u.cl->length
4125 && ts->u.cl->length->expr_type == EXPR_CONSTANT) 4262 && ts->u.cl->length->expr_type == EXPR_CONSTANT)
4126 { 4263 {
4127 char_len = mpz_get_si (ts->u.cl->length->value.integer); 4264 HOST_WIDE_INT char_len = gfc_mpz_get_hwi (ts->u.cl->length->value.integer);
4128 init_expr->value.character.length = char_len; 4265 init_expr->value.character.length = char_len;
4129 init_expr->value.character.string = gfc_get_wide_string (char_len+1); 4266 init_expr->value.character.string = gfc_get_wide_string (char_len+1);
4130 for (i = 0; i < char_len; i++) 4267 for (size_t i = 0; i < (size_t) char_len; i++)
4131 init_expr->value.character.string[i] 4268 init_expr->value.character.string[i]
4132 = (unsigned char) gfc_option.flag_init_character_value; 4269 = (unsigned char) gfc_option.flag_init_character_value;
4133 } 4270 }
4134 else 4271 else
4135 { 4272 {
4136 gfc_free_expr (init_expr); 4273 gfc_free_expr (init_expr);
4137 init_expr = NULL; 4274 init_expr = NULL;
4138 } 4275 }
4139 if (!init_expr && gfc_option.flag_init_character == GFC_INIT_CHARACTER_ON 4276 if (!init_expr
4277 && (force || gfc_option.flag_init_character == GFC_INIT_CHARACTER_ON)
4140 && ts->u.cl->length && flag_max_stack_var_size != 0) 4278 && ts->u.cl->length && flag_max_stack_var_size != 0)
4141 { 4279 {
4142 gfc_actual_arglist *arg; 4280 gfc_actual_arglist *arg;
4143 init_expr = gfc_get_expr (); 4281 init_expr = gfc_get_expr ();
4144 init_expr->where = *where; 4282 init_expr->where = *where;
4174 { 4312 {
4175 if (ts->type == BT_CHARACTER && !attr->pointer && init 4313 if (ts->type == BT_CHARACTER && !attr->pointer && init
4176 && ts->u.cl 4314 && ts->u.cl
4177 && ts->u.cl->length && ts->u.cl->length->expr_type == EXPR_CONSTANT) 4315 && ts->u.cl->length && ts->u.cl->length->expr_type == EXPR_CONSTANT)
4178 { 4316 {
4179 int len;
4180
4181 gcc_assert (ts->u.cl && ts->u.cl->length); 4317 gcc_assert (ts->u.cl && ts->u.cl->length);
4182 gcc_assert (ts->u.cl->length->expr_type == EXPR_CONSTANT); 4318 gcc_assert (ts->u.cl->length->expr_type == EXPR_CONSTANT);
4183 gcc_assert (ts->u.cl->length->ts.type == BT_INTEGER); 4319 gcc_assert (ts->u.cl->length->ts.type == BT_INTEGER);
4184 4320
4185 len = mpz_get_si (ts->u.cl->length->value.integer); 4321 HOST_WIDE_INT len = gfc_mpz_get_hwi (ts->u.cl->length->value.integer);
4186 4322
4187 if (init->expr_type == EXPR_CONSTANT) 4323 if (init->expr_type == EXPR_CONSTANT)
4188 gfc_set_constant_character_len (len, init, -1); 4324 gfc_set_constant_character_len (len, init, -1);
4189 else if (init 4325 else if (init
4190 && init->ts.u.cl 4326 && init->ts.type == BT_CHARACTER
4327 && init->ts.u.cl && init->ts.u.cl->length
4191 && mpz_cmp (ts->u.cl->length->value.integer, 4328 && mpz_cmp (ts->u.cl->length->value.integer,
4192 init->ts.u.cl->length->value.integer)) 4329 init->ts.u.cl->length->value.integer))
4193 { 4330 {
4194 gfc_constructor *ctor; 4331 gfc_constructor *ctor;
4195 ctor = gfc_constructor_first (init->value.constructor); 4332 ctor = gfc_constructor_first (init->value.constructor);
4196 4333
4197 if (ctor) 4334 if (ctor)
4198 { 4335 {
4199 int first_len;
4200 bool has_ts = (init->ts.u.cl 4336 bool has_ts = (init->ts.u.cl
4201 && init->ts.u.cl->length_from_typespec); 4337 && init->ts.u.cl->length_from_typespec);
4202 4338
4203 /* Remember the length of the first element for checking 4339 /* Remember the length of the first element for checking
4204 that all elements *in the constructor* have the same 4340 that all elements *in the constructor* have the same
4205 length. This need not be the length of the LHS! */ 4341 length. This need not be the length of the LHS! */
4206 gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT); 4342 gcc_assert (ctor->expr->expr_type == EXPR_CONSTANT);
4207 gcc_assert (ctor->expr->ts.type == BT_CHARACTER); 4343 gcc_assert (ctor->expr->ts.type == BT_CHARACTER);
4208 first_len = ctor->expr->value.character.length; 4344 gfc_charlen_t first_len = ctor->expr->value.character.length;
4209 4345
4210 for ( ; ctor; ctor = gfc_constructor_next (ctor)) 4346 for ( ; ctor; ctor = gfc_constructor_next (ctor))
4211 if (ctor->expr->expr_type == EXPR_CONSTANT) 4347 if (ctor->expr->expr_type == EXPR_CONSTANT)
4212 { 4348 {
4213 gfc_set_constant_character_len (len, ctor->expr, 4349 gfc_set_constant_character_len (len, ctor->expr,
4328 *map_p = NULL; 4464 *map_p = NULL;
4329 4465
4330 return init; 4466 return init;
4331 } 4467 }
4332 4468
4469 static bool
4470 class_allocatable (gfc_component *comp)
4471 {
4472 return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
4473 && CLASS_DATA (comp)->attr.allocatable;
4474 }
4475
4476 static bool
4477 class_pointer (gfc_component *comp)
4478 {
4479 return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
4480 && CLASS_DATA (comp)->attr.pointer;
4481 }
4482
4483 static bool
4484 comp_allocatable (gfc_component *comp)
4485 {
4486 return comp->attr.allocatable || class_allocatable (comp);
4487 }
4488
4489 static bool
4490 comp_pointer (gfc_component *comp)
4491 {
4492 return comp->attr.pointer
4493 || comp->attr.pointer
4494 || comp->attr.proc_pointer
4495 || comp->attr.class_pointer
4496 || class_pointer (comp);
4497 }
4498
4333 /* Fetch or generate an initializer for the given component. 4499 /* Fetch or generate an initializer for the given component.
4334 Only generate an initializer if generate is true. */ 4500 Only generate an initializer if generate is true. */
4335 4501
4336 static gfc_expr * 4502 static gfc_expr *
4337 component_initializer (gfc_typespec *ts, gfc_component *c, bool generate) 4503 component_initializer (gfc_component *c, bool generate)
4338 { 4504 {
4339 gfc_expr *init = NULL; 4505 gfc_expr *init = NULL;
4340 4506
4341 /* See if we can find the initializer immediately. 4507 /* Allocatable components always get EXPR_NULL.
4342 Some components should never get initializers. */ 4508 Pointer components are only initialized when generating, and only if they
4343 if (c->initializer || !generate 4509 do not already have an initializer. */
4344 || (ts->type == BT_CLASS && !c->attr.allocatable) 4510 if (comp_allocatable (c) || (generate && comp_pointer (c) && !c->initializer))
4345 || c->attr.pointer 4511 {
4346 || c->attr.class_pointer 4512 init = gfc_get_null_expr (&c->loc);
4347 || c->attr.proc_pointer) 4513 init->ts = c->ts;
4514 return init;
4515 }
4516
4517 /* See if we can find the initializer immediately. */
4518 if (c->initializer || !generate)
4348 return c->initializer; 4519 return c->initializer;
4349 4520
4350 /* Recursively handle derived type components. */ 4521 /* Recursively handle derived type components. */
4351 if (c->ts.type == BT_DERIVED || c->ts.type == BT_CLASS) 4522 else if (c->ts.type == BT_DERIVED || c->ts.type == BT_CLASS)
4352 init = gfc_generate_initializer (&c->ts, true); 4523 init = gfc_generate_initializer (&c->ts, true);
4353 4524
4354 else if (c->ts.type == BT_UNION && c->ts.u.derived->components) 4525 else if (c->ts.type == BT_UNION && c->ts.u.derived->components)
4355 { 4526 {
4356 gfc_component *map = NULL; 4527 gfc_component *map = NULL;
4389 } 4560 }
4390 4561
4391 /* Treat simple components like locals. */ 4562 /* Treat simple components like locals. */
4392 else 4563 else
4393 { 4564 {
4394 init = gfc_build_default_init_expr (&c->ts, &c->loc); 4565 /* We MUST give an initializer, so force generation. */
4566 init = gfc_build_init_expr (&c->ts, &c->loc, true);
4395 gfc_apply_init (&c->ts, &c->attr, init); 4567 gfc_apply_init (&c->ts, &c->attr, init);
4396 } 4568 }
4397 4569
4398 return init; 4570 return init;
4399 } 4571 }
4405 gfc_default_initializer (gfc_typespec *ts) 4577 gfc_default_initializer (gfc_typespec *ts)
4406 { 4578 {
4407 return gfc_generate_initializer (ts, false); 4579 return gfc_generate_initializer (ts, false);
4408 } 4580 }
4409 4581
4582 /* Generate an initializer expression for an iso_c_binding type
4583 such as c_[fun]ptr. The appropriate initializer is c_null_[fun]ptr. */
4584
4585 static gfc_expr *
4586 generate_isocbinding_initializer (gfc_symbol *derived)
4587 {
4588 /* The initializers have already been built into the c_null_[fun]ptr symbols
4589 from gen_special_c_interop_ptr. */
4590 gfc_symtree *npsym = NULL;
4591 if (0 == strcmp (derived->name, "c_ptr"))
4592 gfc_find_sym_tree ("c_null_ptr", gfc_current_ns, true, &npsym);
4593 else if (0 == strcmp (derived->name, "c_funptr"))
4594 gfc_find_sym_tree ("c_null_funptr", gfc_current_ns, true, &npsym);
4595 else
4596 gfc_internal_error ("generate_isocbinding_initializer(): bad iso_c_binding"
4597 " type, expected %<c_ptr%> or %<c_funptr%>");
4598 if (npsym)
4599 {
4600 gfc_expr *init = gfc_copy_expr (npsym->n.sym->value);
4601 init->symtree = npsym;
4602 init->ts.is_iso_c = true;
4603 return init;
4604 }
4605
4606 return NULL;
4607 }
4410 4608
4411 /* Get or generate an expression for a default initializer of a derived type. 4609 /* Get or generate an expression for a default initializer of a derived type.
4412 If -finit-derived is specified, generate default initialization expressions 4610 If -finit-derived is specified, generate default initialization expressions
4413 for components that lack them when generate is set. */ 4611 for components that lack them when generate is set. */
4414 4612
4415 gfc_expr * 4613 gfc_expr *
4416 gfc_generate_initializer (gfc_typespec *ts, bool generate) 4614 gfc_generate_initializer (gfc_typespec *ts, bool generate)
4417 { 4615 {
4418 gfc_expr *init, *tmp; 4616 gfc_expr *init, *tmp;
4419 gfc_component *comp; 4617 gfc_component *comp;
4618
4420 generate = flag_init_derived && generate; 4619 generate = flag_init_derived && generate;
4620
4621 if (ts->u.derived->ts.is_iso_c && generate)
4622 return generate_isocbinding_initializer (ts->u.derived);
4421 4623
4422 /* See if we have a default initializer in this, but not in nested 4624 /* See if we have a default initializer in this, but not in nested
4423 types (otherwise we could use gfc_has_default_initializer()). 4625 types (otherwise we could use gfc_has_default_initializer()).
4424 We don't need to check if we are going to generate them. */ 4626 We don't need to check if we are going to generate them. */
4425 comp = ts->u.derived->components; 4627 comp = ts->u.derived->components;
4426 if (!generate) 4628 if (!generate)
4427 { 4629 {
4428 for (; comp; comp = comp->next) 4630 for (; comp; comp = comp->next)
4429 if (comp->initializer || comp->attr.allocatable 4631 if (comp->initializer || comp_allocatable (comp))
4430 || (comp->ts.type == BT_CLASS && CLASS_DATA (comp)
4431 && CLASS_DATA (comp)->attr.allocatable))
4432 break; 4632 break;
4433 } 4633 }
4434 4634
4435 if (!comp) 4635 if (!comp)
4436 return NULL; 4636 return NULL;
4442 for (comp = ts->u.derived->components; comp; comp = comp->next) 4642 for (comp = ts->u.derived->components; comp; comp = comp->next)
4443 { 4643 {
4444 gfc_constructor *ctor = gfc_constructor_get(); 4644 gfc_constructor *ctor = gfc_constructor_get();
4445 4645
4446 /* Fetch or generate an initializer for the component. */ 4646 /* Fetch or generate an initializer for the component. */
4447 tmp = component_initializer (ts, comp, generate); 4647 tmp = component_initializer (comp, generate);
4448 if (tmp) 4648 if (tmp)
4449 { 4649 {
4450 /* Save the component ref for STRUCTUREs and UNIONs. */ 4650 /* Save the component ref for STRUCTUREs and UNIONs. */
4451 if (ts->u.derived->attr.flavor == FL_STRUCT 4651 if (ts->u.derived->attr.flavor == FL_STRUCT
4452 || ts->u.derived->attr.flavor == FL_UNION) 4652 || ts->u.derived->attr.flavor == FL_UNION)
4453 ctor->n.component = comp; 4653 ctor->n.component = comp;
4454 4654
4455 /* If the initializer was not generated, we need a copy. */ 4655 /* If the initializer was not generated, we need a copy. */
4456 ctor->expr = comp->initializer ? gfc_copy_expr (tmp) : tmp; 4656 ctor->expr = comp->initializer ? gfc_copy_expr (tmp) : tmp;
4457 if ((comp->ts.type != tmp->ts.type 4657 if ((comp->ts.type != tmp->ts.type || comp->ts.kind != tmp->ts.kind)
4458 || comp->ts.kind != tmp->ts.kind)
4459 && !comp->attr.pointer && !comp->attr.proc_pointer) 4658 && !comp->attr.pointer && !comp->attr.proc_pointer)
4460 { 4659 {
4461 bool val; 4660 bool val;
4462 val = gfc_convert_type_warn (ctor->expr, &comp->ts, 1, false); 4661 val = gfc_convert_type_warn (ctor->expr, &comp->ts, 1, false);
4463 if (val == false) 4662 if (val == false)
4464 return NULL; 4663 return NULL;
4465 } 4664 }
4466 }
4467
4468 if (comp->attr.allocatable
4469 || (comp->ts.type == BT_CLASS && CLASS_DATA (comp)->attr.allocatable))
4470 {
4471 ctor->expr = gfc_get_expr ();
4472 ctor->expr->expr_type = EXPR_NULL;
4473 ctor->expr->where = init->where;
4474 ctor->expr->ts = comp->ts;
4475 } 4665 }
4476 4666
4477 gfc_constructor_append (&init->value.constructor, ctor); 4667 gfc_constructor_append (&init->value.constructor, ctor);
4478 } 4668 }
4479 4669
4820 5010
4821 5011
4822 /* Determine if an expression is a function with an allocatable class array 5012 /* Determine if an expression is a function with an allocatable class array
4823 result. */ 5013 result. */
4824 bool 5014 bool
4825 gfc_is_alloc_class_array_function (gfc_expr *expr) 5015 gfc_is_class_array_function (gfc_expr *expr)
4826 { 5016 {
4827 if (expr->expr_type == EXPR_FUNCTION 5017 if (expr->expr_type == EXPR_FUNCTION
4828 && expr->value.function.esym 5018 && expr->value.function.esym
4829 && expr->value.function.esym->result 5019 && expr->value.function.esym->result
4830 && expr->value.function.esym->result->ts.type == BT_CLASS 5020 && expr->value.function.esym->result->ts.type == BT_CLASS
4831 && CLASS_DATA (expr->value.function.esym->result)->attr.dimension 5021 && CLASS_DATA (expr->value.function.esym->result)->attr.dimension
4832 && CLASS_DATA (expr->value.function.esym->result)->attr.allocatable) 5022 && (CLASS_DATA (expr->value.function.esym->result)->attr.allocatable
5023 || CLASS_DATA (expr->value.function.esym->result)->attr.pointer))
4833 return true; 5024 return true;
4834 5025
4835 return false; 5026 return false;
4836 } 5027 }
4837 5028
4981 5172
4982 return true; 5173 return true;
4983 } 5174 }
4984 5175
4985 gfc_expr * 5176 gfc_expr *
4986 gfc_find_stat_co(gfc_expr *e) 5177 gfc_find_team_co (gfc_expr *e)
5178 {
5179 gfc_ref *ref;
5180
5181 for (ref = e->ref; ref; ref = ref->next)
5182 if (ref->type == REF_ARRAY && ref->u.ar.codimen > 0)
5183 return ref->u.ar.team;
5184
5185 if (e->value.function.actual->expr)
5186 for (ref = e->value.function.actual->expr->ref; ref;
5187 ref = ref->next)
5188 if (ref->type == REF_ARRAY && ref->u.ar.codimen > 0)
5189 return ref->u.ar.team;
5190
5191 return NULL;
5192 }
5193
5194 gfc_expr *
5195 gfc_find_stat_co (gfc_expr *e)
4987 { 5196 {
4988 gfc_ref *ref; 5197 gfc_ref *ref;
4989 5198
4990 for (ref = e->ref; ref; ref = ref->next) 5199 for (ref = e->ref; ref; ref = ref->next)
4991 if (ref->type == REF_ARRAY && ref->u.ar.codimen > 0) 5200 if (ref->type == REF_ARRAY && ref->u.ar.codimen > 0)
5183 gfc_array_ref *ar = NULL; 5392 gfc_array_ref *ar = NULL;
5184 gfc_ref *ref, *part_ref = NULL; 5393 gfc_ref *ref, *part_ref = NULL;
5185 gfc_symbol *sym; 5394 gfc_symbol *sym;
5186 5395
5187 if (expr->expr_type == EXPR_FUNCTION) 5396 if (expr->expr_type == EXPR_FUNCTION)
5188 return expr->value.function.esym 5397 {
5189 ? expr->value.function.esym->result->attr.contiguous : false; 5398 if (expr->value.function.esym)
5399 return expr->value.function.esym->result->attr.contiguous;
5400 else
5401 {
5402 /* Type-bound procedures. */
5403 gfc_symbol *s = expr->symtree->n.sym;
5404 if (s->ts.type != BT_CLASS && s->ts.type != BT_DERIVED)
5405 return false;
5406
5407 gfc_ref *rc = NULL;
5408 for (gfc_ref *r = expr->ref; r; r = r->next)
5409 if (r->type == REF_COMPONENT)
5410 rc = r;
5411
5412 if (rc == NULL || rc->u.c.component == NULL
5413 || rc->u.c.component->ts.interface == NULL)
5414 return false;
5415
5416 return rc->u.c.component->ts.interface->attr.contiguous;
5417 }
5418 }
5190 else if (expr->expr_type != EXPR_VARIABLE) 5419 else if (expr->expr_type != EXPR_VARIABLE)
5191 return false; 5420 return false;
5192 5421
5193 if (!permit_element && expr->rank == 0) 5422 if (!permit_element && expr->rank == 0)
5194 return false; 5423 return false;
5206 ar = &ref->u.ar; 5435 ar = &ref->u.ar;
5207 } 5436 }
5208 5437
5209 sym = expr->symtree->n.sym; 5438 sym = expr->symtree->n.sym;
5210 if (expr->ts.type != BT_CLASS 5439 if (expr->ts.type != BT_CLASS
5211 && ((part_ref 5440 && ((part_ref
5212 && !part_ref->u.c.component->attr.contiguous 5441 && !part_ref->u.c.component->attr.contiguous
5213 && part_ref->u.c.component->attr.pointer) 5442 && part_ref->u.c.component->attr.pointer)
5214 || (!part_ref 5443 || (!part_ref
5215 && !sym->attr.contiguous 5444 && !sym->attr.contiguous
5216 && (sym->attr.pointer 5445 && (sym->attr.pointer
5217 || sym->as->type == AS_ASSUMED_RANK 5446 || (sym->as && sym->as->type == AS_ASSUMED_RANK)
5218 || sym->as->type == AS_ASSUMED_SHAPE)))) 5447 || (sym->as && sym->as->type == AS_ASSUMED_SHAPE)))))
5219 return false; 5448 return false;
5220 5449
5221 if (!ar || ar->type == AR_FULL) 5450 if (!ar || ar->type == AR_FULL)
5222 return true; 5451 return true;
5223 5452