Re: [PATCH] Fortran: Mark internal symbols as artificial [PR88009,PR68800]

2021-11-17 Thread Bernhard Reutner-Fischer via Fortran
On Tue, 16 Nov 2021 21:46:32 +0100
Harald Anlauf via Fortran  wrote:

> Hi Bernhard,
> 
> I'm trying to understand your patch.  What does it really try to solve?

Compiler generated symbols should be marked artificial.
The fix for PR88009 ( f8add009ce300f24b75e9c2e2cc5dd944a020c28 ,
r9-5194 ) added artificial just to the _final component and left out all the 
rest.
Note that the majority of compiler generated symbols in class.c
already had artificial set properly.
The proposed patch amends the other generated symbols to be marked
artificial, too.

The other parts fix memory leaks.

> 
> PR88009 is closed and seems to have nothing to do with this.

Well it marked only _final as artificial and forgot to adjust the
others as well.
We can remove the reference to PR88009 if you prefer?

thanks!
> 
> Harald
> 
> Am 14.11.21 um 23:17 schrieb Bernhard Reutner-Fischer via Fortran:
> > Hi!
> > 
> > Amend fix for PR88009 to mark all these class components as artificial.
> > 
> > gcc/fortran/ChangeLog:
> > 
> >  * class.c (gfc_build_class_symbol, generate_finalization_wrapper,
> >  (gfc_find_derived_vtab, find_intrinsic_vtab): Use stringpool for
> >  names. Mark internal symbols as artificial.
> >  * decl.c (gfc_match_decl_type_spec, gfc_match_end): Fix
> >  indentation.
> >  (gfc_match_derived_decl): Fix indentation. Check extension level
> >  before incrementing refs counter.
> >  * parse.c (parse_derived): Fix style.
> >  * resolve.c (resolve_global_procedure): Likewise.
> >  * symbol.c (gfc_check_conflict): Do not ignore artificial symbols.
> >  (gfc_add_flavor): Reorder condition, cheapest first.
> >  (gfc_new_symbol, gfc_get_sym_tree,
> >  generate_isocbinding_symbol): Fix style.
> >  * trans-expr.c (gfc_trans_subcomponent_assign): Remove
> >  restriction on !artificial.
> >  * match.c (gfc_match_equivalence): Special-case CLASS_DATA for
> >  warnings.
> > 
> > ---
> > gfc_match_equivalence(), too, should not bail-out early on the first
> > error but should diagnose all errors. I.e. not goto cleanup but set
> > err=true and continue in order to diagnose all constraints of a
> > statement. Maybe Sandra or somebody else will eventually find time to
> > tweak that.
> > 
> > I think it also plugs a very minor leak of name in gfc_find_derived_vtab
> > so i also tagged it [PR68800]. At least that was the initial
> > motiviation to look at that spot.
> > We were doing
> > -  name = xasprintf ("__vtab_%s", tname);
> > ...
> >gfc_set_sym_referenced (vtab);
> > - name = xasprintf ("__vtype_%s", tname);
> > 
> > Bootstrapped and regtested without regressions on x86_64-unknown-linux.
> > Ok for trunk?
> >   
> 
> 



Re: [PATCH] Fortran: Mark internal symbols as artificial [PR88009,PR68800]

2021-11-17 Thread Harald Anlauf via Fortran

Do you have testcases/reproducers demonstrating that the patch actually
fixes the issues you're describing?

Am 17.11.21 um 09:12 schrieb Bernhard Reutner-Fischer via Gcc-patches:

On Tue, 16 Nov 2021 21:46:32 +0100
Harald Anlauf via Fortran  wrote:


Hi Bernhard,

I'm trying to understand your patch.  What does it really try to solve?


Compiler generated symbols should be marked artificial.
The fix for PR88009 ( f8add009ce300f24b75e9c2e2cc5dd944a020c28 ,
r9-5194 ) added artificial just to the _final component and left out all the 
rest.
Note that the majority of compiler generated symbols in class.c
already had artificial set properly.
The proposed patch amends the other generated symbols to be marked
artificial, too.

The other parts fix memory leaks.



PR88009 is closed and seems to have nothing to do with this.


Well it marked only _final as artificial and forgot to adjust the
others as well.
We can remove the reference to PR88009 if you prefer?

thanks!


Harald

Am 14.11.21 um 23:17 schrieb Bernhard Reutner-Fischer via Fortran:

Hi!

Amend fix for PR88009 to mark all these class components as artificial.

gcc/fortran/ChangeLog:

  * class.c (gfc_build_class_symbol, generate_finalization_wrapper,
  (gfc_find_derived_vtab, find_intrinsic_vtab): Use stringpool for
  names. Mark internal symbols as artificial.
  * decl.c (gfc_match_decl_type_spec, gfc_match_end): Fix
  indentation.
  (gfc_match_derived_decl): Fix indentation. Check extension level
  before incrementing refs counter.
  * parse.c (parse_derived): Fix style.
  * resolve.c (resolve_global_procedure): Likewise.
  * symbol.c (gfc_check_conflict): Do not ignore artificial symbols.
  (gfc_add_flavor): Reorder condition, cheapest first.
  (gfc_new_symbol, gfc_get_sym_tree,
  generate_isocbinding_symbol): Fix style.
  * trans-expr.c (gfc_trans_subcomponent_assign): Remove
  restriction on !artificial.
  * match.c (gfc_match_equivalence): Special-case CLASS_DATA for
  warnings.

---
gfc_match_equivalence(), too, should not bail-out early on the first
error but should diagnose all errors. I.e. not goto cleanup but set
err=true and continue in order to diagnose all constraints of a
statement. Maybe Sandra or somebody else will eventually find time to
tweak that.

I think it also plugs a very minor leak of name in gfc_find_derived_vtab
so i also tagged it [PR68800]. At least that was the initial
motiviation to look at that spot.
We were doing
-  name = xasprintf ("__vtab_%s", tname);
...
gfc_set_sym_referenced (vtab);
- name = xasprintf ("__vtype_%s", tname);

Bootstrapped and regtested without regressions on x86_64-unknown-linux.
Ok for trunk?











[PATCH] PR fortran/101329 - ICE: Invalid expression in gfc_element_size

2021-11-17 Thread Harald Anlauf via Fortran
Dear Fortranners,

as NULL() is not interoperable, we have to reject it.
Confirmed by NAG.  Other compilers show "interesting behavior".

Obvious patch by Steve.  Regtested on x86_64-pc-linux-gnu.

OK for mainline?

Thanks,
Harald

From 52a3ee53f0a12e897c4651fa8378e045653b9fd3 Mon Sep 17 00:00:00 2001
From: Harald Anlauf 
Date: Wed, 17 Nov 2021 22:21:24 +0100
Subject: [PATCH] Fortran: NULL() is not interoperable

gcc/fortran/ChangeLog:

	PR fortran/101329
	* check.c (is_c_interoperable): Reject NULL() as it is not
	interoperable.

gcc/testsuite/ChangeLog:

	PR fortran/101329
	* gfortran.dg/pr101329.f90: New test.

Co-authored-by: Steven G. Kargl 
---
 gcc/fortran/check.c|  6 ++
 gcc/testsuite/gfortran.dg/pr101329.f90 | 13 +
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr101329.f90

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index ffa07b510cd..5a5aca10ebe 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5223,6 +5223,12 @@ is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr)
 {
   *msg = NULL;

+  if (expr->expr_type == EXPR_NULL)
+{
+  *msg = "NULL() is not interoperable";
+  return false;
+}
+
   if (expr->ts.type == BT_CLASS)
 {
   *msg = "Expression is polymorphic";
diff --git a/gcc/testsuite/gfortran.dg/pr101329.f90 b/gcc/testsuite/gfortran.dg/pr101329.f90
new file mode 100644
index 000..b82210d4e28
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr101329.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! PR fortran/101329 - ICE: Invalid expression in gfc_element_size
+
+program p
+  use iso_c_binding
+  implicit none
+  integer(c_int), pointer :: ip4
+  integer(c_int64_t), pointer :: ip8
+  print *, c_sizeof (c_null_ptr) ! valid
+  print *, c_sizeof (null ())! { dg-error "is not interoperable" }
+  print *, c_sizeof (null (ip4)) ! { dg-error "is not interoperable" }
+  print *, c_sizeof (null (ip8)) ! { dg-error "is not interoperable" }
+end
--
2.26.2