public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55446] New: array new with size zero vanishes from object code
@ 2012-11-23 10:49 jens.maurer at gmx dot net
2012-11-23 22:21 ` [Bug c++/55446] " daniel.kruegler at googlemail dot com
` (14 more replies)
0 siblings, 15 replies; 16+ messages in thread
From: jens.maurer at gmx dot net @ 2012-11-23 10:49 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Bug #: 55446
Summary: array new with size zero vanishes from object code
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: jens.maurer@gmx.net
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
The following program compiles successfully and outputs nothing at all. In
fact, the generated assembly has an empty "main". This happens even when
compiling with -O0.
#include <iostream>
struct S {
S() { }
};
int main()
{
std::cout << new S[0] << " bla" << std::endl;
}
$ g++ new-opt.cc -Wall -Wextra
$ ./a.out
(no output)
The issue goes away when removing the default constructor of "S". It seems gcc
believes array-new with zero size is undefined behavior and thus removes the
rest of the expression. I can't follow the "undefined behavior" part;
array-new with zero size should yield a non-zero pointer (see 3.7.3.1p2
[basic.stc.dynamic.allocation] and 5.3.4p7 [expr.new]).
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
@ 2012-11-23 22:21 ` daniel.kruegler at googlemail dot com
2012-11-23 22:28 ` paolo.carlini at oracle dot com
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-11-23 22:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Daniel Krügler <daniel.kruegler at googlemail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |daniel.kruegler at
| |googlemail dot com
--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-11-23 22:21:30 UTC ---
I observe the same thing with gcc 4.8.0 20121104 (experimental) on my
mingw-x86_64 system. Odd.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
2012-11-23 22:21 ` [Bug c++/55446] " daniel.kruegler at googlemail dot com
@ 2012-11-23 22:28 ` paolo.carlini at oracle dot com
2012-11-23 22:29 ` paolo.carlini at oracle dot com
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-23 22:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-11-23
Ever Confirmed|0 |1
--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-23 22:28:26 UTC ---
Yes, this is confirmed.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
2012-11-23 22:21 ` [Bug c++/55446] " daniel.kruegler at googlemail dot com
2012-11-23 22:28 ` paolo.carlini at oracle dot com
@ 2012-11-23 22:29 ` paolo.carlini at oracle dot com
2012-11-24 0:30 ` paolo.carlini at oracle dot com
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-23 22:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|major |normal
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (2 preceding siblings ...)
2012-11-23 22:29 ` paolo.carlini at oracle dot com
@ 2012-11-24 0:30 ` paolo.carlini at oracle dot com
2012-11-24 1:24 ` [Bug c++/55446] [4.7/4.8 Regression] " paolo.carlini at oracle dot com
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-24 0:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-24 00:30:40 UTC ---
build_new_1, called by build_new, returns error_mark_node.
This happens because something goes very badly wrong in the cp_build_binary_op
call around line 2712: essentially it computes 0 - 1!
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (3 preceding siblings ...)
2012-11-24 0:30 ` paolo.carlini at oracle dot com
@ 2012-11-24 1:24 ` paolo.carlini at oracle dot com
2012-11-24 1:53 ` paolo.carlini at oracle dot com
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-24 1:24 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.7.3
Summary|array new with size zero |[4.7/4.8 Regression] array
|vanishes from object code |new with size zero vanishes
| |from object code
--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-24 01:24:38 UTC ---
And it's a regression.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (4 preceding siblings ...)
2012-11-24 1:24 ` [Bug c++/55446] [4.7/4.8 Regression] " paolo.carlini at oracle dot com
@ 2012-11-24 1:53 ` paolo.carlini at oracle dot com
2012-11-24 1:54 ` paolo.carlini at oracle dot com
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-24 1:53 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-24 01:52:49 UTC ---
And it's mine because I caused it with the fix for PR45385 :(
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (5 preceding siblings ...)
2012-11-24 1:53 ` paolo.carlini at oracle dot com
@ 2012-11-24 1:54 ` paolo.carlini at oracle dot com
2012-11-24 9:28 ` harald at gigawatt dot nl
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-24 1:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |paolo.carlini at oracle dot
|gnu.org |com
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (6 preceding siblings ...)
2012-11-24 1:54 ` paolo.carlini at oracle dot com
@ 2012-11-24 9:28 ` harald at gigawatt dot nl
2012-11-24 9:33 ` paolo.carlini at oracle dot com
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: harald at gigawatt dot nl @ 2012-11-24 9:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Harald van Dijk <harald at gigawatt dot nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |harald at gigawatt dot nl
--- Comment #6 from Harald van Dijk <harald at gigawatt dot nl> 2012-11-24 09:28:44 UTC ---
A compile-only test for this can be
struct S { S(); };
void f(S *);
void g() {
S *s = new S[0];
f(s);
}
which causes a bogus warning:
test.cc: In function 'void g()':
test.cc:5:7: warning: 's' is used uninitialized in this function
[-Wuninitialized]
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (7 preceding siblings ...)
2012-11-24 9:28 ` harald at gigawatt dot nl
@ 2012-11-24 9:33 ` paolo.carlini at oracle dot com
2012-11-24 10:04 ` paolo.carlini at oracle dot com
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-24 9:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-24 09:32:48 UTC ---
Thanks. Relying on a warning seems a bit brittle, maybe a scan in the original
dump would be good enough in terms of compile only testcases, but I sent to the
mailing list a run time test.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (8 preceding siblings ...)
2012-11-24 9:33 ` paolo.carlini at oracle dot com
@ 2012-11-24 10:04 ` paolo.carlini at oracle dot com
2012-11-24 11:27 ` harald at gigawatt dot nl
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-24 10:04 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-24 10:04:27 UTC ---
Patch here:
http://gcc.gnu.org/ml/gcc-patches/2012-11/msg01991.html
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (9 preceding siblings ...)
2012-11-24 10:04 ` paolo.carlini at oracle dot com
@ 2012-11-24 11:27 ` harald at gigawatt dot nl
2012-11-24 23:46 ` paolo at gcc dot gnu.org
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: harald at gigawatt dot nl @ 2012-11-24 11:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
--- Comment #9 from Harald van Dijk <harald at gigawatt dot nl> 2012-11-24 11:27:25 UTC ---
Ah, okay, an alternative compile-only testcase that does not rely on particular
warnings would be
struct S { S(); };
__typeof__(new S[0]) s;
test.cc:2:23: error: invalid type in declaration before ';' token
but if you've already got a good testcase, sure, go with that :)
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (10 preceding siblings ...)
2012-11-24 11:27 ` harald at gigawatt dot nl
@ 2012-11-24 23:46 ` paolo at gcc dot gnu.org
2012-11-24 23:55 ` paolo at gcc dot gnu.org
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-11-24 23:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
--- Comment #10 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-11-24 23:45:49 UTC ---
Author: paolo
Date: Sat Nov 24 23:45:45 2012
New Revision: 193785
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193785
Log:
/cp
2012-11-24 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/55446
* init.c (build_vec_init): Do not early return error_mark_mode
when integer_all_onesp (maxindex).
/testsuite
2012-11-24 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/55446
* g++.dg/init/new41.C: New.
Added:
trunk/gcc/testsuite/g++.dg/init/new41.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/init.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (11 preceding siblings ...)
2012-11-24 23:46 ` paolo at gcc dot gnu.org
@ 2012-11-24 23:55 ` paolo at gcc dot gnu.org
2012-11-24 23:56 ` paolo.carlini at oracle dot com
2013-01-30 10:19 ` paolo.carlini at oracle dot com
14 siblings, 0 replies; 16+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-11-24 23:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
--- Comment #11 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-11-24 23:55:26 UTC ---
Author: paolo
Date: Sat Nov 24 23:55:22 2012
New Revision: 193786
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193786
Log:
/cp
2012-11-24 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/55446
* init.c (build_vec_init): Do not early return error_mark_mode
when integer_all_onesp (maxindex).
/testsuite
2012-11-24 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/55446
* g++.dg/init/new41.C: New.
Added:
branches/gcc-4_7-branch/gcc/testsuite/g++.dg/init/new41.C
Modified:
branches/gcc-4_7-branch/gcc/cp/ChangeLog
branches/gcc-4_7-branch/gcc/cp/init.c
branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (12 preceding siblings ...)
2012-11-24 23:55 ` paolo at gcc dot gnu.org
@ 2012-11-24 23:56 ` paolo.carlini at oracle dot com
2013-01-30 10:19 ` paolo.carlini at oracle dot com
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-24 23:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #12 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-24 23:56:20 UTC ---
Fixed.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/55446] [4.7/4.8 Regression] array new with size zero vanishes from object code
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
` (13 preceding siblings ...)
2012-11-24 23:56 ` paolo.carlini at oracle dot com
@ 2013-01-30 10:19 ` paolo.carlini at oracle dot com
14 siblings, 0 replies; 16+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-01-30 10:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55446
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |2013.bugzilla.gcc.gnu.org
| |at ingomueller dot net
--- Comment #13 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-01-30 10:19:05 UTC ---
*** Bug 56146 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2013-01-30 10:19 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-23 10:49 [Bug c++/55446] New: array new with size zero vanishes from object code jens.maurer at gmx dot net
2012-11-23 22:21 ` [Bug c++/55446] " daniel.kruegler at googlemail dot com
2012-11-23 22:28 ` paolo.carlini at oracle dot com
2012-11-23 22:29 ` paolo.carlini at oracle dot com
2012-11-24 0:30 ` paolo.carlini at oracle dot com
2012-11-24 1:24 ` [Bug c++/55446] [4.7/4.8 Regression] " paolo.carlini at oracle dot com
2012-11-24 1:53 ` paolo.carlini at oracle dot com
2012-11-24 1:54 ` paolo.carlini at oracle dot com
2012-11-24 9:28 ` harald at gigawatt dot nl
2012-11-24 9:33 ` paolo.carlini at oracle dot com
2012-11-24 10:04 ` paolo.carlini at oracle dot com
2012-11-24 11:27 ` harald at gigawatt dot nl
2012-11-24 23:46 ` paolo at gcc dot gnu.org
2012-11-24 23:55 ` paolo at gcc dot gnu.org
2012-11-24 23:56 ` paolo.carlini at oracle dot com
2013-01-30 10:19 ` paolo.carlini at oracle dot com
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).