Bug 86492

Summary: [8/9 Regression] store-merging wrong-code
Product: gcc Reporter: Jakub Jelinek <jakub>
Component: tree-optimizationAssignee: Jakub Jelinek <jakub>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 9.0   
Target Milestone: 8.2   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2018-07-11 00:00:00
Attachments: gcc9-pr86492.patch

Description Jakub Jelinek 2018-07-11 16:45:21 UTC
union U
{
  unsigned int r;
  struct
  {
    unsigned int a:12;
    unsigned int b:4;
    unsigned int c:16;
  } f;
};

__attribute__((noinline, noclone)) unsigned int
foo (unsigned int x)
{
  union U r;
  r.r = 0;
  r.f.c = x;
  r.f.b = 0xe;
  return r.r;
}

int
main ()
{
  volatile unsigned int x;
  x = 0x72;
  x = foo (x);
  union U r;
  r.r = x;
  if (r.f.a != 0 || r.f.b != 0xe || r.f.c != 0x72)
    __builtin_abort ();
  return 0;
}

is miscompiled by store-merging at -O2.
Comment 1 Jakub Jelinek 2018-07-11 16:52:05 UTC
Started with my r254948.
Comment 2 Jakub Jelinek 2018-07-11 17:18:45 UTC
Related to PR84503.
Comment 3 Jakub Jelinek 2018-07-11 17:55:24 UTC
Created attachment 44385 [details]
gcc9-pr86492.patch

Untested fix.
Comment 4 Jakub Jelinek 2018-07-12 07:40:05 UTC
Author: jakub
Date: Thu Jul 12 07:39:33 2018
New Revision: 262576

URL: https://gcc.gnu.org/viewcvs?rev=262576&root=gcc&view=rev
Log:
	PR tree-optimization/86492
	* gimple-ssa-store-merging.c
	(imm_store_chain_info::coalesce_immediate_stores): Call
	check_no_overlap even for the merge_overlapping case.  Formatting fix.

	* gcc.c-torture/execute/pr86492.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr86492.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-ssa-store-merging.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Jakub Jelinek 2018-07-12 07:46:36 UTC
Author: jakub
Date: Thu Jul 12 07:46:04 2018
New Revision: 262577

URL: https://gcc.gnu.org/viewcvs?rev=262577&root=gcc&view=rev
Log:
	PR tree-optimization/86492
	* gimple-ssa-store-merging.c
	(imm_store_chain_info::coalesce_immediate_stores): Call
	check_no_overlap even for the merge_overlapping case.

	* gcc.c-torture/execute/pr86492.c: New test.

Added:
    branches/gcc-8-branch/gcc/testsuite/gcc.c-torture/execute/pr86492.c
Modified:
    branches/gcc-8-branch/gcc/ChangeLog
    branches/gcc-8-branch/gcc/gimple-ssa-store-merging.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 6 Jakub Jelinek 2018-07-12 08:12:19 UTC
Fixed for 8.2+.
Comment 7 Umesh Kalappa 2018-07-13 07:05:49 UTC
Thank you Jakub for the quick fix and as stated the patch works for reported case.