forked from OSchip/llvm-project
Remove warning in dead stores checker for
dead stores within nested assignments. I have never seen an actual bug found by this specific warning, and it can lead to many false positives. llvm-svn: 123394
This commit is contained in:
parent
b084be90e8
commit
f224820b45
|
@ -1,4 +1,4 @@
|
|||
//==- DeadStores.cpp - Check for stores to dead variables --------*- C++ -*-==//
|
||||
//==- DeadStoresChecker.cpp - Check for stores to dead variables -*- C++ -*-==//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -70,11 +70,10 @@ public:
|
|||
break;
|
||||
|
||||
case Enclosing:
|
||||
BugType = "Dead nested assignment";
|
||||
msg = "Although the value stored to '" + name +
|
||||
"' is used in the enclosing expression, the value is never actually"
|
||||
" read from '" + name + "'";
|
||||
break;
|
||||
// Don't report issues in this case, e.g.: "if (x = foo())",
|
||||
// where 'x' is unused later. We have yet to see a case where
|
||||
// this is a real bug.
|
||||
return;
|
||||
}
|
||||
|
||||
BR.EmitBasicReport(BugType, "Dead store", msg, L, R);
|
||||
|
|
|
@ -75,9 +75,11 @@ int f7d(int *p) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
// Don't warn for dead stores in nested expressions. We have yet
|
||||
// to see a real bug in this scenario.
|
||||
int f8(int *p) {
|
||||
extern int *baz();
|
||||
if ((p = baz())) // expected-warning{{Although the value}}
|
||||
if ((p = baz())) // no-warning
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -148,9 +150,11 @@ void f15(unsigned x, unsigned y) {
|
|||
int z[count]; // expected-warning{{unused variable 'z'}}
|
||||
}
|
||||
|
||||
// Don't warn for dead stores in nested expressions. We have yet
|
||||
// to see a real bug in this scenario.
|
||||
int f16(int x) {
|
||||
x = x * 2;
|
||||
x = sizeof(int [x = (x || x + 1) * 2]) // expected-warning{{Although the value stored to 'x' is used}} expected-warning{{The left operand to '*' is always 1}} expected-warning{{The left operand to '+' is always 0}}
|
||||
x = sizeof(int [x = (x || x + 1) * 2]) // expected-warning{{The left operand to '+' is always 0}} expected-warning{{The left operand to '*' is always 1}}
|
||||
? 5 : 8;
|
||||
return x;
|
||||
}
|
||||
|
@ -175,7 +179,9 @@ int f18() {
|
|||
x = 10; // expected-warning{{Value stored to 'x' is never read}}
|
||||
while (1);
|
||||
|
||||
return (x = 10); // expected-warning{{Although the value stored to 'x' is used in the enclosing expression, the value is never actually read from 'x'}}
|
||||
// Don't warn for dead stores in nested expressions. We have yet
|
||||
// to see a real bug in this scenario.
|
||||
return (x = 10); // no-warning
|
||||
}
|
||||
|
||||
// PR 3514: false positive `dead initialization` warning for init to global
|
||||
|
|
Loading…
Reference in New Issue