diff options
| author | Ted Kremenek <kremenek@apple.com> | 2011-02-02 23:35:53 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2011-02-02 23:35:53 +0000 |
| commit | b3dbe28e3196f8f5cc9d5dd834ce1df4dfe1588e (patch) | |
| tree | 74a04dbdf68475b129e73e772875ef271db5e796 /clang/lib/Sema | |
| parent | 0c12ed14293b62196d093c0e754166d3e9bb8eaa (diff) | |
| download | bcm5719-llvm-b3dbe28e3196f8f5cc9d5dd834ce1df4dfe1588e.tar.gz bcm5719-llvm-b3dbe28e3196f8f5cc9d5dd834ce1df4dfe1588e.zip | |
Based on user feedback, swap -Wuninitialized diagnostics to have the warning refer to the bad use, and the note to the variable declaration.
llvm-svn: 124758
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/AnalysisBasedWarnings.cpp | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp b/clang/lib/Sema/AnalysisBasedWarnings.cpp index 3e6cd81b760..0e7846f021a 100644 --- a/clang/lib/Sema/AnalysisBasedWarnings.cpp +++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp @@ -393,14 +393,13 @@ public: void flushDiagnostics() { if (!uses) return; - + for (UsesMap::iterator i = uses->begin(), e = uses->end(); i != e; ++i) { const VarDecl *vd = i->first; UsesVec *vec = i->second; - - S.Diag(vd->getLocStart(), diag::warn_uninit_var) - << vd->getDeclName() << vd->getSourceRange(); - + + bool fixitIssued = false; + // Sort the uses by their SourceLocations. While not strictly // guaranteed to produce them in line/column order, this will provide // a stable ordering. @@ -409,43 +408,49 @@ public: for (UsesVec::iterator vi = vec->begin(), ve = vec->end(); vi != ve; ++vi) { if (const DeclRefExpr *dr = dyn_cast<DeclRefExpr>(*vi)) { - S.Diag(dr->getLocStart(), diag::note_uninit_var) - << vd->getDeclName() << dr->getSourceRange(); + S.Diag(dr->getLocStart(), diag::warn_uninit_var) + << vd->getDeclName() << dr->getSourceRange(); } else { const BlockExpr *be = cast<BlockExpr>(*vi); - S.Diag(be->getLocStart(), diag::note_uninit_var_captured_by_block) + S.Diag(be->getLocStart(), diag::warn_uninit_var_captured_by_block) << vd->getDeclName(); } - } + + // Report where the variable was declared. + S.Diag(vd->getLocStart(), diag::note_uninit_var_def) + << vd->getDeclName(); + + // Only report the fixit once. + if (fixitIssued) + continue; + + fixitIssued = true; - // Suggest possible initialization (if any). - const char *initialization = 0; - QualType vdTy = vd->getType().getCanonicalType(); + // Suggest possible initialization (if any). + const char *initialization = 0; + QualType vdTy = vd->getType().getCanonicalType(); - if (vdTy->getAs<ObjCObjectPointerType>()) { - // Check if 'nil' is defined. - if (S.PP.getMacroInfo(&S.getASTContext().Idents.get("nil"))) - initialization = " = nil"; - else + if (vdTy->getAs<ObjCObjectPointerType>()) { + // Check if 'nil' is defined. + if (S.PP.getMacroInfo(&S.getASTContext().Idents.get("nil"))) + initialization = " = nil"; + else + initialization = " = 0"; + } + else if (vdTy->isRealFloatingType()) + initialization = " = 0.0"; + else if (vdTy->isBooleanType() && S.Context.getLangOptions().CPlusPlus) + initialization = " = false"; + else if (vdTy->isScalarType()) initialization = " = 0"; - } - else if (vdTy->isRealFloatingType()) { - initialization = " = 0.0"; - } - else if (vdTy->isBooleanType() && S.Context.getLangOptions().CPlusPlus) { - initialization = " = false"; - } - else if (vdTy->isScalarType()) { - initialization = " = 0"; - } - if (initialization) { - SourceLocation loc = S.PP.getLocForEndOfToken(vd->getLocEnd()); - S.Diag(loc, diag::note_var_fixit_add_initialization) - << FixItHint::CreateInsertion(loc, initialization); + if (initialization) { + SourceLocation loc = S.PP.getLocForEndOfToken(vd->getLocEnd()); + S.Diag(loc, diag::note_var_fixit_add_initialization) + << FixItHint::CreateInsertion(loc, initialization); + } } - delete vec; } delete uses; |

