Message ID | 1505a7c9fab.f52df49364480.2316667444406332595@zoho.com |
---|---|
State | New |
Headers | show |
On Sun, Oct 11, 2015 at 10:18:48PM -0700, Louis Krupp wrote: > The problem involves a derived type with a character component declared CHARACTER(NULL()) or CHARACTER(NULL(n)), where mold argument n is an integer pointer. > I was looking at 67805 this weekend, which is somewhat related to this PR. AFAICT, gfortran does no checking for n in CHARACTER(LEN=n). n should be a scalar-int-expr (that is scalar INTEGER expression). NULL() is not an integer, and NULL(n) is a disassociated pointer. So, I believe neither can appear in an scalar-int-expr. Note, also that there is a table in 13.7.125 on where NULL() can appear. My patch for 67805 leads to one regression that I've been unable to resolve.
---- On Mon, 12 Oct 2015 08:41:43 -0700 Steve Kargl<sgk@troutmask.apl.washington.edu> wrote ---- > On Sun, Oct 11, 2015 at 10:18:48PM -0700, Louis Krupp wrote: > > The problem involves a derived type with a character component declared CHARACTER(NULL()) or CHARACTER(NULL(n)), where mold argument n is an integer pointer. > > > > I was looking at 67805 this weekend, which is somewhat > related to this PR. AFAICT, gfortran does no checking > for n in CHARACTER(LEN=n). n should be a scalar-int-expr > (that is scalar INTEGER expression). NULL() is not > an integer, and NULL(n) is a disassociated pointer. So, > I believe neither can appear in an scalar-int-expr. > > Note, also that there is a table in 13.7.125 on where > NULL() can appear. > > My patch for 67805 leads to one regression that I've been > unable to resolve. For what it's worth, my patch does absolutely nothing for 67805. As to my error message, should I fold this misuse of NULL() into the existing message saying "Character length needs to be a constant specification expression" and not mention NULL()? There are times I wish I knew the story behind the code in some of these bug reports. Were they written by someone looking for edge cases that might cause trouble, or was someone actually trying to do something? Louis
Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 228700) +++ gcc/fortran/resolve.c (working copy) @@ -1134,7 +1134,8 @@ resolve_structure_cons (gfc_expr *expr, int init) t = true; if (expr->ts.type == BT_DERIVED) - resolve_fl_derived0 (expr->ts.u.derived); + if (!resolve_fl_derived0 (expr->ts.u.derived)) + return false; cons = gfc_constructor_first (expr->value.constructor); @@ -10882,6 +10883,13 @@ resolve_charlen (gfc_charlen *cl) } } + if (cl->length && cl->length->expr_type == EXPR_NULL) + { + gfc_error ("Character length is target of NULL pointer at %L", + &cl->length->where); + return false; + } + /* "If the character length parameter value evaluates to a negative value, the length of character entities declared is zero." */ if (cl->length && !gfc_extract_int (cl->length, &i) && i < 0) @@ -13090,10 +13098,16 @@ resolve_fl_derived0 (gfc_symbol *sym) || (!resolve_charlen(c->ts.u.cl)) || !gfc_is_constant_expr (c->ts.u.cl->length)) { - gfc_error ("Character length of component %qs needs to " - "be a constant specification expression at %L", + gfc_error (c->ts.u.cl->length && + c->ts.u.cl->length->expr_type == EXPR_NULL ? + "Character length of component %qs is target of " + "NULL pointer at %L" + : + "Character length of component %qs needs to " + "be a constant specification expression at %L", c->name, - c->ts.u.cl->length ? &c->ts.u.cl->length->where : &c->loc); + c->ts.u.cl->length ? + &c->ts.u.cl->length->where : &c->loc); return false; } }