On 9 October 2010 05:22, Geert Bosch <bo...@adacore.com> wrote: > > On Oct 8, 2010, at 18:18, Manuel López-Ibáñez wrote: > >> It is possible to do it quite fast. Clang implements all warnings, >> including Wuninitialized, in the FE using fast analysis and they claim >> very low false positives. >> However, there are various reasons why it has not been attempted in GCC: >> >> * GCC is too slow already at -O0, slowing it down further would not be >> acceptable. So you need a really high-performing implementation. > > The Ada front end has very extensive warnings. I don't think > they really contribute measurably to performance. > We don't try to construct call graphs to determine > wether the array reference will be executed or not. > If the line appears in your program, it will cause an > error if executed, so we will warn: either you wrote > dead code, or wrong code.
This may be acceptable for Ada, but it seems not acceptable for C/C++. In fact, warnings have been removed/tweaked because they broke GCC build for such code. In any case, it is possible to implement a basic flow-sensitive CFG in the FE: http://clang.llvm.org/docs/InternalsManual.html#CFG but it is not clear whether such a thing would be accepted in GCC. My intention by answering Gary is to point out that if he is thinking about working on this problem, he should consider building a cheap FE-specific CFG, rather than try to share the current infrastructure between FE and middle-end. I would like to see this implemented, so I'd rather have a good-enough implementation committed to GCC than a near-perfect solution that is never completed or accepted in trunk. > To avoid false positives in inlined code, code instantiated > from templates and the like, we have a notion of code that > comes from source or not. For many warnings, we will only > post the warning if the code comes from source, that is: > is not generated by the compiler as part of the compilation > process. Good for Ada! Unfortunately, the C/C++ FEs do not have such infrastructure. There is some promising work for macros http://gcc.gnu.org/PR7263 but it is far from ready and it would still require the diagnostics machinery to start using it, which is even further away. I hope Dodji manages to find some time to finish it, because the possibilities are impressive. See "Automatic Macro Expansion" here: http://clang.llvm.org/diagnostics.html I think for templates it is currently feasible to do this for each warning, but there is no general or straight-forward way. See the often-reported bug: http://gcc.gnu.org/PR11856 A counter-example: http://gcc.gnu.org/PR43167 And (for once!!!) Clang doesn't get this right this either: http://llvm.org/PR6418 I think it is generally acknowledged that Ada has the best diagnostics among GCC FEs. Too bad Adacore customers do not use C/C++ ;-) Cheers, Manuel.