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

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).