Jul 24, 2014
04:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 24, 2014
04:02 PM
Hi All,
I went to build my XMC4500 project in DAVE 3.1.10 using -Os optimization, and found that the generated DBG002.c produces several of this compiler warning:
dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
This should probably be considered a defect, as DBG002 may not work correctly if the compiler is set to optimize.
The DBG002 version was 1.0.22
Thanks.
I went to build my XMC4500 project in DAVE 3.1.10 using -Os optimization, and found that the generated DBG002.c produces several of this compiler warning:
dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
This should probably be considered a defect, as DBG002 may not work correctly if the compiler is set to optimize.
The DBG002 version was 1.0.22
Thanks.
2 Replies
Not applicable
Jul 25, 2014
01:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 25, 2014
01:45 AM
Hi Kurt,
The reason for the error is:
The compiler assumes that a variable shall not be accessed with a pointer of another type.
CmdFromHost->Message is of type uint8_t (a character array/string).
However, the compiler is able to optimize the code better with the assumption especially when optimizing for size.
Changing uint32_t * to char * in the following snip of code will fix the warning.
DBG002_ChannelConfig.DynamicFilterMacroGroupID[0] = *((uint32_t*)(&(CmdFromHost->Message[1])));
In principle, typecasting the entire right-hand-side of the above code should not cause the program to fail.
Best regards,
Sophia
The reason for the error is:
The compiler assumes that a variable shall not be accessed with a pointer of another type.
CmdFromHost->Message is of type uint8_t (a character array/string).
However, the compiler is able to optimize the code better with the assumption especially when optimizing for size.
Changing uint32_t * to char * in the following snip of code will fix the warning.
DBG002_ChannelConfig.DynamicFilterMacroGroupID[0] = *((uint32_t*)(&(CmdFromHost->Message[1])));
In principle, typecasting the entire right-hand-side of the above code should not cause the program to fail.
Best regards,
Sophia
Jul 25, 2014
10:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jul 25, 2014
10:59 AM
Hi Sophia,
Thanks for your kind reply.
You are quite right about the changes to the code that can fix the warning. I can make modifications of DBG002.c to do this.
We have a policy where I am working to eliminate all the compiler warnings in our code base. I was hoping that a future version of DBG002 would address these gcc warnings, so that I may keep unmodified DAVE3 generated code in our project. I have many other DAVE3 apps in this project, and none of them (Except DBG002) exhibit additional compiler warnings when optimization is turned on.
Best Regards, and thank you all for such a good tool - DAVE3.
-Kurt
Thanks for your kind reply.
You are quite right about the changes to the code that can fix the warning. I can make modifications of DBG002.c to do this.
We have a policy where I am working to eliminate all the compiler warnings in our code base. I was hoping that a future version of DBG002 would address these gcc warnings, so that I may keep unmodified DAVE3 generated code in our project. I have many other DAVE3 apps in this project, and none of them (Except DBG002) exhibit additional compiler warnings when optimization is turned on.
Best Regards, and thank you all for such a good tool - DAVE3.
-Kurt