diff options
Diffstat (limited to 'lib/Sema/AnalysisBasedWarnings.cpp')
-rw-r--r-- | lib/Sema/AnalysisBasedWarnings.cpp | 101 |
1 files changed, 49 insertions, 52 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index 15a0adb3cd..73787610b5 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/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->getLocEnd(); auto EmitDiag = [&](SourceLocation Loc, unsigned DiagID) { if (IsCoroutine) S.Diag(Loc, DiagID) << FSI->CoroutinePromise->getType(); @@ -771,8 +771,7 @@ 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( @@ -781,9 +780,8 @@ static void CreateIfFixit(Sema &S, const Stmt *If, const Stmt *Then, } 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; @@ -1266,12 +1263,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 +1294,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, @@ -1396,9 +1393,9 @@ static void diagnoseRepeatedUseOfWeak(Sema &S, SourceManager &SM = S.getSourceManager(); llvm::sort(UsesByStmt.begin(), UsesByStmt.end(), [&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 +1464,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 +1535,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 +1602,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 +1613,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 +1627,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)); @@ -2070,7 +2067,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, // Install the logical handler for -Wtautological-overlap-compare llvm::Optional<LogicalErrorHandler> LEH; if (!Diags.isIgnored(diag::warn_tautological_overlap_comparison, - D->getLocStart())) { + D->getBeginLoc())) { LEH.emplace(S); AC.getCFGBuildOptions().Observer = &*LEH; } @@ -2147,9 +2144,9 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, SourceLocation FL = AC.getDecl()->getLocation(); SourceLocation FEL = AC.getDecl()->getLocEnd(); 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 +2161,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 +2186,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 +2216,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(); } |