r175425 - Disable dead stores checker for template instantations. Fixes <rdar://problem/13213575>.

David Blaikie dblaikie at gmail.com
Sun Feb 17 23:25:59 PST 2013


On Sun, Feb 17, 2013 at 11:18 PM, Ted Kremenek <kremenek at apple.com> wrote:

> Author: kremenek
> Date: Mon Feb 18 01:18:28 2013
> New Revision: 175425
>
> URL: http://llvm.org/viewvc/llvm-project?rev=175425&view=rev
> Log:
> Disable dead stores checker for template instantations.  Fixes
> <rdar://problem/13213575>.
>
> Modified:
>     cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
>     cfe/trunk/test/Analysis/dead-stores.cpp
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp?rev=175425&r1=175424&r2=175425&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp Mon Feb 18
> 01:18:28 2013
> @@ -419,6 +419,15 @@ class DeadStoresChecker : public Checker
>  public:
>    void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
>                          BugReporter &BR) const {
> +
> +    // Don't do anything for template instantiations.
> +    // Proving that code in a template instantiation is "dead"
> +    // means proving that it is dead in all instantiations.
> +    // This same problem exists with -Wunreachable-code.
>

I believe last time we spoke about this we agreed that correctness can be
attained by examining template patterns not specializations for unreachable
code. Your concern was one of performance that I never did get around to
providing numbers for (your concern was that examining all template
patterns might be too expensive) - I'm not sure if you have the same
concern for the Static Analyzer in this regard, or an easier way to verify
the perf impact to thins you care about here.

(or perhaps the Static Analyzer already gets this right by examining
template patterns elsewhere?)


> +    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
> +      if (FD->isTemplateInstantiation())
> +        return;
> +
>      if (LiveVariables *L = mgr.getAnalysis<LiveVariables>(D)) {
>        CFG &cfg = *mgr.getCFG(D);
>        AnalysisDeclContext *AC = mgr.getAnalysisDeclContext(D);
>
> Modified: cfe/trunk/test/Analysis/dead-stores.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.cpp?rev=175425&r1=175424&r2=175425&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Analysis/dead-stores.cpp (original)
> +++ cfe/trunk/test/Analysis/dead-stores.cpp Mon Feb 18 01:18:28 2013
> @@ -156,3 +156,21 @@ void testCXX11Using() {
>    Int value;
>    value = 1; // expected-warning {{never read}}
>  }
> +
>
> +//===----------------------------------------------------------------------===//
> +// Dead stores in template instantiations (do not warn).
>
> +//===----------------------------------------------------------------------===//
> +
> +template <bool f> int radar13213575_testit(int i) {
> +  int x = 5+i; // warning: Value stored to 'x' during its initialization
> is never read
> +  int y = 7;
> +  if (f)
> +    return x;
> +  else
> +    return y;
> +}
> +
> +int radar_13213575() {
> +  return radar13213575_testit<true>(5) + radar13213575_testit<false>(3);
> +}
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130217/1396d953/attachment.html>


More information about the cfe-commits mailing list