* [Bug c++/55513] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
@ 2012-11-28 10:05 ` gnobal at hotmail dot com
2012-11-28 10:19 ` [Bug c++/55513] [4.7 Regression] " redi at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: gnobal at hotmail dot com @ 2012-11-28 10:05 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
--- Comment #1 from Amit Schreiber <gnobal at hotmail dot com> 2012-11-28 10:05:16 UTC ---
Created attachment 28819
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28819
The program
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
2012-11-28 10:05 ` [Bug c++/55513] " gnobal at hotmail dot com
@ 2012-11-28 10:19 ` redi at gcc dot gnu.org
2012-11-28 12:35 ` rguenth at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-28 10:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-11-28
Known to work| |4.6.3, 4.8.0
Summary|Incorrect snprintf folding |[4.7 Regression] Incorrect
|when building with |snprintf folding when
|-std=c++0x |building with -std=c++0x
Ever Confirmed|0 |1
Known to fail| |4.7.1, 4.7.2
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-28 10:18:57 UTC ---
Confirmed. -fno-builtin fixes it too.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
2012-11-28 10:05 ` [Bug c++/55513] " gnobal at hotmail dot com
2012-11-28 10:19 ` [Bug c++/55513] [4.7 Regression] " redi at gcc dot gnu.org
@ 2012-11-28 12:35 ` rguenth at gcc dot gnu.org
2012-11-28 14:26 ` [Bug c++/55513] [4.7/4.8 " jakub at gcc dot gnu.org
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-11-28 12:35 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.7.3
Known to fail| |4.7.0
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> 2012-11-28 12:35:16 UTC ---
Seems to be simply folded away.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (2 preceding siblings ...)
2012-11-28 12:35 ` rguenth at gcc dot gnu.org
@ 2012-11-28 14:26 ` jakub at gcc dot gnu.org
2012-11-28 15:15 ` jakub at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-11-28 14:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
Summary|[4.7 Regression] Incorrect |[4.7/4.8 Regression]
|snprintf folding when |Incorrect snprintf folding
|building with -std=c++0x |when building with
| |-std=c++0x
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-28 14:25:44 UTC ---
With const int strLength = snprintf(str, 10, "Hello"); instead it fails also on
the trunk, with sizeof(str) it has been "fixed" by my
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192141
changes.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (3 preceding siblings ...)
2012-11-28 14:26 ` [Bug c++/55513] [4.7/4.8 " jakub at gcc dot gnu.org
@ 2012-11-28 15:15 ` jakub at gcc dot gnu.org
2012-11-28 15:51 ` jakub at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-11-28 15:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-28 15:15:11 UTC ---
In cp_parser_constant_expression when we call cp_parser_assignment_expression
on the initializer, it returns
((char *) __builtin_memcpy ((char *) &str, (const char *) "Hello", 6);, 5)
As this is C++11, we call potential_rvalue_constant_expression which returns
true (the call in the COMPOUND_EXPR is builtin, and all its arguments are
pontential_rvalue_constant_expression arguments). I bet somewhere later on we
see that it is const and ignore the TREE_SIDE_EFFECTS initializer.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (4 preceding siblings ...)
2012-11-28 15:15 ` jakub at gcc dot gnu.org
@ 2012-11-28 15:51 ` jakub at gcc dot gnu.org
2012-12-05 17:10 ` aldyh at gcc dot gnu.org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-11-28 15:51 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-28 15:51:21 UTC ---
Reduced testcase:
void
f1 ()
{
char s[10];
const int t = __builtin_snprintf (s, 10, "Hello");
__builtin_printf ("%d %s\n", t, s);
}
void
f2 ()
{
char s[10];
const int t = (__builtin_memcpy (s, "Hello", 6), 5);
__builtin_printf ("%d %s\n", t, s);
}
int
main ()
{
f1 ();
f2 ();
}
Even f2 fails to call memcpy, so it isn't related to folding the snprintf into
what it folds to, but about handling COMPOUND_EXPRs with side-effects on the
LHS where the only side-effects are builtin calls. If the LHS of the
COMPOUND_EXPR is a non-builtin, potential_rvalue_constant_expression returns
false and it is handled correctly, but even if it is say __builtin_exit (0) or
similar, it is optimized away.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (5 preceding siblings ...)
2012-11-28 15:51 ` jakub at gcc dot gnu.org
@ 2012-12-05 17:10 ` aldyh at gcc dot gnu.org
2012-12-06 16:16 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: aldyh at gcc dot gnu.org @ 2012-12-05 17:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
Aldy Hernandez <aldyh at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |aldyh at gcc dot gnu.org
AssignedTo|unassigned at gcc dot |aldyh at gcc dot gnu.org
|gnu.org |
--- Comment #7 from Aldy Hernandez <aldyh at gcc dot gnu.org> 2012-12-05 17:08:48 UTC ---
I'll take a look.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (6 preceding siblings ...)
2012-12-05 17:10 ` aldyh at gcc dot gnu.org
@ 2012-12-06 16:16 ` rguenth at gcc dot gnu.org
2012-12-06 21:06 ` aldyh at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-12-06 16:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
Known to work|4.8.0 |
Known to fail| |4.8.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (7 preceding siblings ...)
2012-12-06 16:16 ` rguenth at gcc dot gnu.org
@ 2012-12-06 21:06 ` aldyh at gcc dot gnu.org
2012-12-07 5:21 ` jason at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: aldyh at gcc dot gnu.org @ 2012-12-06 21:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
--- Comment #8 from Aldy Hernandez <aldyh at gcc dot gnu.org> 2012-12-06 21:06:29 UTC ---
After Jason's patch here (trunk@177066):
PR c++/49813
* semantics.c (potential_constant_expression_1): Allow any builtin.
(morally_constexpr_builtin_function_p): Remove.
It seems we return true for any built-in in potential_constant_expression_1.
This means that check_initializer->store_init_value->maybe_constant_init will
chop off the built-in side of a COMPOUND_EXPR when setting a DECL_INITIAL,
transforming:
(COMPOUND_EXPR (CALL_EXPR built-in) INTEGER_CST)
into
INTEGER_CST
Since potential_constant_expression_1 returns true for any built-in, we end up
removing even a __builtin_exit from code like this:
const int t = (__builtin_exit(0), 777);
Jason, is this by design? Should we not limit the conditional here further?:
/* Allow any built-in function; if the expansion
isn't constant, we'll deal with that then. */
&& !is_builtin_fn (fun))
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (8 preceding siblings ...)
2012-12-06 21:06 ` aldyh at gcc dot gnu.org
@ 2012-12-07 5:21 ` jason at gcc dot gnu.org
2012-12-08 3:13 ` aldyh at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jason at gcc dot gnu.org @ 2012-12-07 5:21 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> 2012-12-07 05:21:01 UTC ---
(In reply to comment #8)
> /* Allow any built-in function; if the expansion
> isn't constant, we'll deal with that then. */
> && !is_builtin_fn (fun))
The problem seems to be in the dealing with it "then";
cxx_eval_builtin_function_call needs to actually check whether folding the call
produces a constant or not.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (9 preceding siblings ...)
2012-12-07 5:21 ` jason at gcc dot gnu.org
@ 2012-12-08 3:13 ` aldyh at gcc dot gnu.org
2012-12-08 3:14 ` aldyh at gcc dot gnu.org
2012-12-12 9:57 ` pluto at agmk dot net
12 siblings, 0 replies; 14+ messages in thread
From: aldyh at gcc dot gnu.org @ 2012-12-08 3:13 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
--- Comment #10 from Aldy Hernandez <aldyh at gcc dot gnu.org> 2012-12-08 01:20:33 UTC ---
Author: aldyh
Date: Sat Dec 8 01:19:13 2012
New Revision: 194316
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194316
Log:
PR c++/55513
* semantics.c (cxx_eval_builtin_function_call): Set non_constant_p
after folding.
Added:
trunk/gcc/testsuite/g++.dg/pr55513.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/semantics.c
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (10 preceding siblings ...)
2012-12-08 3:13 ` aldyh at gcc dot gnu.org
@ 2012-12-08 3:14 ` aldyh at gcc dot gnu.org
2012-12-12 9:57 ` pluto at agmk dot net
12 siblings, 0 replies; 14+ messages in thread
From: aldyh at gcc dot gnu.org @ 2012-12-08 3:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
Aldy Hernandez <aldyh at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
--- Comment #11 from Aldy Hernandez <aldyh at gcc dot gnu.org> 2012-12-08 01:24:30 UTC ---
Fixed in trunk.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c++/55513] [4.7/4.8 Regression] Incorrect snprintf folding when building with -std=c++0x
2012-11-28 10:04 [Bug c++/55513] New: Incorrect snprintf folding when building with -std=c++0x gnobal at hotmail dot com
` (11 preceding siblings ...)
2012-12-08 3:14 ` aldyh at gcc dot gnu.org
@ 2012-12-12 9:57 ` pluto at agmk dot net
12 siblings, 0 replies; 14+ messages in thread
From: pluto at agmk dot net @ 2012-12-12 9:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55513
--- Comment #12 from Pawel Sikora <pluto at agmk dot net> 2012-12-12 09:57:32 UTC ---
(In reply to comment #11)
> Fixed in trunk.
no backport to 4.7 branch?
^ permalink raw reply [flat|nested] 14+ messages in thread