diff options
| author | 2017-01-14 19:55:43 +0000 | |
|---|---|---|
| committer | 2017-01-14 19:55:43 +0000 | |
| commit | bd3306aecb3a15e8967143b8cdbbccf2b1b19b74 (patch) | |
| tree | 309a8132b44564b9e634c0da6815187ce8eab27c /gnu/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp | |
| parent | killp -a should not kill the window if only one pane. (diff) | |
| download | wireguard-openbsd-bd3306aecb3a15e8967143b8cdbbccf2b1b19b74.tar.xz wireguard-openbsd-bd3306aecb3a15e8967143b8cdbbccf2b1b19b74.zip | |
Import LLVM 3.9.1 including clang and lld.
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp')
| -rw-r--r-- | gnu/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp | 65 |
1 files changed, 46 insertions, 19 deletions
diff --git a/gnu/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp b/gnu/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp index 5f74343fbd9..67762bde343 100644 --- a/gnu/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/gnu/llvm/tools/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -889,7 +889,7 @@ 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_uninit_var_def) + S.Diag(VD->getLocStart(), diag::note_var_declared_here) << VD->getDeclName(); return true; @@ -1071,6 +1071,34 @@ namespace { }; } // anonymous namespace +static StringRef getFallthroughAttrSpelling(Preprocessor &PP, + SourceLocation Loc) { + TokenValue FallthroughTokens[] = { + tok::l_square, tok::l_square, + PP.getIdentifierInfo("fallthrough"), + tok::r_square, tok::r_square + }; + + TokenValue ClangFallthroughTokens[] = { + tok::l_square, tok::l_square, PP.getIdentifierInfo("clang"), + tok::coloncolon, PP.getIdentifierInfo("fallthrough"), + tok::r_square, tok::r_square + }; + + bool PreferClangAttr = !PP.getLangOpts().CPlusPlus1z; + + StringRef MacroName; + if (PreferClangAttr) + MacroName = PP.getLastMacroWithSpelling(Loc, ClangFallthroughTokens); + if (MacroName.empty()) + MacroName = PP.getLastMacroWithSpelling(Loc, FallthroughTokens); + if (MacroName.empty() && !PreferClangAttr) + MacroName = PP.getLastMacroWithSpelling(Loc, ClangFallthroughTokens); + if (MacroName.empty()) + MacroName = PreferClangAttr ? "[[clang::fallthrough]]" : "[[fallthrough]]"; + return MacroName; +} + static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC, bool PerFunction) { // Only perform this analysis when using C++11. There is no good workflow @@ -1129,15 +1157,7 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC, } if (!(B->empty() && Term && isa<BreakStmt>(Term))) { Preprocessor &PP = S.getPreprocessor(); - TokenValue Tokens[] = { - tok::l_square, tok::l_square, PP.getIdentifierInfo("clang"), - tok::coloncolon, PP.getIdentifierInfo("fallthrough"), - tok::r_square, tok::r_square - }; - StringRef AnnotationSpelling = "[[clang::fallthrough]]"; - StringRef MacroName = PP.getLastMacroWithSpelling(L, Tokens); - if (!MacroName.empty()) - AnnotationSpelling = MacroName; + StringRef AnnotationSpelling = getFallthroughAttrSpelling(PP, L); SmallString<64> TextToInsert(AnnotationSpelling); TextToInsert += "; "; S.Diag(L, diag::note_insert_fallthrough_fixit) << @@ -1151,7 +1171,7 @@ static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC, } for (const auto *F : FM.getFallthroughStmts()) - S.Diag(F->getLocStart(), diag::warn_fallthrough_attr_invalid_placement); + S.Diag(F->getLocStart(), diag::err_fallthrough_attr_invalid_placement); } static bool isInLoop(const ASTContext &Ctx, const ParentMap &PM, @@ -1302,21 +1322,27 @@ static void diagnoseRepeatedUseOfWeak(Sema &S, Ivar } ObjectKind; - const NamedDecl *D = Key.getProperty(); - if (isa<VarDecl>(D)) + const NamedDecl *KeyProp = Key.getProperty(); + if (isa<VarDecl>(KeyProp)) ObjectKind = Variable; - else if (isa<ObjCPropertyDecl>(D)) + else if (isa<ObjCPropertyDecl>(KeyProp)) ObjectKind = Property; - else if (isa<ObjCMethodDecl>(D)) + else if (isa<ObjCMethodDecl>(KeyProp)) ObjectKind = ImplicitProperty; - else if (isa<ObjCIvarDecl>(D)) + else if (isa<ObjCIvarDecl>(KeyProp)) ObjectKind = Ivar; else llvm_unreachable("Unexpected weak object kind!"); + // Do not warn about IBOutlet weak property receivers being set to null + // since they are typically only used from the main thread. + if (const ObjCPropertyDecl *Prop = dyn_cast<ObjCPropertyDecl>(KeyProp)) + if (Prop->hasAttr<IBOutletAttr>()) + continue; + // Show the first time the object was read. S.Diag(FirstRead->getLocStart(), DiagKind) - << int(ObjectKind) << D << int(FunctionKind) + << int(ObjectKind) << KeyProp << int(FunctionKind) << FirstRead->getSourceRange(); // Print all the other accesses as notes. @@ -1871,7 +1897,7 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, if (cast<DeclContext>(D)->isDependentContext()) return; - if (Diags.hasUncompilableErrorOccurred() || Diags.hasFatalErrorOccurred()) { + if (Diags.hasUncompilableErrorOccurred()) { // Flush out any possibly unreachable diagnostics. flushDiagnostics(S, fscope); return; @@ -2038,7 +2064,8 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P, !Diags.isIgnored(diag::warn_unannotated_fallthrough, D->getLocStart()); bool FallThroughDiagPerFunction = !Diags.isIgnored( diag::warn_unannotated_fallthrough_per_function, D->getLocStart()); - if (FallThroughDiagFull || FallThroughDiagPerFunction) { + if (FallThroughDiagFull || FallThroughDiagPerFunction || + fscope->HasFallthroughStmt) { DiagnoseSwitchLabelsFallthrough(S, AC, !FallThroughDiagFull); } |
