Skip to content

Commit 5683cab

Browse files
committed
Revert "[clang] Add -Wuninitialized-const-pointer (llvm#148337)"
This reverts commit 00dacf8.
1 parent fa7b8d6 commit 5683cab

File tree

9 files changed

+18
-84
lines changed

9 files changed

+18
-84
lines changed

clang/include/clang/Analysis/Analyses/UninitializedValues.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class UninitUse {
5050
/// Is this use a const reference to this variable?
5151
bool ConstRefUse = false;
5252

53-
/// Is this use a const pointer to this variable?
54-
bool ConstPtrUse = false;
55-
5653
/// This use is always uninitialized if it occurs after any of these branches
5754
/// is taken.
5855
SmallVector<Branch, 2> UninitBranches;
@@ -68,14 +65,11 @@ class UninitUse {
6865
void setUninitAfterCall() { UninitAfterCall = true; }
6966
void setUninitAfterDecl() { UninitAfterDecl = true; }
7067
void setConstRefUse() { ConstRefUse = true; }
71-
void setConstPtrUse() { ConstPtrUse = true; }
7268

7369
/// Get the expression containing the uninitialized use.
7470
const Expr *getUser() const { return User; }
7571

7672
bool isConstRefUse() const { return ConstRefUse; }
77-
bool isConstPtrUse() const { return ConstPtrUse; }
78-
bool isConstRefOrPtrUse() const { return ConstRefUse || ConstPtrUse; }
7973

8074
/// The kind of uninitialized use.
8175
enum Kind {

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,11 +952,9 @@ def UninitializedMaybe : DiagGroup<"conditional-uninitialized">;
952952
def UninitializedSometimes : DiagGroup<"sometimes-uninitialized">;
953953
def UninitializedStaticSelfInit : DiagGroup<"static-self-init">;
954954
def UninitializedConstReference : DiagGroup<"uninitialized-const-reference">;
955-
def UninitializedConstPointer : DiagGroup<"uninitialized-const-pointer">;
956955
def Uninitialized : DiagGroup<"uninitialized", [UninitializedSometimes,
957956
UninitializedStaticSelfInit,
958-
UninitializedConstReference,
959-
UninitializedConstPointer]>;
957+
UninitializedConstReference]>;
960958
def IgnoredPragmaIntrinsic : DiagGroup<"ignored-pragma-intrinsic">;
961959
// #pragma optimize is often used to avoid to work around MSVC codegen bugs or
962960
// to disable inlining. It's not completely clear what alternative to suggest

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,10 +2548,6 @@ def warn_uninit_const_reference : Warning<
25482548
"variable %0 is uninitialized when passed as a const reference argument "
25492549
"here">, InGroup<UninitializedConstReference>, DefaultIgnore;
25502550

2551-
def warn_uninit_const_pointer : Warning<
2552-
"variable %0 is uninitialized when passed as a const pointer argument here">,
2553-
InGroup<UninitializedConstPointer>, DefaultIgnore;
2554-
25552551
def warn_unsequenced_mod_mod : Warning<
25562552
"multiple unsequenced modifications to %0">, InGroup<Unsequenced>;
25572553
def warn_unsequenced_mod_use : Warning<

clang/lib/Analysis/UninitializedValues.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,13 @@ namespace {
276276
/// escaped the analysis and will be treated as an initialization.
277277
class ClassifyRefs : public StmtVisitor<ClassifyRefs> {
278278
public:
279-
enum Class { Init, Use, SelfInit, ConstRefUse, ConstPtrUse, Ignore };
279+
enum Class {
280+
Init,
281+
Use,
282+
SelfInit,
283+
ConstRefUse,
284+
Ignore
285+
};
280286

281287
private:
282288
const DeclContext *DC;
@@ -445,7 +451,8 @@ void ClassifyRefs::VisitCallExpr(CallExpr *CE) {
445451
const Expr *Ex = stripCasts(DC->getParentASTContext(), *I);
446452
const auto *UO = dyn_cast<UnaryOperator>(Ex);
447453
if (UO && UO->getOpcode() == UO_AddrOf)
448-
classify(UO->getSubExpr(), isTrivialBody ? Ignore : ConstPtrUse);
454+
Ex = UO->getSubExpr();
455+
classify(Ex, Ignore);
449456
}
450457
}
451458
}
@@ -489,7 +496,6 @@ class TransferFunctions : public StmtVisitor<TransferFunctions> {
489496

490497
void reportUse(const Expr *ex, const VarDecl *vd);
491498
void reportConstRefUse(const Expr *ex, const VarDecl *vd);
492-
void reportConstPtrUse(const Expr *ex, const VarDecl *vd);
493499

494500
void VisitBinaryOperator(BinaryOperator *bo);
495501
void VisitBlockExpr(BlockExpr *be);
@@ -676,15 +682,6 @@ void TransferFunctions::reportConstRefUse(const Expr *ex, const VarDecl *vd) {
676682
}
677683
}
678684

679-
void TransferFunctions::reportConstPtrUse(const Expr *ex, const VarDecl *vd) {
680-
Value v = vals[vd];
681-
if (isAlwaysUninit(v)) {
682-
auto use = getUninitUse(ex, vd, v);
683-
use.setConstPtrUse();
684-
handler.handleUseOfUninitVariable(vd, use);
685-
}
686-
}
687-
688685
void TransferFunctions::VisitObjCForCollectionStmt(ObjCForCollectionStmt *FS) {
689686
// This represents an initialization of the 'element' value.
690687
if (const auto *DS = dyn_cast<DeclStmt>(FS->getElement())) {
@@ -757,9 +754,6 @@ void TransferFunctions::VisitDeclRefExpr(DeclRefExpr *dr) {
757754
case ClassifyRefs::ConstRefUse:
758755
reportConstRefUse(dr, cast<VarDecl>(dr->getDecl()));
759756
break;
760-
case ClassifyRefs::ConstPtrUse:
761-
reportConstPtrUse(dr, cast<VarDecl>(dr->getDecl()));
762-
break;
763757
}
764758
}
765759

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -994,14 +994,6 @@ 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-
1005997
/// DiagnoseUninitializedUse -- Helper function for diagnosing uses of an
1006998
/// uninitialized variable. This manages the different forms of diagnostic
1007999
/// emitted for particular types of uses. Returns true if the use was diagnosed
@@ -1607,9 +1599,9 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
16071599
// a stable ordering.
16081600
llvm::sort(*vec, [](const UninitUse &a, const UninitUse &b) {
16091601
// Prefer the direct use of an uninitialized variable over its use via
1610-
// constant reference or pointer.
1611-
if (a.isConstRefOrPtrUse() != b.isConstRefOrPtrUse())
1612-
return b.isConstRefOrPtrUse();
1602+
// constant reference.
1603+
if (a.isConstRefUse() != b.isConstRefUse())
1604+
return b.isConstRefUse();
16131605
// Prefer a more confident report over a less confident one.
16141606
if (a.getKind() != b.getKind())
16151607
return a.getKind() > b.getKind();
@@ -1620,9 +1612,6 @@ class UninitValsDiagReporter : public UninitVariablesHandler {
16201612
if (U.isConstRefUse()) {
16211613
if (DiagnoseUninitializedConstRefUse(S, vd, U))
16221614
return;
1623-
} else if (U.isConstPtrUse()) {
1624-
if (DiagnoseUninitializedConstPtrUse(S, vd, U))
1625-
return;
16261615
} else {
16271616
// If we have self-init, downgrade all uses to 'may be uninitialized'.
16281617
UninitUse Use = hasSelfInit ? UninitUse(U.getUser(), false) : U;
@@ -2839,8 +2828,7 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
28392828
if (!Diags.isIgnored(diag::warn_uninit_var, D->getBeginLoc()) ||
28402829
!Diags.isIgnored(diag::warn_sometimes_uninit_var, D->getBeginLoc()) ||
28412830
!Diags.isIgnored(diag::warn_maybe_uninit_var, D->getBeginLoc()) ||
2842-
!Diags.isIgnored(diag::warn_uninit_const_reference, D->getBeginLoc()) ||
2843-
!Diags.isIgnored(diag::warn_uninit_const_pointer, D->getBeginLoc())) {
2831+
!Diags.isIgnored(diag::warn_uninit_const_reference, D->getBeginLoc())) {
28442832
if (CFG *cfg = AC.getCFG()) {
28452833
UninitValsDiagReporter reporter(S);
28462834
UninitVariablesAnalysisStats stats;

clang/test/Misc/warning-wall.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ CHECK-NEXT: -Wuninitialized
6666
CHECK-NEXT: -Wsometimes-uninitialized
6767
CHECK-NEXT: -Wstatic-self-init
6868
CHECK-NEXT: -Wuninitialized-const-reference
69-
CHECK-NEXT: -Wuninitialized-const-pointer
7069
CHECK-NEXT: -Wunknown-pragmas
7170
CHECK-NEXT: -Wunused
7271
CHECK-NEXT: -Wunused-argument

clang/test/SemaCXX/warn-uninitialized-const-pointer.cpp

Lines changed: 0 additions & 35 deletions
This file was deleted.

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ int main(int, char**)
6262
{
6363
testbuf<char> sb1;
6464
std::ostream os1(&sb1);
65-
int n1 = 0;
65+
int n1;
6666
os1 << &n1;
6767
assert(os1.good());
6868
std::string s1(sb1.str());
6969

7070
testbuf<char> sb2;
7171
std::ostream os2(&sb2);
72-
int n2 = 0;
72+
int n2;
7373
os2 << &n2;
7474
assert(os2.good());
7575
std::string s2(sb2.str());

libcxx/test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters.arithmetic/pointer.volatile.pass.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class testbuf : public std::basic_streambuf<CharT> {
6161
int main(int, char**) {
6262
testbuf<char> sb1;
6363
std::ostream os1(&sb1);
64-
int n1 = 0;
64+
int n1;
6565
os1 << &n1;
6666
assert(os1.good());
6767
std::string s1 = sb1.str();
@@ -74,7 +74,7 @@ int main(int, char**) {
7474

7575
testbuf<char> sb3;
7676
std::ostream os3(&sb3);
77-
volatile int n3 = 0;
77+
volatile int n3;
7878
os3 << &n3;
7979
assert(os3.good());
8080
std::string s3 = sb3.str();

0 commit comments

Comments
 (0)