Bug 90267 - [7.3 regression] wrong code generated wth -O2 as missing data dependence base on memory
Summary: [7.3 regression] wrong code generated wth -O2 as missing data dependence base...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 7.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-27 03:17 UTC by vfdff
Modified: 2019-04-28 01:44 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
a simple testcase (517 bytes, text/plain)
2019-04-27 03:17 UTC, vfdff
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vfdff 2019-04-27 03:17:05 UTC
Created attachment 46254 [details]
a simple testcase

test case attached, and we can see the code in line 42 clear the memory point with pstruDlTpcPara, so the value in the memory cross the line 42 is different.

 39             TpcFingerNum[TpcIdex][0] = *(UINT32*)(void*)pstruDlTpcPara;
 40             TpcFingerNum[TpcIdex][1] = pstruDlTpcPara->ucThreeSlotFngNum;
 41 
 42             *(volatile UINT32*)(void*)pstruDlTpcPara = 0;
 43 
 44             TpcFingerNum[TpcIdex][2] = *(UINT32*)(void*)pstruDlTpcPara;
 45             TpcFingerNum[TpcIdex][3] = pstruDlTpcPara->ucThreeSlotFngNum;


base on the gcc 7.3, in the dumpfile test.c.037t.fre1, we can see the value _6 get before the operator of clear the memory. So it miss the data dependence base on memory.
(Generated by cmd:../../GCC/gcc-730/binary/bin/gcc test.c -dAp -S -O2 -g3 -fdump-tree-all)

 37   _4 = MEM[(struct STRU_CCH_DLTPC_PARA *)&gastruDlTpcPara][_1].ucThreeSlotFngNum;
 38   _6 = (unsigned int) _4;
 39   TpcFingerNum[TpcIdex.0_2][1] = _6;
 40   MEM[(volatile UINT32 *)pstruDlTpcPara_20] ={v} 0;
 41   _8 = MEM[(UINT32 *)pstruDlTpcPara_20];
 42   TpcFingerNum[TpcIdex.0_2][2] = _8;
 43   TpcFingerNum[TpcIdex.0_2][3] = _6;
Comment 1 Drea Pinski 2019-04-27 03:23:30 UTC
You are violating C aliasing rules for sure.
Comment 2 Drea Pinski 2019-04-27 03:24:22 UTC
Use either -fno-strict-aliasing or change STRU_CCH_DLTPC_PARA to use an union and access it via that.
Comment 3 vfdff 2019-04-28 01:44:08 UTC
but it doesn't warning anything, even with  -Wstrict-aliasing -Wall.

Accord to http://blog.sina.com.cn/s/blog_74caf0ce010173up.html, We expect an warning similar the following infomation.

warning: dereferencing type-punned pointer will break strict-aliasing rules