r206232 - Fix a bad interaction between -Wtautological-overlap-compare and delayed

Nick Lewycky nlewycky at google.com
Mon Apr 14 18:08:04 PDT 2014


On 14 April 2014 17:57, Richard Trieu <rtrieu at google.com> wrote:

> Author: rtrieu
> Date: Mon Apr 14 19:57:50 2014
> New Revision: 206232
>
> URL: http://llvm.org/viewvc/llvm-project?rev=206232&view=rev
> Log:
> Fix a bad interaction between -Wtautological-overlap-compare and delayed
> diagnostics which caused delayed diagnostics on dead paths to be emitted.
>
> Modified:
>     cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
>     cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
>     cfe/trunk/test/Sema/warn-overlap.c
>
> Modified: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp?rev=206232&r1=206231&r2=206232&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp (original)
> +++ cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp Mon Apr 14 19:57:50 2014
> @@ -189,6 +189,9 @@ CFG *AnalysisDeclContext::getCFG() {
>
>      if (PM)
>        addParentsForSyntheticStmts(cfg.get(), *PM);
> +
> +    // The Obersver should only observe one build of the CFG.
>

Typo, "Obersver".


> +    getCFGBuildOptions().Observer = 0;
>    }
>    return cfg.get();
>  }
> @@ -205,6 +208,9 @@ CFG *AnalysisDeclContext::getUnoptimized
>
>      if (PM)
>        addParentsForSyntheticStmts(completeCFG.get(), *PM);
> +
> +    // The Obersver should only observe one build of the CFG.
>

Typo again!

Nick


> +    getCFGBuildOptions().Observer = 0;
>    }
>    return completeCFG.get();
>  }
>
> Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=206232&r1=206231&r2=206232&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
> +++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Mon Apr 14 19:57:50 2014
> @@ -1838,12 +1838,12 @@ AnalysisBasedWarnings::IssueWarnings(sem
>        .setAlwaysAdd(Stmt::AttributedStmtClass);
>    }
>
> +  // Install the logical handler for -Wtautological-overlap-compare
> +  std::unique_ptr<LogicalErrorHandler> LEH;
>    if (Diags.getDiagnosticLevel(diag::warn_tautological_overlap_comparison,
>                                 D->getLocStart())) {
> -    LogicalErrorHandler LEH(S);
> -    AC.getCFGBuildOptions().Observer = &LEH;
> -    AC.getCFG();
> -    AC.getCFGBuildOptions().Observer = 0;
> +    LEH.reset(new LogicalErrorHandler(S));
> +    AC.getCFGBuildOptions().Observer = LEH.get();
>    }
>
>    // Emit delayed diagnostics.
> @@ -1991,6 +1991,13 @@ AnalysisBasedWarnings::IssueWarnings(sem
>      }
>    }
>
> +  // If none of the previous checks caused a CFG build, trigger one here
> +  // for -Wtautological-overlap-compare
> +  if (Diags.getDiagnosticLevel(diag::warn_tautological_overlap_comparison,
> +                               D->getLocStart())) {
> +    AC.getCFG();
> +  }
> +
>    // Collect statistics about the CFG if it was built.
>    if (S.CollectStats && AC.isCFGBuilt()) {
>      ++NumFunctionsAnalyzed;
>
> Modified: cfe/trunk/test/Sema/warn-overlap.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-overlap.c?rev=206232&r1=206231&r2=206232&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Sema/warn-overlap.c (original)
> +++ cfe/trunk/test/Sema/warn-overlap.c Mon Apr 14 19:57:50 2014
> @@ -56,3 +56,9 @@ void f(int x) {
>    if (x == (mydefine + 1) && x > 3) { }
>  }
>
> +// Don't generate a warning here.
> +void array_out_of_bounds() {
> +  int x;
> +  int buffer[4];
> +  x = (-7 > 0) ? (buffer[-7]) : 0;
> +}
>
>
> _______________________________________________
> 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/20140414/95d3baaa/attachment.html>


More information about the cfe-commits mailing list