Summary: | Bogus stringop-overflow warning in gcc 12 | ||
---|---|---|---|
Product: | gcc | Reporter: | Mike Hommey <mh+gcc> |
Component: | tree-optimization | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | UNCONFIRMED --- | ||
Severity: | normal | CC: | sjames, sylvestre |
Priority: | P3 | Keywords: | diagnostic |
Version: | 12.2.0 | ||
Target Milestone: | --- | ||
See Also: | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109571 | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | ||
Bug Depends on: | |||
Bug Blocks: | 88443 |
Description
Mike Hommey
2022-11-15 09:08:31 UTC
PR 109571 is basically the same here just with a different warning (and upcasting instead of downcasting). In this case if we look at: void nsJSPrincipals::Destroy(JSPrincipals* jsprin) { nsJSPrincipals* nsjsprin = nsJSPrincipals::get(jsprin); if jsprin is null, then nsjsprin needs to be null too. And since nsjsprin == jsprin-8(bytes) (if it was a valid pointer), the C++ front-end needs to add a check for null. And then the optimizations come along and does jump threading. so one way of removing this is adding an assumption which can be done via one of the following: if (!jsprin) __builtin_unreachable(); [[assume(jsprin)]]; The first one is valid for GCC all the way back in 4.7 (and before). the second one is C++23 and was only added in GCC 13. |