public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/95002] New: VLA:   'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>'
@ 2020-05-08  9:34 burnus at gcc dot gnu.org
  2020-05-08 10:04 ` [Bug c/95002] " burnus at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2020-05-08  9:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95002

            Bug ID: 95002
           Summary: VLA:   'var = sizeof array' gives spurous '= array,
                    <size expr>' instead of just '= <size expr>'
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

[Cf. PR94874 and PR 90859; the extra 'array' is exposed to OpenMP and makes a
difference there.]


The following code (assuming size_t == unsigned long):

void f1(int len_1) {int arr1[len_1]; int size1 = sizeof arr1; }
void f2(int len_2) {int arr2[len_2]; unsigned long size2 = sizeof arr2; }


Gives a spurious '= array,' is the LHS and the RHS have the same type:

int size1 = (int) ((unsigned int) (sizetype) SAVE_EXPR <len_1> * 4);

long unsigned int size2 = arr2, (long unsigned int) ((sizetype) SAVE_EXPR
<len_2> * 4);;

The code starts to differ at c/c-typeck.c's digest_init() when the second code
(size_t on LHS) enters the "if (inside_init' – as the compound_expr
'inside_init' has the same type as the (lhs) 'type'.

That's fixed by:

--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -7974 +7974,2 @@ digest_init (location_t init_loc, tree type, tree init,
-      if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE)
+      if (TREE_CODE (TREE_TYPE (inside_init)) == POINTER_TYPE
+          || TREE_CODE (TREE_TYPE (inside_init)) == INTEGER_TYPE)

However, despite having then an identical 'convert_for_assignment' call, the
result is still different.

Debugging continues …

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/95002] VLA:   'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>'
  2020-05-08  9:34 [Bug c/95002] New: VLA: 'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>' burnus at gcc dot gnu.org
@ 2020-05-08 10:04 ` burnus at gcc dot gnu.org
  2020-05-11  9:06 ` burnus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2020-05-08 10:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95002

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 48481
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48481&action=edit
PATCH – works but is modifies quite a lot: digest_init, convert_for_assignment,
convert

Working patch – but I wonder whether that many modifications are needed?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/95002] VLA:   'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>'
  2020-05-08  9:34 [Bug c/95002] New: VLA: 'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>' burnus at gcc dot gnu.org
  2020-05-08 10:04 ` [Bug c/95002] " burnus at gcc dot gnu.org
@ 2020-05-11  9:06 ` burnus at gcc dot gnu.org
  2020-05-11 13:53 ` burnus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2020-05-11  9:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95002

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> ---
The "array," is added by c_expr_sizeof_expr:

      if (c_vla_type_p (TREE_TYPE (folded_expr)))
        {
          /* sizeof is evaluated when given a vla (C99 6.5.3.4p2).  */
          ret.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret.value),
                              folded_expr, ret.value);
          C_MAYBE_CONST_EXPR_NON_CONST (ret.value) = !expr_const_operands;
          SET_EXPR_LOCATION (ret.value, loc);
        }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/95002] VLA:   'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>'
  2020-05-08  9:34 [Bug c/95002] New: VLA: 'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>' burnus at gcc dot gnu.org
  2020-05-08 10:04 ` [Bug c/95002] " burnus at gcc dot gnu.org
  2020-05-11  9:06 ` burnus at gcc dot gnu.org
@ 2020-05-11 13:53 ` burnus at gcc dot gnu.org
  2020-05-11 13:54 ` burnus at gcc dot gnu.org
  2020-05-11 14:14 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2020-05-11 13:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95002

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
As discussed with Joseph on IRC:

* The 'array, 4*len' is one on purpose per C spec
  (sizeof for an expression with VLA type is defined to evaluate its argument.)
* g++ might not do this, if so, it is a bug.

* Convert should do the folding and leave the fold to gimple folding

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/95002] VLA:   'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>'
  2020-05-08  9:34 [Bug c/95002] New: VLA: 'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>' burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-05-11 13:53 ` burnus at gcc dot gnu.org
@ 2020-05-11 13:54 ` burnus at gcc dot gnu.org
  2020-05-11 14:14 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: burnus at gcc dot gnu.org @ 2020-05-11 13:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95002

--- Comment #4 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to Tobias Burnus from comment #3)
> * Convert should do the folding and leave the fold to gimple folding

Which means that one has to do this kind of folding before handling the
share/map handling for OpenMP/OpenACC.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/95002] VLA:   'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>'
  2020-05-08  9:34 [Bug c/95002] New: VLA: 'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>' burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2020-05-11 13:54 ` burnus at gcc dot gnu.org
@ 2020-05-11 14:14 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-05-11 14:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95002

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Or deal with that during gimplification.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-05-11 14:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08  9:34 [Bug c/95002] New: VLA: 'var = sizeof array' gives spurous '= array, <size expr>' instead of just '= <size expr>' burnus at gcc dot gnu.org
2020-05-08 10:04 ` [Bug c/95002] " burnus at gcc dot gnu.org
2020-05-11  9:06 ` burnus at gcc dot gnu.org
2020-05-11 13:53 ` burnus at gcc dot gnu.org
2020-05-11 13:54 ` burnus at gcc dot gnu.org
2020-05-11 14:14 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).