public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/109450] New: Wrong code for VLA in struct sithe size expression
@ 2023-04-08 9:21 muecker at gwdg dot de
2023-04-09 2:20 ` [Bug c/109450] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: muecker at gwdg dot de @ 2023-04-08 9:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109450
Bug ID: 109450
Summary: Wrong code for VLA in struct sithe size expression
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: muecker at gwdg dot de
Target Milestone: ---
The following code should return 1 but returns two.
int bar(int n, struct foo* x)
{
int a = n;
struct foo { char buf[n++]; }* p = x;
return a;
}
int main()
{
return bar(1, 0);
}
https://godbolt.org/z/e94dsfhc9
I noticed this when working on a fix for PR107557 and PR108423.
Already affects 4.7.3 and maybe earlier.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/109450] Wrong code for VLA in struct sithe size expression
2023-04-08 9:21 [Bug c/109450] New: Wrong code for VLA in struct sithe size expression muecker at gwdg dot de
@ 2023-04-09 2:20 ` pinskia at gcc dot gnu.org
2023-04-09 7:58 ` [Bug c/109450] VLA struct definition vs use in the function declaration muecker at gwdg dot de
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-04-09 2:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109450
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |ice-on-valid-code,
| |wrong-code
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The issue is related to struct foo in the function declaration.
With a slightly modified code you can get an ICE instead:
int bar(int n, struct foo *x)
{
int a = n;
struct foo { char buf[a++]; }* p = x;
return n == a;
}
int main()
{
return bar(1, 0);
}
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/109450] VLA struct definition vs use in the function declaration
2023-04-08 9:21 [Bug c/109450] New: Wrong code for VLA in struct sithe size expression muecker at gwdg dot de
2023-04-09 2:20 ` [Bug c/109450] " pinskia at gcc dot gnu.org
@ 2023-04-09 7:58 ` muecker at gwdg dot de
2023-05-18 12:55 ` muecker at gwdg dot de
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: muecker at gwdg dot de @ 2023-04-09 7:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109450
--- Comment #2 from Martin Uecker <muecker at gwdg dot de> ---
This is unrelated to PR29970. The cause of this is that gimplify_parm_type
recurses into incomplete types which is wrong for the same reason as in
gimplify_type_sizes.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/109450] VLA struct definition vs use in the function declaration
2023-04-08 9:21 [Bug c/109450] New: Wrong code for VLA in struct sithe size expression muecker at gwdg dot de
2023-04-09 2:20 ` [Bug c/109450] " pinskia at gcc dot gnu.org
2023-04-09 7:58 ` [Bug c/109450] VLA struct definition vs use in the function declaration muecker at gwdg dot de
@ 2023-05-18 12:55 ` muecker at gwdg dot de
2023-05-23 20:05 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: muecker at gwdg dot de @ 2023-05-18 12:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109450
--- Comment #3 from Martin Uecker <muecker at gwdg dot de> ---
PATCH: https://gcc.gnu.org/pipermail/gcc-patches/2023-May/618911.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/109450] VLA struct definition vs use in the function declaration
2023-04-08 9:21 [Bug c/109450] New: Wrong code for VLA in struct sithe size expression muecker at gwdg dot de
` (2 preceding siblings ...)
2023-05-18 12:55 ` muecker at gwdg dot de
@ 2023-05-23 20:05 ` cvs-commit at gcc dot gnu.org
2023-11-03 20:06 ` uecker at gcc dot gnu.org
2023-11-03 20:06 ` uecker at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-23 20:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109450
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Uecker <uecker@gcc.gnu.org>:
https://gcc.gnu.org/g:42d1612eb5c3b2ee327bc3336bfcbc43a0d0fc5b
commit r14-1143-g42d1612eb5c3b2ee327bc3336bfcbc43a0d0fc5b
Author: Martin Uecker <uecker@tugraz.at>
Date: Sun May 21 19:32:01 2023 +0200
Fix ICEs related to VM types in C 2/2 [PR109450]
Size expressions were sometimes lost and not gimplified correctly,
leading to ICEs and incorrect evaluation order. Fix this by 1) not
recursing pointers when gimplifying parameters, which was incorrect
because it might access variables declared later for incomplete
structs, and 2) adding a decl expr for variably-modified arrays
that are pointed to by parameters declared as arrays.
PR c/109450
gcc/
* function.cc (gimplify_parm_type): Remove function.
(gimplify_parameters): Call gimplify_type_sizes.
gcc/c/
* c-decl.cc (add_decl_expr): New function.
(grokdeclarator): Add decl expr for size expression in
types pointed to by parameters declared as arrays.
gcc/testsuite/
* gcc.dg/pr109450-1.c: New test.
* gcc.dg/pr109450-2.c: New test.
* gcc.dg/vla-26.c: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/109450] VLA struct definition vs use in the function declaration
2023-04-08 9:21 [Bug c/109450] New: Wrong code for VLA in struct sithe size expression muecker at gwdg dot de
` (3 preceding siblings ...)
2023-05-23 20:05 ` cvs-commit at gcc dot gnu.org
@ 2023-11-03 20:06 ` uecker at gcc dot gnu.org
2023-11-03 20:06 ` uecker at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: uecker at gcc dot gnu.org @ 2023-11-03 20:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109450
uecker at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |uecker at gcc dot gnu.org
Target Milestone|--- |14.0
--- Comment #5 from uecker at gcc dot gnu.org ---
fixed on trunk.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/109450] VLA struct definition vs use in the function declaration
2023-04-08 9:21 [Bug c/109450] New: Wrong code for VLA in struct sithe size expression muecker at gwdg dot de
` (4 preceding siblings ...)
2023-11-03 20:06 ` uecker at gcc dot gnu.org
@ 2023-11-03 20:06 ` uecker at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: uecker at gcc dot gnu.org @ 2023-11-03 20:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109450
uecker at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from uecker at gcc dot gnu.org ---
fixed on trunk.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-11-03 20:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-08 9:21 [Bug c/109450] New: Wrong code for VLA in struct sithe size expression muecker at gwdg dot de
2023-04-09 2:20 ` [Bug c/109450] " pinskia at gcc dot gnu.org
2023-04-09 7:58 ` [Bug c/109450] VLA struct definition vs use in the function declaration muecker at gwdg dot de
2023-05-18 12:55 ` muecker at gwdg dot de
2023-05-23 20:05 ` cvs-commit at gcc dot gnu.org
2023-11-03 20:06 ` uecker at gcc dot gnu.org
2023-11-03 20:06 ` uecker 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).