summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2014-10-31 21:10:22 +0000
committerRichard Trieu <rtrieu@google.com>2014-10-31 21:10:22 +0000
commitd4a013600232120cb157df89a1993183b16c8d0c (patch)
treeb2e018e546839ccac8e945d8b619df0150f66105
parent5ad0169855cbc152a5f76a0e7c8117d56f557cc4 (diff)
downloadbcm5719-llvm-d4a013600232120cb157df89a1993183b16c8d0c.tar.gz
bcm5719-llvm-d4a013600232120cb157df89a1993183b16c8d0c.zip
Have -Wuninitialized catch uninitalized use in overloaded operator arguments.
llvm-svn: 221000
-rw-r--r--clang/lib/Sema/SemaDecl.cpp11
-rw-r--r--clang/lib/Sema/SemaDeclCXX.cpp11
-rw-r--r--clang/test/SemaCXX/uninitialized.cpp26
3 files changed, 44 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3d0ebf277d0..734a01e2e30 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8434,11 +8434,14 @@ namespace {
}
void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
- if (E->getNumArgs() > 0)
- if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->getArg(0)))
- HandleDeclRefExpr(DRE);
+ Expr *Callee = E->getCallee();
+
+ if (isa<UnresolvedLookupExpr>(Callee))
+ return Inherited::VisitCXXOperatorCallExpr(E);
- Inherited::VisitCXXOperatorCallExpr(E);
+ Visit(Callee);
+ for (auto Arg: E->arguments())
+ HandleValue(Arg->IgnoreParenImpCasts());
}
void VisitUnaryOperator(UnaryOperator *E) {
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index adbcafe4339..233ab615a52 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -2494,6 +2494,17 @@ namespace {
Inherited::VisitCallExpr(E);
}
+ void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
+ Expr *Callee = E->getCallee();
+
+ if (isa<UnresolvedLookupExpr>(Callee))
+ return Inherited::VisitCXXOperatorCallExpr(E);
+
+ Visit(Callee);
+ for (auto Arg : E->arguments())
+ HandleValue(Arg->IgnoreParenImpCasts(), false /*AddressOf*/);
+ }
+
void VisitBinaryOperator(BinaryOperator *E) {
// If a field assignment is detected, remove the field from the
// uninitiailized field set.
diff --git a/clang/test/SemaCXX/uninitialized.cpp b/clang/test/SemaCXX/uninitialized.cpp
index 61dabb2d001..d9fb9eebc2e 100644
--- a/clang/test/SemaCXX/uninitialized.cpp
+++ b/clang/test/SemaCXX/uninitialized.cpp
@@ -183,8 +183,12 @@ class A {
A(A *a) {}
A(A &&a) {}
~A();
+ bool operator!();
+ bool operator!=(const A&);
};
+bool operator!=(int, const A&);
+
A getA() { return A(); }
A getA(int x) { return A(); }
A getA(A* a) { return A(); }
@@ -243,6 +247,13 @@ void setupA(bool x) {
A a38({a38}); // expected-warning {{variable 'a38' is uninitialized when used within its own initialization}}
A a39 = {a39}; // expected-warning {{variable 'a39' is uninitialized when used within its own initialization}}
A a40 = A({a40}); // expected-warning {{variable 'a40' is uninitialized when used within its own initialization}}
+
+ A a41 = !a41; // expected-warning {{variable 'a41' is uninitialized when used within its own initialization}}
+ A a42 = !(a42); // expected-warning {{variable 'a42' is uninitialized when used within its own initialization}}
+ A a43 = a43 != a42; // expected-warning {{variable 'a43' is uninitialized when used within its own initialization}}
+ A a44 = a43 != a44; // expected-warning {{variable 'a44' is uninitialized when used within its own initialization}}
+ A a45 = a45 != a45; // expected-warning 2{{variable 'a45' is uninitialized when used within its own initialization}}
+ A a46 = 0 != a46; // expected-warning {{variable 'a46' is uninitialized when used within its own initialization}}
}
bool cond;
@@ -295,6 +306,14 @@ A a38({a38}); // expected-warning {{variable 'a38' is uninitialized when used w
A a39 = {a39}; // expected-warning {{variable 'a39' is uninitialized when used within its own initialization}}
A a40 = A({a40}); // expected-warning {{variable 'a40' is uninitialized when used within its own initialization}}
+A a41 = !a41; // expected-warning {{variable 'a41' is uninitialized when used within its own initialization}}
+A a42 = !(a42); // expected-warning {{variable 'a42' is uninitialized when used within its own initialization}}
+A a43 = a43 != a42; // expected-warning {{variable 'a43' is uninitialized when used within its own initialization}}
+A a44 = a43 != a44; // expected-warning {{variable 'a44' is uninitialized when used within its own initialization}}
+A a45 = a45 != a45; // expected-warning 2{{variable 'a45' is uninitialized when used within its own initialization}}
+
+A a46 = 0 != a46; // expected-warning {{variable 'a46' is uninitialized when used within its own initialization}}
+
class T {
A a, a2;
const A c_a;
@@ -348,6 +367,13 @@ class T {
T(bool (*)[38]) : a({a}) {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[39]) : a{a} {} // expected-warning {{field 'a' is uninitialized when used here}}
T(bool (*)[40]) : a({a}) {} // expected-warning {{field 'a' is uninitialized when used here}}
+
+ T(bool (*)[41]) : a(!a) {} // expected-warning {{field 'a' is uninitialized when used here}}
+ T(bool (*)[42]) : a(!(a)) {} // expected-warning {{field 'a' is uninitialized when used here}}
+ T(bool (*)[43]) : a(), a2(a2 != a) {} // expected-warning {{field 'a2' is uninitialized when used here}}
+ T(bool (*)[44]) : a(), a2(a != a2) {} // expected-warning {{field 'a2' is uninitialized when used here}}
+ T(bool (*)[45]) : a(a != a) {} // expected-warning 2{{field 'a' is uninitialized when used here}}
+ T(bool (*)[46]) : a(0 != a) {} // expected-warning {{field 'a' is uninitialized when used here}}
};
struct B {
OpenPOWER on IntegriCloud