diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-20 14:02:54 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-20 14:02:54 +0000 | 
| commit | d5ea6fa648f8835a44adfb322b788e615d77cb71 (patch) | |
| tree | 570aa90958a58b9d6a71fa8594ee0ad8d2a18f2c /contrib/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp | |
| parent | d9484dd61cc151c4f34c31e07f693fefa66316b5 (diff) | |
| parent | 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp')
| -rw-r--r-- | contrib/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp | 135 | 
1 files changed, 68 insertions, 67 deletions
diff --git a/contrib/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp b/contrib/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp index ed240f4ed292..c818d40c7771 100644 --- a/contrib/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/contrib/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -114,7 +114,7 @@ static void CheckUnreachable(Sema &S, AnalysisDeclContext &AC) {    //    // Note that this is also a performance optimization.  Analyzing    // headers many times can be expensive. -  if (!S.getSourceManager().isInMainFile(AC.getDecl()->getLocStart())) +  if (!S.getSourceManager().isInMainFile(AC.getDecl()->getBeginLoc()))      return;    UnreachableCodeHandler UC(S); @@ -252,7 +252,7 @@ static void checkRecursiveFunction(Sema &S, const FunctionDecl *FD,    // Emit diagnostic if a recursive function call is detected for all paths.    if (checkForRecursiveFunctionCall(FD, cfg)) -    S.Diag(Body->getLocStart(), diag::warn_infinite_recursive_function); +    S.Diag(Body->getBeginLoc(), diag::warn_infinite_recursive_function);  }  //===----------------------------------------------------------------------===// @@ -651,7 +651,7 @@ static void CheckFallThroughForBody(Sema &S, const Decl *D, const Stmt *Body,    // Short circuit for compilation speed.    if (CD.checkDiagnostics(Diags, ReturnsVoid, HasNoReturn))        return; -  SourceLocation LBrace = Body->getLocStart(), RBrace = Body->getLocEnd(); +  SourceLocation LBrace = Body->getBeginLoc(), RBrace = Body->getEndLoc();    auto EmitDiag = [&](SourceLocation Loc, unsigned DiagID) {      if (IsCoroutine)        S.Diag(Loc, DiagID) << FSI->CoroutinePromise->getType(); @@ -748,10 +748,10 @@ static bool SuggestInitializationFixit(Sema &S, const VarDecl *VD) {      return false;    // Don't suggest a fixit inside macros. -  if (VD->getLocEnd().isMacroID()) +  if (VD->getEndLoc().isMacroID())      return false; -  SourceLocation Loc = S.getLocForEndOfToken(VD->getLocEnd()); +  SourceLocation Loc = S.getLocForEndOfToken(VD->getEndLoc());    // Suggest possible initialization (if any).    std::string Init = S.getFixItZeroInitializerForType(VariableTy, Loc); @@ -771,19 +771,17 @@ static void CreateIfFixit(Sema &S, const Stmt *If, const Stmt *Then,    if (CondVal) {      // If condition is always true, remove all but the 'then'.      Fixit1 = FixItHint::CreateRemoval( -        CharSourceRange::getCharRange(If->getLocStart(), -                                      Then->getLocStart())); +        CharSourceRange::getCharRange(If->getBeginLoc(), Then->getBeginLoc()));      if (Else) { -      SourceLocation ElseKwLoc = S.getLocForEndOfToken(Then->getLocEnd()); -      Fixit2 = FixItHint::CreateRemoval( -          SourceRange(ElseKwLoc, Else->getLocEnd())); +      SourceLocation ElseKwLoc = S.getLocForEndOfToken(Then->getEndLoc()); +      Fixit2 = +          FixItHint::CreateRemoval(SourceRange(ElseKwLoc, Else->getEndLoc()));      }    } else {      // If condition is always false, remove all but the 'else'.      if (Else) -      Fixit1 = FixItHint::CreateRemoval( -          CharSourceRange::getCharRange(If->getLocStart(), -                                        Else->getLocStart())); +      Fixit1 = FixItHint::CreateRemoval(CharSourceRange::getCharRange( +          If->getBeginLoc(), Else->getBeginLoc()));      else        Fixit1 = FixItHint::CreateRemoval(If->getSourceRange());    } @@ -797,7 +795,7 @@ static void DiagUninitUse(Sema &S, const VarDecl *VD, const UninitUse &Use,    switch (Use.getKind()) {    case UninitUse::Always: -    S.Diag(Use.getUser()->getLocStart(), diag::warn_uninit_var) +    S.Diag(Use.getUser()->getBeginLoc(), diag::warn_uninit_var)          << VD->getDeclName() << IsCapturedByBlock          << Use.getUser()->getSourceRange();      return; @@ -809,8 +807,8 @@ static void DiagUninitUse(Sema &S, const VarDecl *VD, const UninitUse &Use,        << (Use.getKind() == UninitUse::AfterDecl ? 4 : 5)        << const_cast<DeclContext*>(VD->getLexicalDeclContext())        << VD->getSourceRange(); -    S.Diag(Use.getUser()->getLocStart(), diag::note_uninit_var_use) -      << IsCapturedByBlock << Use.getUser()->getSourceRange(); +    S.Diag(Use.getUser()->getBeginLoc(), diag::note_uninit_var_use) +        << IsCapturedByBlock << Use.getUser()->getSourceRange();      return;    case UninitUse::Maybe: @@ -880,8 +878,8 @@ static void DiagUninitUse(Sema &S, const VarDecl *VD, const UninitUse &Use,        if ((BO->getOpcode() == BO_LAnd && I->Output) ||            (BO->getOpcode() == BO_LOr && !I->Output))          // true && y -> y, false || y -> y. -        Fixit1 = FixItHint::CreateRemoval(SourceRange(BO->getLocStart(), -                                                      BO->getOperatorLoc())); +        Fixit1 = FixItHint::CreateRemoval( +            SourceRange(BO->getBeginLoc(), BO->getOperatorLoc()));        else          // false && y -> false, true || y -> true.          Fixit1 = FixItHint::CreateReplacement(BO->getSourceRange(), FixitStr); @@ -943,8 +941,8 @@ static void DiagUninitUse(Sema &S, const VarDecl *VD, const UninitUse &Use,      S.Diag(Range.getBegin(), diag::warn_sometimes_uninit_var)        << VD->getDeclName() << IsCapturedByBlock << DiagKind        << Str << I->Output << Range; -    S.Diag(User->getLocStart(), diag::note_uninit_var_use) -      << IsCapturedByBlock << User->getSourceRange(); +    S.Diag(User->getBeginLoc(), diag::note_uninit_var_use) +        << IsCapturedByBlock << User->getSourceRange();      if (RemoveDiagKind != -1)        S.Diag(Fixit1.RemoveRange.getBegin(), diag::note_uninit_fixit_remove_cond)          << RemoveDiagKind << Str << I->Output << Fixit1 << Fixit2; @@ -953,7 +951,7 @@ static void DiagUninitUse(Sema &S, const VarDecl *VD, const UninitUse &Use,    }    if (!Diagnosed) -    S.Diag(Use.getUser()->getLocStart(), diag::warn_maybe_uninit_var) +    S.Diag(Use.getUser()->getBeginLoc(), diag::warn_maybe_uninit_var)          << VD->getDeclName() << IsCapturedByBlock          << Use.getUser()->getSourceRange();  } @@ -985,9 +983,8 @@ static bool DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,        ContainsReference CR(S.Context, DRE);        CR.Visit(Initializer);        if (CR.doesContainReference()) { -        S.Diag(DRE->getLocStart(), -               diag::warn_uninit_self_reference_in_init) -          << VD->getDeclName() << VD->getLocation() << DRE->getSourceRange(); +        S.Diag(DRE->getBeginLoc(), diag::warn_uninit_self_reference_in_init) +            << VD->getDeclName() << VD->getLocation() << DRE->getSourceRange();          return true;        }      } @@ -996,9 +993,9 @@ static bool DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,    } else {      const BlockExpr *BE = cast<BlockExpr>(Use.getUser());      if (VD->getType()->isBlockPointerType() && !VD->hasAttr<BlocksAttr>()) -      S.Diag(BE->getLocStart(), +      S.Diag(BE->getBeginLoc(),               diag::warn_uninit_byref_blockvar_captured_by_block) -        << VD->getDeclName(); +          << VD->getDeclName();      else        DiagUninitUse(S, VD, Use, true);    } @@ -1007,8 +1004,8 @@ static bool DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,    // the initializer of that declaration & we didn't already suggest    // an initialization fixit.    if (!SuggestInitializationFixit(S, VD)) -    S.Diag(VD->getLocStart(), diag::note_var_declared_here) -      << VD->getDeclName(); +    S.Diag(VD->getBeginLoc(), diag::note_var_declared_here) +        << VD->getDeclName();    return true;  } @@ -1098,7 +1095,7 @@ namespace {                  // attribute in template instantiations as it may not be                  // unreachable in all instantiations of the template.                  if (!IsTemplateInstantiation) -                  S.Diag(AS->getLocStart(), +                  S.Diag(AS->getBeginLoc(),                           diag::warn_fallthrough_attr_unreachable);                  markFallthroughVisited(AS);                  ++AnnotatedCnt; @@ -1156,7 +1153,12 @@ namespace {      bool TraverseDecl(Decl *D) { return true; }      // We analyze lambda bodies separately. Skip them here. -    bool TraverseLambdaBody(LambdaExpr *LE) { return true; } +    bool TraverseLambdaExpr(LambdaExpr *LE) { +      // Traverse the captures, but not the body. +      for (const auto &C : zip(LE->captures(), LE->capture_inits())) +        TraverseLambdaCapture(LE, &std::get<0>(C), std::get<1>(C)); +      return true; +    }    private: @@ -1266,12 +1268,12 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC,                                        IsTemplateInstantiation))        continue; -    S.Diag(Label->getLocStart(), -        PerFunction ? diag::warn_unannotated_fallthrough_per_function -                    : diag::warn_unannotated_fallthrough); +    S.Diag(Label->getBeginLoc(), +           PerFunction ? diag::warn_unannotated_fallthrough_per_function +                       : diag::warn_unannotated_fallthrough);      if (!AnnotatedCnt) { -      SourceLocation L = Label->getLocStart(); +      SourceLocation L = Label->getBeginLoc();        if (L.isMacroID())          continue;        if (S.getLangOpts().CPlusPlus11) { @@ -1297,7 +1299,7 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC,    }    for (const auto *F : FM.getFallthroughStmts()) -    S.Diag(F->getLocStart(), diag::err_fallthrough_attr_invalid_placement); +    S.Diag(F->getBeginLoc(), diag::err_fallthrough_attr_invalid_placement);  }  static bool isInLoop(const ASTContext &Ctx, const ParentMap &PM, @@ -1312,11 +1314,10 @@ static bool isInLoop(const ASTContext &Ctx, const ParentMap &PM,      case Stmt::ObjCForCollectionStmtClass:        return true;      case Stmt::DoStmtClass: { -      const Expr *Cond = cast<DoStmt>(S)->getCond(); -      llvm::APSInt Val; -      if (!Cond->EvaluateAsInt(Val, Ctx)) +      Expr::EvalResult Result; +      if (!cast<DoStmt>(S)->getCond()->EvaluateAsInt(Result, Ctx))          return true; -      return Val.getBoolValue(); +      return Result.Val.getInt().getBoolValue();      }      default:        break; @@ -1394,11 +1395,11 @@ static void diagnoseRepeatedUseOfWeak(Sema &S,    // Sort by first use so that we emit the warnings in a deterministic order.    SourceManager &SM = S.getSourceManager(); -  llvm::sort(UsesByStmt.begin(), UsesByStmt.end(), +  llvm::sort(UsesByStmt,               [&SM](const StmtUsesPair &LHS, const StmtUsesPair &RHS) { -    return SM.isBeforeInTranslationUnit(LHS.first->getLocStart(), -                                        RHS.first->getLocStart()); -  }); +               return SM.isBeforeInTranslationUnit(LHS.first->getBeginLoc(), +                                                   RHS.first->getBeginLoc()); +             });    // Classify the current code body for better warning text.    // This enum should stay in sync with the cases in @@ -1467,15 +1468,15 @@ static void diagnoseRepeatedUseOfWeak(Sema &S,          continue;      // Show the first time the object was read. -    S.Diag(FirstRead->getLocStart(), DiagKind) -      << int(ObjectKind) << KeyProp << int(FunctionKind) -      << FirstRead->getSourceRange(); +    S.Diag(FirstRead->getBeginLoc(), DiagKind) +        << int(ObjectKind) << KeyProp << int(FunctionKind) +        << FirstRead->getSourceRange();      // Print all the other accesses as notes.      for (const auto &Use : Uses) {        if (Use.getUseExpr() == FirstRead)          continue; -      S.Diag(Use.getUseExpr()->getLocStart(), +      S.Diag(Use.getUseExpr()->getBeginLoc(),               diag::note_arc_weak_also_accessed_here)            << Use.getUseExpr()->getSourceRange();      } @@ -1538,7 +1539,7 @@ public:            // Prefer a more confident report over a less confident one.            if (a.getKind() != b.getKind())              return a.getKind() > b.getKind(); -          return a.getUser()->getLocStart() < b.getUser()->getLocStart(); +          return a.getUser()->getBeginLoc() < b.getUser()->getBeginLoc();          });          for (const auto &U : *vec) { @@ -1605,7 +1606,7 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {    OptionalNotes getNotes() const {      if (Verbose && CurrentFunction) { -      PartialDiagnosticAt FNote(CurrentFunction->getBody()->getLocStart(), +      PartialDiagnosticAt FNote(CurrentFunction->getBody()->getBeginLoc(),                                  S.PDiag(diag::note_thread_warning_in_fun)                                      << CurrentFunction);        return OptionalNotes(1, FNote); @@ -1616,7 +1617,7 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {    OptionalNotes getNotes(const PartialDiagnosticAt &Note) const {      OptionalNotes ONS(1, Note);      if (Verbose && CurrentFunction) { -      PartialDiagnosticAt FNote(CurrentFunction->getBody()->getLocStart(), +      PartialDiagnosticAt FNote(CurrentFunction->getBody()->getBeginLoc(),                                  S.PDiag(diag::note_thread_warning_in_fun)                                      << CurrentFunction);        ONS.push_back(std::move(FNote)); @@ -1630,7 +1631,7 @@ class ThreadSafetyReporter : public clang::threadSafety::ThreadSafetyHandler {      ONS.push_back(Note1);      ONS.push_back(Note2);      if (Verbose && CurrentFunction) { -      PartialDiagnosticAt FNote(CurrentFunction->getBody()->getLocStart(), +      PartialDiagnosticAt FNote(CurrentFunction->getBody()->getBeginLoc(),                                  S.PDiag(diag::note_thread_warning_in_fun)                                      << CurrentFunction);        ONS.push_back(std::move(FNote)); @@ -2068,11 +2069,11 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,    }    // Install the logical handler for -Wtautological-overlap-compare -  std::unique_ptr<LogicalErrorHandler> LEH; +  llvm::Optional<LogicalErrorHandler> LEH;    if (!Diags.isIgnored(diag::warn_tautological_overlap_comparison, -                       D->getLocStart())) { -    LEH.reset(new LogicalErrorHandler(S)); -    AC.getCFGBuildOptions().Observer = LEH.get(); +                       D->getBeginLoc())) { +    LEH.emplace(S); +    AC.getCFGBuildOptions().Observer = &*LEH;    }    // Emit delayed diagnostics. @@ -2145,11 +2146,11 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,    // Check for thread safety violations    if (P.enableThreadSafetyAnalysis) {      SourceLocation FL = AC.getDecl()->getLocation(); -    SourceLocation FEL = AC.getDecl()->getLocEnd(); +    SourceLocation FEL = AC.getDecl()->getEndLoc();      threadSafety::ThreadSafetyReporter Reporter(S, FL, FEL); -    if (!Diags.isIgnored(diag::warn_thread_safety_beta, D->getLocStart())) +    if (!Diags.isIgnored(diag::warn_thread_safety_beta, D->getBeginLoc()))        Reporter.setIssueBetaWarnings(true); -    if (!Diags.isIgnored(diag::warn_thread_safety_verbose, D->getLocStart())) +    if (!Diags.isIgnored(diag::warn_thread_safety_verbose, D->getBeginLoc()))        Reporter.setVerbose(true);      threadSafety::runThreadSafetyAnalysis(AC, Reporter, @@ -2164,9 +2165,9 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,      Analyzer.run(AC);    } -  if (!Diags.isIgnored(diag::warn_uninit_var, D->getLocStart()) || -      !Diags.isIgnored(diag::warn_sometimes_uninit_var, D->getLocStart()) || -      !Diags.isIgnored(diag::warn_maybe_uninit_var, D->getLocStart())) { +  if (!Diags.isIgnored(diag::warn_uninit_var, D->getBeginLoc()) || +      !Diags.isIgnored(diag::warn_sometimes_uninit_var, D->getBeginLoc()) || +      !Diags.isIgnored(diag::warn_maybe_uninit_var, D->getBeginLoc())) {      if (CFG *cfg = AC.getCFG()) {        UninitValsDiagReporter reporter(S);        UninitVariablesAnalysisStats stats; @@ -2189,29 +2190,29 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,    }    bool FallThroughDiagFull = -      !Diags.isIgnored(diag::warn_unannotated_fallthrough, D->getLocStart()); +      !Diags.isIgnored(diag::warn_unannotated_fallthrough, D->getBeginLoc());    bool FallThroughDiagPerFunction = !Diags.isIgnored( -      diag::warn_unannotated_fallthrough_per_function, D->getLocStart()); +      diag::warn_unannotated_fallthrough_per_function, D->getBeginLoc());    if (FallThroughDiagFull || FallThroughDiagPerFunction ||        fscope->HasFallthroughStmt) {      DiagnoseSwitchLabelsFallthrough(S, AC, !FallThroughDiagFull);    }    if (S.getLangOpts().ObjCWeak && -      !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, D->getLocStart())) +      !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, D->getBeginLoc()))      diagnoseRepeatedUseOfWeak(S, fscope, D, AC.getParentMap());    // Check for infinite self-recursion in functions    if (!Diags.isIgnored(diag::warn_infinite_recursive_function, -                       D->getLocStart())) { +                       D->getBeginLoc())) {      if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {        checkRecursiveFunction(S, FD, Body, AC);      }    }    // Check for throw out of non-throwing function. -  if (!Diags.isIgnored(diag::warn_throw_in_noexcept_func, D->getLocStart())) +  if (!Diags.isIgnored(diag::warn_throw_in_noexcept_func, D->getBeginLoc()))      if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))        if (S.getLangOpts().CPlusPlus && isNoexcept(FD))          checkThrowInNonThrowingFunc(S, FD, AC); @@ -2219,7 +2220,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,    // If none of the previous checks caused a CFG build, trigger one here    // for -Wtautological-overlap-compare    if (!Diags.isIgnored(diag::warn_tautological_overlap_comparison, -                               D->getLocStart())) { +                       D->getBeginLoc())) {      AC.getCFG();    }  | 
