r218366 - Fix an edge case with BinaryOperator's in -Wuninitialized. Add testcases for

Richard Trieu rtrieu at google.com
Tue Sep 23 20:53:56 PDT 2014


Author: rtrieu
Date: Tue Sep 23 22:53:56 2014
New Revision: 218366

URL: http://llvm.org/viewvc/llvm-project?rev=218366&view=rev
Log:
Fix an edge case with BinaryOperator's in -Wuninitialized.  Add testcases for
the other visitors as well.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/uninitialized.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=218366&r1=218365&r2=218366&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep 23 22:53:56 2014
@@ -8359,9 +8359,11 @@ namespace {
       }
 
       if (BinaryOperator *BO = dyn_cast<BinaryOperator>(E)) {
-        if (BO->getOpcode() == BO_Comma)
+        if (BO->getOpcode() == BO_Comma) {
+          Visit(BO->getLHS());
           HandleValue(BO->getRHS());
-        return;
+          return;
+        }
       }
 
       if (isa<MemberExpr>(E)) {

Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=218366&r1=218365&r2=218366&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninitialized.cpp Tue Sep 23 22:53:56 2014
@@ -42,6 +42,8 @@ int q = moved(std::move(q)); // expected
 int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
 int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
 int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
+int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
+int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
 
 void test_stuff () {
   int a = a; // no-warning: used to signal intended lack of initialization.
@@ -68,6 +70,8 @@ void test_stuff () {
   int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
   int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
   int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
+  int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
+  int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
 
   for (;;) {
     int a = a; // no-warning: used to signal intended lack of initialization.
@@ -94,6 +98,8 @@ void test_stuff () {
     int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
     int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
     int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
+    int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
+    int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
   }
 }
 
@@ -303,6 +309,7 @@ B b24 = std::move(x ? b23 : (18, b24));
 // Also test similar constructs in a field's initializer.
 struct S {
   int x;
+  int y;
   void *ptr;
 
   S(bool (*)[1]) : x(x) {} // expected-warning {{field 'x' is uninitialized when used here}}
@@ -318,6 +325,9 @@ struct S {
   S(char (*)[4]) : x(bar(&x)) {}
   S(char (*)[5]) : x(boo(x)) {}
   S(char (*)[6]) : x(far(x)) {}
+
+  S(char (*)[7]) : x(0), y((foo(y), x)) {} // expected-warning {{field 'y' is uninitialized when used here}}
+  S(char (*)[8]) : x(0), y(x += y) {} // expected-warning {{field 'y' is uninitialized when used here}}
 };
 
 struct C { char a[100], *e; } car = { .e = car.a };
@@ -484,6 +494,8 @@ namespace statics {
   static int r = std::move((p ? q : (18, r))); // expected-warning {{variable 'r' is uninitialized when used within its own initialization}}
   static int s = r ?: s; // expected-warning {{variable 's' is uninitialized when used within its own initialization}}
   static int t = t ?: s; // expected-warning {{variable 't' is uninitialized when used within its own initialization}}
+  static int u = (foo(u), s); // expected-warning {{variable 'u' is uninitialized when used within its own initialization}}
+  static int v = (u += v); // expected-warning {{variable 'v' is uninitialized when used within its own initialization}}
 
   void test() {
     static int a = a; // no-warning: used to signal intended lack of initialization.
@@ -510,6 +522,8 @@ namespace statics {
     static int r = std::move((p ? q : (18, r)));  // expected-warning {{static variable 'r' is suspiciously used within its own initialization}}
     static int s = r ?: s;  // expected-warning {{static variable 's' is suspiciously used within its own initialization}}
     static int t = t ?: s;  // expected-warning {{static variable 't' is suspiciously used within its own initialization}}
+    static int u = (foo(u), s);  // expected-warning {{static variable 'u' is suspiciously used within its own initialization}}
+    static int v = (u += v);  // expected-warning {{static variable 'v' is suspiciously used within its own initialization}}
    for (;;) {
       static int a = a; // no-warning: used to signal intended lack of initialization.
       static int b = b + 1; // expected-warning {{static variable 'b' is suspiciously used within its own initialization}}
@@ -535,6 +549,8 @@ namespace statics {
       static int r = std::move((p ? q : (18, r)));  // expected-warning {{static variable 'r' is suspiciously used within its own initialization}}
       static int s = r ?: s;  // expected-warning {{static variable 's' is suspiciously used within its own initialization}}
       static int t = t ?: s;  // expected-warning {{static variable 't' is suspiciously used within its own initialization}}
+      static int u = (foo(u), s);  // expected-warning {{static variable 'u' is suspiciously used within its own initialization}}
+      static int v = (u += v);  // expected-warning {{static variable 'v' is suspiciously used within its own initialization}}
     }
   }
 }





More information about the cfe-commits mailing list