[PATCH] Add new warning to Clang to detect when all code paths in a function has a call back to the function.

Richard Trieu rtrieu at google.com
Tue Oct 8 20:13:18 PDT 2013


Implement a warning to detect when a function will call itself recursively on every code path.  If a program ever calls such a function, the function will attempt to call itself until it runs out of stack space.

This warning searches the CFG to determine if every codepath results in a self call.  In addition to the test for this warning, several other tests needed to be fixed, and a pragma to prevent this warning where Clang really wants a stack overflow.

Testing with this warning has already caught several buggy functions.  Common mistakes include: incorrect namespaces, wrapper classes not forwarding calls properly, similarly named member function and data member, and failing to call an overload of the same function.  When run outside of template instantiations, all true positives.  In template instantiations, only 25% true positive.  Therefore, this warning is disabled in template instantiations.  An example of such a false positive is in the test cases.

http://llvm-reviews.chandlerc.com/D1864

Files:
  test/Analysis/inlining/test-always-inline-size-option.c
  test/Analysis/misc-ps-region-store.cpp
  test/Analysis/cxx11-crashes.cpp
  test/FixIt/typo.m
  test/FixIt/fixit.c
  test/Sema/unused-expr-system-header.c
  test/Sema/warn-unused-function.c
  test/Sema/attr-deprecated.c
  test/Parser/cxx-using-declaration.cpp
  test/Parser/expressions.c
  test/CodeGen/functions.c
  test/SemaCXX/statements.cpp
  test/SemaCXX/warn-bool-conversion.cpp
  test/SemaCXX/warn-infinite-recursion.cpp
  test/SemaCXX/MicrosoftCompatibility.cpp
  test/Lexer/gnu-flags.c
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/DiagnosticGroups.td
  lib/Sema/AnalysisBasedWarnings.cpp
  lib/Lex/Pragma.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1864.1.patch
Type: text/x-patch
Size: 15152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131008/70fceda3/attachment.bin>


More information about the cfe-commits mailing list