[cfe-commits] r161909 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/uninitialized.cpp
Richard Trieu
rtrieu at google.com
Tue Aug 14 16:50:52 PDT 2012
Author: rtrieu
Date: Tue Aug 14 18:50:52 2012
New Revision: 161909
URL: http://llvm.org/viewvc/llvm-project?rev=161909&view=rev
Log:
Check local static variables for self reference on initialization.
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=161909&r1=161908&r2=161909&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Aug 14 18:50:52 2012
@@ -6313,7 +6313,7 @@
// by a dataflow analysis.
// Record types initialized by initializer list are handled here.
// Initialization by constructors are handled in TryConstructorInitialization.
- if (!VDecl->hasLocalStorage() && !VDecl->isStaticLocal() &&
+ if (!VDecl->hasLocalStorage() &&
(isa<InitListExpr>(Init) || !VDecl->getType()->isRecordType()))
CheckSelfReference(RealDecl, Init);
Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=161909&r1=161908&r2=161909&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninitialized.cpp Tue Aug 14 18:50:52 2012
@@ -316,3 +316,65 @@
G(char (*)[8]) : f3(new F(f3->*ptr)) {} // expected-warning {{field is uninitialized when used here}}
};
}
+
+namespace statics {
+ static int a = a; // no-warning: used to signal intended lack of initialization.
+ static int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
+ static int c = (c + c); // expected-warning 2{{variable 'c' is uninitialized when used within its own initialization}}
+ static int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
+ static int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
+
+ // Thes don't warn as they don't require the value.
+ static int g = sizeof(g);
+ int gg = g; // Silence unneeded warning
+ static void* ptr = &ptr;
+ static int h = bar(&h);
+ static int i = boo(i);
+ static int j = far(j);
+ static int k = __alignof__(k);
+
+ static int l = k ? l : l; // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}}
+ static int m = 1 + (k ? m : m); // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}}
+ static int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
+
+ void test() {
+ static int a = a; // no-warning: used to signal intended lack of initialization.
+ static int b = b + 1; // expected-warning {{variable 'b' is uninitialized when used within its own initialization}}
+ static int c = (c + c); // expected-warning 2{{variable 'c' is uninitialized when used within its own initialization}}
+ static int d = ({ d + d ;}); // expected-warning 2{{variable 'd' is uninitialized when used within its own initialization}}
+ static int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
+ static int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
+
+ // Thes don't warn as they don't require the value.
+ static int g = sizeof(g);
+ static void* ptr = &ptr;
+ static int h = bar(&h);
+ static int i = boo(i);
+ static int j = far(j);
+ static int k = __alignof__(k);
+
+ static int l = k ? l : l; // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}}
+ static int m = 1 + (k ? m : m); // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}}
+ static int n = -n; // expected-warning {{variable 'n' is uninitialized when 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 {{variable 'b' is uninitialized when used within its own initialization}}
+ static int c = (c + c); // expected-warning 2{{variable 'c' is uninitialized when used within its own initialization}}
+ static int d = ({ d + d ;}); // expected-warning 2{{variable 'd' is uninitialized when used within its own initialization}}
+ static int e = static_cast<long>(e) + 1; // expected-warning {{variable 'e' is uninitialized when used within its own initialization}}
+ static int f = foo(f); // expected-warning {{variable 'f' is uninitialized when used within its own initialization}}
+
+ // Thes don't warn as they don't require the value.
+ static int g = sizeof(g);
+ static void* ptr = &ptr;
+ static int h = bar(&h);
+ static int i = boo(i);
+ static int j = far(j);
+ static int k = __alignof__(k);
+
+ static int l = k ? l : l; // expected-warning 2{{variable 'l' is uninitialized when used within its own initialization}}
+ static int m = 1 + (k ? m : m); // expected-warning 2{{variable 'm' is uninitialized when used within its own initialization}}
+ static int n = -n; // expected-warning {{variable 'n' is uninitialized when used within its own initialization}}
+ }
+ }
+}
More information about the cfe-commits
mailing list