[cfe-commits] r172888 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/uninitialized.cpp

Ted Kremenek kremenek at apple.com
Fri Jan 18 20:33:15 PST 2013


Author: kremenek
Date: Fri Jan 18 22:33:14 2013
New Revision: 172888

URL: http://llvm.org/viewvc/llvm-project?rev=172888&view=rev
Log:
Reapply r172878 with test case.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/uninitialized.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=172888&r1=172887&r2=172888&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Jan 18 22:33:14 2013
@@ -259,7 +259,9 @@
 def Unicode  : DiagGroup<"unicode">;
 def UninitializedMaybe : DiagGroup<"conditional-uninitialized">;
 def UninitializedSometimes : DiagGroup<"sometimes-uninitialized">;
-def Uninitialized  : DiagGroup<"uninitialized", [UninitializedSometimes]>;
+def UninitializedStaticSelfInit : DiagGroup<"static-self-init">;
+def Uninitialized  : DiagGroup<"uninitialized", [UninitializedSometimes,
+                                                 UninitializedStaticSelfInit]>;
 def UnknownPragmas : DiagGroup<"unknown-pragmas">;
 def UnknownWarningOption : DiagGroup<"unknown-warning-option">;
 def NSobjectAttribute : DiagGroup<"NSObject-attribute">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=172888&r1=172887&r2=172888&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jan 18 22:33:14 2013
@@ -1292,6 +1292,9 @@
 def warn_reference_field_is_uninit : Warning<
   "reference %0 is not yet bound to a value when used here">,
   InGroup<Uninitialized>;
+def warn_static_self_reference_in_init : Warning<
+  "static variable %0 is suspiciously used within its own initialization">,
+  InGroup<UninitializedStaticSelfInit>;
 def warn_uninit_self_reference_in_init : Warning<
   "variable %0 is uninitialized when used within its own initialization">,
   InGroup<Uninitialized>;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=172888&r1=172887&r2=172888&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan 18 22:33:14 2013
@@ -6685,9 +6685,15 @@
     void HandleDeclRefExpr(DeclRefExpr *DRE) {
       Decl* ReferenceDecl = DRE->getDecl();
       if (OrigDecl != ReferenceDecl) return;
-      unsigned diag = isReferenceType
-          ? diag::warn_uninit_self_reference_in_reference_init
-          : diag::warn_uninit_self_reference_in_init;
+      unsigned diag;
+      if (isReferenceType) {
+        diag = diag::warn_uninit_self_reference_in_reference_init;
+      } else if (cast<VarDecl>(OrigDecl)->isStaticLocal()) {
+        diag = diag::warn_static_self_reference_in_init;
+      } else {
+        diag = diag::warn_uninit_self_reference_in_init;
+      }
+
       S.DiagRuntimeBehavior(DRE->getLocStart(), DRE,
                             S.PDiag(diag)
                               << DRE->getNameInfo().getName()

Modified: cfe/trunk/test/SemaCXX/uninitialized.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninitialized.cpp?rev=172888&r1=172887&r2=172888&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninitialized.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninitialized.cpp Fri Jan 18 22:33:14 2013
@@ -406,11 +406,11 @@
 
   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}}
+    static int b = b + 1; // expected-warning {{static variable 'b' is suspiciously used within its own initialization}}
+    static int c = (c + c); // expected-warning 2{{static variable 'c' is suspiciously used within its own initialization}}
+    static int d = ({ d + d ;}); // expected-warning 2{{static variable 'd' is suspiciously used within its own initialization}}
+    static int e = static_cast<long>(e) + 1; // expected-warning {{static variable 'e' is suspiciously used within its own initialization}}
+    static int f = foo(f); // expected-warning {{static variable 'f' is suspiciously used within its own initialization}}
 
     // Thes don't warn as they don't require the value.
     static int g = sizeof(g);
@@ -420,16 +420,16 @@
     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}}
+    static int l = k ? l : l;  // expected-warning 2{{static variable 'l' is suspiciously used within its own initialization}}
+    static int m = 1 + (k ? m : m);  // expected-warning 2{{static variable 'm' is suspiciously used within its own initialization}}
+    static int n = -n;  // expected-warning {{static variable 'n' 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 {{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}}
+      static int b = b + 1; // expected-warning {{static variable 'b' is suspiciously used within its own initialization}}
+      static int c = (c + c); // expected-warning 2{{static variable 'c' is suspiciously used within its own initialization}}
+      static int d = ({ d + d ;}); // expected-warning 2{{static variable 'd' is suspiciously used within its own initialization}}
+      static int e = static_cast<long>(e) + 1; // expected-warning {{static variable 'e' is suspiciously used within its own initialization}}
+      static int f = foo(f); // expected-warning {{static variable 'f' is suspiciously used within its own initialization}}
 
       // Thes don't warn as they don't require the value.
       static int g = sizeof(g);
@@ -439,9 +439,9 @@
       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}}
+      static int l = k ? l : l;  // expected-warning 2{{static variable 'l' is suspiciously used within its own initialization}}
+      static int m = 1 + (k ? m : m); // expected-warning 2{{static variable 'm' is suspiciously used within its own initialization}}
+      static int n = -n;  // expected-warning {{static variable 'n' is suspiciously used within its own initialization}}
     }
   }
 }





More information about the cfe-commits mailing list