This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/66622] -Wsign-conversion does not take advantage of data flow analysis
- From: "miyuki at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 22 Jun 2015 10:28:00 +0000
- Subject: [Bug c/66622] -Wsign-conversion does not take advantage of data flow analysis
- Auto-submitted: auto-generated
- References: <bug-66622-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66622
Mikhail Maltsev <miyuki at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
CC| |miyuki at gcc dot gnu.org
Severity|normal |enhancement
--- Comment #1 from Mikhail Maltsev <miyuki at gcc dot gnu.org> ---
That is possible to implement, but not easy. The compiler transforms code in
such a way that lots of information is lost and it's hard to tell which code
was written by user, and which was generated by the compiler. Very few warnings
are actually emitted at the stage when data flow (use-def chains and value
ranges) is known (for example -Wmaybe-uninitialized, but it has rather frequent
false positives:
https://gcc.gnu.org/bugzilla/buglist.cgi?quicksearch=Wmaybe-uninitialized).
In your case the program will look like this at very early stage:
unsigned foo(int i)
{
unsigned result;
if (i < 0)
goto bb1;
else
goto bb2;
bb1:
result = 0;
return result;
bb2:
result = (unsigned)i;
return result;
}
Later it will be impossible to say, whether the conversion was introduced
explicitly by user, or by the compiler.
Clang also gives false positive. EDG does not warn for such conversions (even
unconditional).