@@ -987,11 +987,10 @@ static void DiagUninitUse(Sema &S, const VarDecl *VD, const UninitUse &Use,
987987}
988988
989989// / Diagnose uninitialized const reference usages.
990- static bool DiagnoseUninitializedConstRefUse (Sema &S, const VarDecl *VD,
990+ static void DiagnoseUninitializedConstRefUse (Sema &S, const VarDecl *VD,
991991 const UninitUse &Use) {
992992 S.Diag (Use.getUser ()->getBeginLoc (), diag::warn_uninit_const_reference)
993993 << VD->getDeclName () << Use.getUser ()->getSourceRange ();
994- return true ;
995994}
996995
997996// / DiagnoseUninitializedUse -- Helper function for diagnosing uses of an
@@ -1533,33 +1532,24 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
15331532 // order of diagnostics when calling flushDiagnostics().
15341533 typedef llvm::MapVector<const VarDecl *, MappedType> UsesMap;
15351534 UsesMap uses;
1536- UsesMap constRefUses;
15371535
15381536public:
15391537 UninitValsDiagReporter (Sema &S) : S(S) {}
15401538 ~UninitValsDiagReporter () override { flushDiagnostics (); }
15411539
1542- MappedType &getUses (UsesMap &um, const VarDecl *vd) {
1543- MappedType &V = um [vd];
1540+ MappedType &getUses (const VarDecl *vd) {
1541+ MappedType &V = uses [vd];
15441542 if (!V.getPointer ())
15451543 V.setPointer (new UsesVec ());
15461544 return V;
15471545 }
15481546
15491547 void handleUseOfUninitVariable (const VarDecl *vd,
15501548 const UninitUse &use) override {
1551- getUses (uses, vd).getPointer ()->push_back (use);
1552- }
1553-
1554- void handleConstRefUseOfUninitVariable (const VarDecl *vd,
1555- const UninitUse &use) override {
1556- getUses (constRefUses, vd).getPointer ()->push_back (use);
1549+ getUses (vd).getPointer ()->push_back (use);
15571550 }
15581551
1559- void handleSelfInit (const VarDecl *vd) override {
1560- getUses (uses, vd).setInt (true );
1561- getUses (constRefUses, vd).setInt (true );
1562- }
1552+ void handleSelfInit (const VarDecl *vd) override { getUses (vd).setInt (true ); }
15631553
15641554 void flushDiagnostics () {
15651555 for (const auto &P : uses) {
@@ -1582,13 +1572,21 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
15821572 // guaranteed to produce them in line/column order, this will provide
15831573 // a stable ordering.
15841574 llvm::sort (*vec, [](const UninitUse &a, const UninitUse &b) {
1575+ // Move ConstRef uses to the back.
1576+ if (a.isConstRefUse () != b.isConstRefUse ())
1577+ return b.isConstRefUse ();
15851578 // Prefer a more confident report over a less confident one.
15861579 if (a.getKind () != b.getKind ())
15871580 return a.getKind () > b.getKind ();
15881581 return a.getUser ()->getBeginLoc () < b.getUser ()->getBeginLoc ();
15891582 });
15901583
15911584 for (const auto &U : *vec) {
1585+ if (U.isConstRefUse ()) {
1586+ DiagnoseUninitializedConstRefUse (S, vd, U);
1587+ break ;
1588+ }
1589+
15921590 // If we have self-init, downgrade all uses to 'may be uninitialized'.
15931591 UninitUse Use = hasSelfInit ? UninitUse (U.getUser (), false ) : U;
15941592
@@ -1604,32 +1602,6 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
16041602 }
16051603
16061604 uses.clear ();
1607-
1608- // Flush all const reference uses diags.
1609- for (const auto &P : constRefUses) {
1610- const VarDecl *vd = P.first ;
1611- const MappedType &V = P.second ;
1612-
1613- UsesVec *vec = V.getPointer ();
1614- bool hasSelfInit = V.getInt ();
1615-
1616- if (!vec->empty () && hasSelfInit && hasAlwaysUninitializedUse (vec))
1617- DiagnoseUninitializedUse (S, vd,
1618- UninitUse (vd->getInit ()->IgnoreParenCasts (),
1619- /* isAlwaysUninit */ true ),
1620- /* alwaysReportSelfInit */ true );
1621- else {
1622- for (const auto &U : *vec) {
1623- if (DiagnoseUninitializedConstRefUse (S, vd, U))
1624- break ;
1625- }
1626- }
1627-
1628- // Release the uses vector.
1629- delete vec;
1630- }
1631-
1632- constRefUses.clear ();
16331605 }
16341606
16351607private:
0 commit comments