OLD | NEW |
1 //=- AnalysisBasedWarnings.cpp - Sema warnings based on libAnalysis -*- C++ -*-=
// | 1 //=- AnalysisBasedWarnings.cpp - Sema warnings based on libAnalysis -*- C++ -*-=
// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file defines analysis_warnings::[Policy,Executor]. | 10 // This file defines analysis_warnings::[Policy,Executor]. |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 // Although this call will be slow, this is only called when outputting | 641 // Although this call will be slow, this is only called when outputting |
642 // multiple warnings. | 642 // multiple warnings. |
643 return S.getSourceManager().isBeforeInTranslationUnit(left.first, | 643 return S.getSourceManager().isBeforeInTranslationUnit(left.first, |
644 right.first); | 644 right.first); |
645 } | 645 } |
646 }; | 646 }; |
647 | 647 |
648 class ThreadSafetyReporter : public clang::thread_safety::ThreadSafetyHandler { | 648 class ThreadSafetyReporter : public clang::thread_safety::ThreadSafetyHandler { |
649 Sema &S; | 649 Sema &S; |
650 DiagList Warnings; | 650 DiagList Warnings; |
| 651 SourceLocation FunLocation; |
651 | 652 |
652 // Helper functions | 653 // Helper functions |
653 void warnLockMismatch(unsigned DiagID, Name LockName, SourceLocation Loc) { | 654 void warnLockMismatch(unsigned DiagID, Name LockName, SourceLocation Loc) { |
| 655 // Gracefully handle rare cases when the analysis can't get a more |
| 656 // precise source location. |
| 657 if (!Loc.isValid()) |
| 658 Loc = FunLocation; |
654 PartialDiagnostic Warning = S.PDiag(DiagID) << LockName; | 659 PartialDiagnostic Warning = S.PDiag(DiagID) << LockName; |
655 Warnings.push_back(DelayedDiag(Loc, Warning)); | 660 Warnings.push_back(DelayedDiag(Loc, Warning)); |
656 } | 661 } |
657 | 662 |
658 public: | 663 public: |
659 ThreadSafetyReporter(Sema &S) : S(S) {} | 664 ThreadSafetyReporter(Sema &S, SourceLocation FL) |
| 665 : S(S), FunLocation(FL) {} |
660 | 666 |
661 /// \brief Emit all buffered diagnostics in order of sourcelocation. | 667 /// \brief Emit all buffered diagnostics in order of sourcelocation. |
662 /// We need to output diagnostics produced while iterating through | 668 /// We need to output diagnostics produced while iterating through |
663 /// the lockset in deterministic order, so this function orders diagnostics | 669 /// the lockset in deterministic order, so this function orders diagnostics |
664 /// and outputs them. | 670 /// and outputs them. |
665 void emitDiagnostics() { | 671 void emitDiagnostics() { |
666 SortDiagBySourceLocation SortDiagBySL(S); | 672 SortDiagBySourceLocation SortDiagBySL(S); |
667 sort(Warnings.begin(), Warnings.end(), SortDiagBySL); | 673 sort(Warnings.begin(), Warnings.end(), SortDiagBySL); |
668 for (DiagList::iterator I = Warnings.begin(), E = Warnings.end(); | 674 for (DiagList::iterator I = Warnings.begin(), E = Warnings.end(); |
669 I != E; ++I) | 675 I != E; ++I) |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 : CheckFallThroughDiagnostics::MakeForFunction(D)); | 912 : CheckFallThroughDiagnostics::MakeForFunction(D)); |
907 CheckFallThroughForBody(S, D, Body, blkExpr, CD, AC); | 913 CheckFallThroughForBody(S, D, Body, blkExpr, CD, AC); |
908 } | 914 } |
909 | 915 |
910 // Warning: check for unreachable code | 916 // Warning: check for unreachable code |
911 if (P.enableCheckUnreachable) | 917 if (P.enableCheckUnreachable) |
912 CheckUnreachable(S, AC); | 918 CheckUnreachable(S, AC); |
913 | 919 |
914 // Check for thread safety violations | 920 // Check for thread safety violations |
915 if (P.enableThreadSafetyAnalysis) { | 921 if (P.enableThreadSafetyAnalysis) { |
916 thread_safety::ThreadSafetyReporter Reporter(S); | 922 SourceLocation FL = AC.getDecl()->getLocation(); |
| 923 thread_safety::ThreadSafetyReporter Reporter(S, FL); |
917 thread_safety::runThreadSafetyAnalysis(AC, Reporter); | 924 thread_safety::runThreadSafetyAnalysis(AC, Reporter); |
918 Reporter.emitDiagnostics(); | 925 Reporter.emitDiagnostics(); |
919 } | 926 } |
920 | 927 |
921 if (Diags.getDiagnosticLevel(diag::warn_uninit_var, D->getLocStart()) | 928 if (Diags.getDiagnosticLevel(diag::warn_uninit_var, D->getLocStart()) |
922 != DiagnosticsEngine::Ignored || | 929 != DiagnosticsEngine::Ignored || |
923 Diags.getDiagnosticLevel(diag::warn_maybe_uninit_var, D->getLocStart()) | 930 Diags.getDiagnosticLevel(diag::warn_maybe_uninit_var, D->getLocStart()) |
924 != DiagnosticsEngine::Ignored) { | 931 != DiagnosticsEngine::Ignored) { |
925 if (CFG *cfg = AC.getCFG()) { | 932 if (CFG *cfg = AC.getCFG()) { |
926 UninitValsDiagReporter reporter(S); | 933 UninitValsDiagReporter reporter(S); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 << " " << AvgUninitVariablesPerFunction | 989 << " " << AvgUninitVariablesPerFunction |
983 << " average variables per function.\n" | 990 << " average variables per function.\n" |
984 << " " << MaxUninitAnalysisVariablesPerFunction | 991 << " " << MaxUninitAnalysisVariablesPerFunction |
985 << " max variables per function.\n" | 992 << " max variables per function.\n" |
986 << " " << NumUninitAnalysisBlockVisits << " block visits.\n" | 993 << " " << NumUninitAnalysisBlockVisits << " block visits.\n" |
987 << " " << AvgUninitBlockVisitsPerFunction | 994 << " " << AvgUninitBlockVisitsPerFunction |
988 << " average block visits per function.\n" | 995 << " average block visits per function.\n" |
989 << " " << MaxUninitAnalysisBlockVisitsPerFunction | 996 << " " << MaxUninitAnalysisBlockVisitsPerFunction |
990 << " max block visits per function.\n"; | 997 << " max block visits per function.\n"; |
991 } | 998 } |
OLD | NEW |