[Bug c/108375] [10/11/12/13 Regression] Some variably modified types not detected as such

2023-02-18 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108375

--- Comment #9 from CVS Commits  ---
The master branch has been updated by Martin Uecker :

https://gcc.gnu.org/g:47821ba07a19b672d3cba351a03af2b122e02213

commit r13-6128-g47821ba07a19b672d3cba351a03af2b122e02213
Author: Martin Uecker 
Date:   Wed Feb 15 10:54:00 2023 +0100

C: Detect all variably modified types [PR108375]

Some variably modified types were not detected correctly.
Define C_TYPE_VARIABLY_MODIFIED via TYPE_LANG_FLAG 6 in the CFE.
This flag records whether a type is variably modified and is
set for all such types including arrays with variably modified
element type or structures and unions with variably modified
members. This is then used to detect such types in the C FE
and middle-end (via the existing language hook).

gcc/c/ChangeLog:
PR c/108375
* c-decl.cc (decl_jump_unsafe): Use c_type_variably_modified_p.
(diagnose_mismatched_decl): Dito.
(warn_about_goto): Dito:
(c_check_switch_jump_warnings): Dito.
(finish_decl): Dito.
(finish_struct): Dito.
(grokdeclarator): Set C_TYPE_VARIABLY_MODIFIED.
(finish_struct): Set C_TYPE_VARIABLY_MODIFIED.
* c-objc-common.cc (c_var_mod_p): New function.
(c_var_unspec_p): Remove.
* c-objc-common.h: Set lang hook.
* c-parser.cc (c_parser_declararion_or_fndef): Use
c_type_variably_modified_p.
(c_parser_typeof_specifier): Dito.
(c_parser_has_attribute_expression): Dito.
(c_parser_generic_selection): Dito.
* c-tree.h: Define C_TYPE_VARIABLY_MODIFIED and define
c_var_mode_p.
* c-typeck.cc: Remove c_vla_mod_p and use C_TYPE_VARIABLY_MODIFIED.

gcc/testsuite/ChangeLog:
PR c/108375
* gcc.dg/pr108375-1.c: New test.
* gcc.dg/pr108375-2.c: New test.

[Bug c/108375] [10/11/12/13 Regression] Some variably modified types not detected as such

2023-02-17 Thread muecker at gwdg dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108375

--- Comment #8 from Martin Uecker  ---
PATCH: https://gcc.gnu.org/pipermail/gcc-patches/2023-February/612245.html

[Bug c/108375] [10/11/12/13 Regression] Some variably modified types not detected as such

2023-02-15 Thread muecker at gwdg dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108375

Martin Uecker  changed:

   What|Removed |Added

  Attachment #54458|0   |1
is obsolete||

--- Comment #7 from Martin Uecker  ---
Created attachment 54473
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54473=edit
patch against trunk


This patch should be better. It is a FE only change. It stores uses a LANG_FLAG
for each type to store whether it is a VM type which is set during
construction. This should be very efficient. The existing (previously useless)
lang hook then also communicates this information to the middle end. The
variably_modified_p function in tree.cc now does unnecessary work for C, maybe
this could be avoided.

[Bug c/108375] [10/11/12/13 Regression] Some variably modified types not detected as such

2023-02-14 Thread muecker at gwdg dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108375

--- Comment #6 from Martin Uecker  ---
Created attachment 54458
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54458=edit
preliminary patch against trunk

Here is a preliminary patch. It takes a bit from type_common to cache negative
results for records / unions (i.e. not a vm-type). Performance might be ok,
although I think an approach where the FE sets the bit for records which are
known to be variaby modified and all others are not might be preferable.

[Bug c/108375] [10/11/12/13 Regression] Some variably modified types not detected as such

2023-02-13 Thread muecker at gwdg dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108375

--- Comment #5 from Martin Uecker  ---

Recursing into arrays is simple and does not seem to cause any problems,
but this not enough for GNU C, we can also have VLA or variably modified
types as member of structs. At least the later is sometimes useful.

void bar(int a)
{
  struct foo { char (*p)[a]; };
  goto x;
  struct foo B;
  x: ;
}

Unfortunately, recursing into structs is too expensive. We could use
walk_tree_without_duplicates but this still seems expensive.

I think we should simply add a bit which is set by the C FE for such
structs.  The question is whether this is also needed by Ada or other
languages?

[Bug c/108375] [10/11/12/13 Regression] Some variably modified types not detected as such

2023-01-13 Thread ebotcazou at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108375

Eric Botcazou  changed:

   What|Removed |Added

 CC||ebotcazou at gcc dot gnu.org

--- Comment #4 from Eric Botcazou  ---
> I can't tell if the Ada testcase was added or not.

gnat.dg/pointer_array.adb.  The change is probably obsolete nowadays given the
TREE_VISITED dance done in the POINTER_TYPE case.

[Bug c/108375] [10/11/12/13 Regression] Some variably modified types not detected as such

2023-01-11 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108375

--- Comment #3 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #2)
> https://gcc.gnu.org/pipermail/gcc-patches/2006-May/194375.html

I can't tell if the Ada testcase was added or not.

[Bug c/108375] [10/11/12/13 Regression] Some variably modified types not detected as such

2023-01-11 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108375

--- Comment #2 from Andrew Pinski  ---
https://gcc.gnu.org/pipermail/gcc-patches/2006-May/194375.html

[Bug c/108375] [10/11/12/13 Regression] Some variably modified types not detected as such

2023-01-11 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108375

Andrew Pinski  changed:

   What|Removed |Added

   Last reconfirmed||2023-01-11
 Ever confirmed|0   |1
   Target Milestone|--- |10.5
  Known to fail||4.4.7
  Known to work||4.1.2
 Status|UNCONFIRMED |NEW

--- Comment #1 from Andrew Pinski  ---
Confirmed.