This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR/63841: empty constructor doesn't zero-initialize
- From: Teresa Johnson <tejohnson at google dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Andrew Pinski <pinskia at gmail dot com>, Xinliang David Li <davidxl at google dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 13 Nov 2014 12:51:05 -0800
- Subject: Re: [PATCH] Fix PR/63841: empty constructor doesn't zero-initialize
- Authentication-results: sourceware.org; auth=none
- References: <CAAe5K+Vxtb=L3Jdkz5f-D16Y_j4Nd2FWRrF0Bmt1Gvu83YhHgg at mail dot gmail dot com> <CAAkRFZJPuSAmNLLWPkRZULUO9k6gmq1JFW+mH+4WZ1XE8kuEmA at mail dot gmail dot com> <CAAe5K+WC04TFEXph_e72A6vzDRiyiUHbx+JOVKhi7i7nP1N9Jw at mail dot gmail dot com> <CA+=Sn1=WJAznu2GTT4eXAQ7b0cK+ea-hV2GQhf9P9XT-fF8-pQ at mail dot gmail dot com> <CAAe5K+Ve=h0BJ_VTwGsugzur4jrxMjZxrqqQttTr-FSf9sGGgw at mail dot gmail dot com> <CA+=Sn1m+QKApfX051u1_SW5KNtQ0YhFWa-D94wO6hqEY93CE2A at mail dot gmail dot com> <CAAe5K+U9C1_WUE=OA-1goTvUFSTOTeHoAyzzcfMyoDjDywEzPw at mail dot gmail dot com> <20141113143617 dot GR5026 at tucnak dot redhat dot com> <CAAe5K+WJnQ+QMT6xH9co=MpjCTEoW-VkR0fBn5wdnw00UXSpuA at mail dot gmail dot com> <20141113151258 dot GT5026 at tucnak dot redhat dot com> <CAAe5K+UwWtbVP57Z5Qm052gxTv8S4y_SnzciDddLoMDJmnSfHQ at mail dot gmail dot com>
On Thu, Nov 13, 2014 at 7:39 AM, Teresa Johnson <tejohnson@google.com> wrote:
> On Thu, Nov 13, 2014 at 7:12 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>> And for release branches I'd really prefer tree-ssa-strlen.c change.
>
> Ok, I started testing the initializer_zerop change on the 4_9 branch,
> will also test the strlen fix and send that patch for review here when
> it completes.
Here is the more conservative patch for 4_9. Bootstrapped and tested
on x86_64-unknown-linux-gnu. Ok for gcc-4_9 branch?
Thanks,
Teresa
2014-11-13 Teresa Johnson <tejohnson@google.com>
gcc:
PR tree-optimization/63841
* tree-ssa-strlen.c (strlen_optimize_stmt): Ignore clobbers.
2014-11-13 Teresa Johnson <tejohnson@google.com>
gcc/testsuite:
PR tree-optimization/63841
* testsuite/g++.dg/tree-ssa/pr63841.C: New test.
Index: tree-ssa-strlen.c
===================================================================
--- tree-ssa-strlen.c (revision 217503)
+++ tree-ssa-strlen.c (working copy)
@@ -1856,7 +1856,7 @@ strlen_optimize_stmt (gimple_stmt_iterator *gsi)
break;
}
}
- else if (is_gimple_assign (stmt))
+ else if (is_gimple_assign (stmt) && !gimple_clobber_p (stmt))
{
tree lhs = gimple_assign_lhs (stmt);
Index: testsuite/g++.dg/tree-ssa/pr63841.C
===================================================================
--- testsuite/g++.dg/tree-ssa/pr63841.C (revision 0)
+++ testsuite/g++.dg/tree-ssa/pr63841.C (working copy)
@@ -0,0 +1,38 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+#include <cstdio>
+#include <string>
+
+std::string __attribute__ ((noinline)) comp_test_write() {
+ std::string data;
+
+ for (int i = 0; i < 2; ++i) {
+ char b = 1 >> (i * 8);
+ data.append(&b, 1);
+ }
+
+ return data;
+}
+
+std::string __attribute__ ((noinline)) comp_test_write_good() {
+ std::string data;
+
+ char b;
+ for (int i = 0; i < 2; ++i) {
+ b = 1 >> (i * 8);
+ data.append(&b, 1);
+ }
+
+ return data;
+}
+
+int main() {
+ std::string good = comp_test_write_good();
+ printf("expected: %hx\n", *(short*)good.c_str());
+
+ std::string bad = comp_test_write();
+ printf("got: %hx\n", *(short*)bad.c_str());
+
+ return good != bad;
+}
--
Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413