@@ -994,6 +994,14 @@ static bool DiagnoseUninitializedConstRefUse(Sema &S, const VarDecl *VD,
994994 return !S.getDiagnostics ().isLastDiagnosticIgnored ();
995995}
996996
997+ // / Diagnose uninitialized const pointer usages.
998+ static bool DiagnoseUninitializedConstPtrUse (Sema &S, const VarDecl *VD,
999+ const UninitUse &Use) {
1000+ S.Diag (Use.getUser ()->getBeginLoc (), diag::warn_uninit_const_pointer)
1001+ << VD->getDeclName () << Use.getUser ()->getSourceRange ();
1002+ return !S.getDiagnostics ().isLastDiagnosticIgnored ();
1003+ }
1004+
9971005// / DiagnoseUninitializedUse -- Helper function for diagnosing uses of an
9981006// / uninitialized variable. This manages the different forms of diagnostic
9991007// / emitted for particular types of uses. Returns true if the use was diagnosed
@@ -1599,9 +1607,9 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
15991607 // a stable ordering.
16001608 llvm::sort (*vec, [](const UninitUse &a, const UninitUse &b) {
16011609 // Prefer the direct use of an uninitialized variable over its use via
1602- // constant reference.
1603- if (a.isConstRefUse () != b.isConstRefUse ())
1604- return b.isConstRefUse ();
1610+ // constant reference or pointer .
1611+ if (a.isConstRefOrPtrUse () != b.isConstRefOrPtrUse ())
1612+ return b.isConstRefOrPtrUse ();
16051613 // Prefer a more confident report over a less confident one.
16061614 if (a.getKind () != b.getKind ())
16071615 return a.getKind () > b.getKind ();
@@ -1612,6 +1620,9 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
16121620 if (U.isConstRefUse ()) {
16131621 if (DiagnoseUninitializedConstRefUse (S, vd, U))
16141622 return ;
1623+ } else if (U.isConstPtrUse ()) {
1624+ if (DiagnoseUninitializedConstPtrUse (S, vd, U))
1625+ return ;
16151626 } else {
16161627 // If we have self-init, downgrade all uses to 'may be uninitialized'.
16171628 UninitUse Use = hasSelfInit ? UninitUse (U.getUser (), false ) : U;
@@ -2828,7 +2839,8 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
28282839 if (!Diags.isIgnored (diag::warn_uninit_var, D->getBeginLoc ()) ||
28292840 !Diags.isIgnored (diag::warn_sometimes_uninit_var, D->getBeginLoc ()) ||
28302841 !Diags.isIgnored (diag::warn_maybe_uninit_var, D->getBeginLoc ()) ||
2831- !Diags.isIgnored (diag::warn_uninit_const_reference, D->getBeginLoc ())) {
2842+ !Diags.isIgnored (diag::warn_uninit_const_reference, D->getBeginLoc ()) ||
2843+ !Diags.isIgnored (diag::warn_uninit_const_pointer, D->getBeginLoc ())) {
28322844 if (CFG *cfg = AC.getCFG ()) {
28332845 UninitValsDiagReporter reporter (S);
28342846 UninitVariablesAnalysisStats stats;
0 commit comments