[cfe-commits] r109487 - in /cfe/trunk: lib/Checker/UnreachableCodeChecker.cpp test/Analysis/unreachable-code-path.c
Ted Kremenek
kremenek at apple.com
Mon Jul 26 23:13:13 PDT 2010
Thanks Jordy!
On Jul 26, 2010, at 8:39 PM, Jordy Rose wrote:
> Author: jrose
> Date: Mon Jul 26 22:39:53 2010
> New Revision: 109487
>
> URL: http://llvm.org/viewvc/llvm-project?rev=109487&view=rev
> Log:
> Don't warn about unreachable code if the block starts with __builtin_unreachable().
>
> The next step is to warn if a block labeled unreachable is, in fact, reachable. Somewhat related to PR810.
>
> Modified:
> cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp
> cfe/trunk/test/Analysis/unreachable-code-path.c
>
> Modified: cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp?rev=109487&r1=109486&r2=109487&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp (original)
> +++ cfe/trunk/lib/Checker/UnreachableCodeChecker.cpp Mon Jul 26 22:39:53 2010
> @@ -10,7 +10,7 @@
> // path-sensitive analysis. We mark any path visited, and then walk the CFG as a
> // post-analysis to determine what was never visited.
> //
> -// A similar flow-sensitive only check exists in Analysis/UnreachableCode.cpp
> +// A similar flow-sensitive only check exists in Analysis/ReachableCode.cpp
> //===----------------------------------------------------------------------===//
>
> #include "clang/Checker/PathSensitive/CheckerVisitor.h"
> @@ -19,6 +19,7 @@
> #include "clang/Checker/BugReporter/BugReporter.h"
> #include "GRExprEngineExperimentalChecks.h"
> #include "clang/AST/StmtCXX.h"
> +#include "clang/Basic/Builtins.h"
> #include "llvm/ADT/SmallPtrSet.h"
>
> // The number of CFGBlock pointers we want to reserve memory for. This is used
> @@ -79,6 +80,8 @@
> if (!C)
> return;
>
> + ASTContext &Ctx = B.getContext();
> +
> // Find CFGBlocks that were not covered by any node
> for (CFG::const_iterator I = C->begin(); I != C->end(); ++I) {
> const CFGBlock *CB = *I;
> @@ -96,6 +99,18 @@
> if (S.getBegin().isMacroID() || S.getEnd().isMacroID() || S.isInvalid()
> || SL.isInvalid())
> continue;
> +
> + // Special case for __builtin_unreachable.
> + // FIXME: This should be extended to include other unreachable markers,
> + // such as llvm_unreachable.
> + if (!CB->empty()) {
> + const Stmt *First = CB->front();
> + if (const CallExpr *CE = dyn_cast<CallExpr>(First)) {
> + if (CE->isBuiltinCall(Ctx) == Builtin::BI__builtin_unreachable)
> + continue;
> + }
> + }
> +
> B.EmitBasicReport("Unreachable code", "This statement is never executed",
> SL, S);
> }
>
> Modified: cfe/trunk/test/Analysis/unreachable-code-path.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/unreachable-code-path.c?rev=109487&r1=109486&r2=109487&view=diff
> ==============================================================================
> --- cfe/trunk/test/Analysis/unreachable-code-path.c (original)
> +++ cfe/trunk/test/Analysis/unreachable-code-path.c Mon Jul 26 22:39:53 2010
> @@ -53,3 +53,9 @@
> }
> }
>
> +void test6(const char *c) {
> + if (c) return;
> + if (!c) return;
> + __builtin_unreachable(); // no-warning
> +}
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list