[clang] 5b6b840 - Revert "[Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators"
Dávid Bolvanský via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 23 23:45:00 PDT 2022
Author: Dávid Bolvanský
Date: 2022-03-24T07:44:51+01:00
New Revision: 5b6b840531fa05093a4099699b0cda881fbadef8
URL: https://github.com/llvm/llvm-project/commit/5b6b840531fa05093a4099699b0cda881fbadef8
DIFF: https://github.com/llvm/llvm-project/commit/5b6b840531fa05093a4099699b0cda881fbadef8.diff
LOG: Revert "[Clang] -Wunused-but-set-variable warning - handle also pre/post unary operators"
This reverts commit 460fc440ad8d41ca2e3882987512989b1c188fbe.
Added:
Modified:
clang/lib/Sema/SemaExprCXX.cpp
clang/test/Sema/warn-unused-but-set-parameters.c
clang/test/Sema/warn-unused-but-set-variables.c
clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index f360dc6e1a236..8873731cd3d3e 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7921,7 +7921,6 @@ static void MaybeDecrementCount(
Expr *E, llvm::DenseMap<const VarDecl *, int> &RefsMinusAssignments) {
DeclRefExpr *LHS = nullptr;
bool IsCompoundAssign = false;
- bool isIncrementDecrementUnaryOp = false;
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
if (BO->getLHS()->getType()->isDependentType() ||
BO->getRHS()->getType()->isDependentType()) {
@@ -7936,11 +7935,6 @@ static void MaybeDecrementCount(
if (COCE->getOperator() != OO_Equal)
return;
LHS = dyn_cast<DeclRefExpr>(COCE->getArg(0));
- } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) {
- if (!UO->isIncrementDecrementOp())
- return;
- isIncrementDecrementUnaryOp = true;
- LHS = dyn_cast<DeclRefExpr>(UO->getSubExpr());
}
if (!LHS)
return;
@@ -7948,10 +7942,8 @@ static void MaybeDecrementCount(
if (!VD)
return;
// Don't decrement RefsMinusAssignments if volatile variable with compound
- // assignment (+=, ...) or increment/decrement unary operator to avoid
- // potential unused-but-set-variable warning.
- if ((IsCompoundAssign || isIncrementDecrementUnaryOp) &&
- VD->getType().isVolatileQualified())
+ // assignment (+=, ...) to avoid potential unused-but-set-variable warning.
+ if (IsCompoundAssign && VD->getType().isVolatileQualified())
return;
auto iter = RefsMinusAssignments.find(VD);
if (iter == RefsMinusAssignments.end())
diff --git a/clang/test/Sema/warn-unused-but-set-parameters.c b/clang/test/Sema/warn-unused-but-set-parameters.c
index f1563ab50c1fb..4f000617cfcc4 100644
--- a/clang/test/Sema/warn-unused-but-set-parameters.c
+++ b/clang/test/Sema/warn-unused-but-set-parameters.c
@@ -25,10 +25,10 @@ void f3(struct S s) { // expected-warning{{parameter 's' set but not used}}
s = t;
}
-void f4(int j) { // expected-warning{{parameter 'j' set but not used}}
+void f4(int j) { //TODO: warn
j++;
}
-void f5(int k) { // expected-warning{{parameter 'k' set but not used}}
+void f5(int k) { //TODO: warn
--k;
}
diff --git a/clang/test/Sema/warn-unused-but-set-variables.c b/clang/test/Sema/warn-unused-but-set-variables.c
index 58104d198084c..6e5b7d671711b 100644
--- a/clang/test/Sema/warn-unused-but-set-variables.c
+++ b/clang/test/Sema/warn-unused-but-set-variables.c
@@ -73,20 +73,3 @@ void f3(void) {
__attribute__((__cleanup__(for_cleanup))) int x;
x = 5;
}
-
-void f4(void) {
- int x1 = 0; // expected-warning{{variable 'x1' set but not used}}
- x1++;
- int x2 = 0; // expected-warning{{variable 'x2' set but not used}}
- x2--;
- int x3 = 0; // expected-warning{{variable 'x3' set but not used}}
- ++x3;
- int x4 = 0; // expected-warning{{variable 'x4' set but not used}}
- --x4;
-
- volatile int v1 = 0;
- ++v1;
- typedef volatile int volint;
- volint v2 = 0;
- v2++;
-}
diff --git a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
index 418baa78aa964..400e9d7681b31 100644
--- a/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ b/clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
@@ -7,7 +7,6 @@ struct S {
struct __attribute__((warn_unused)) SWarnUnused {
int j;
void operator +=(int);
- void operator ++();
};
int f0() {
@@ -63,9 +62,3 @@ template<typename T> void f4(T n) {
SWarnUnused swu;
swu += n;
}
-
-template <typename T> void f5() {
- // Don't warn for overloaded pre/post operators in template code.
- SWarnUnused swu;
- ++swu;
-}
More information about the cfe-commits
mailing list