[PATCH] D28543: Elliminates uninitialized warning for volitile varibles.

CJ DiMeglio via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 11 13:26:33 PST 2017


lethalantidote updated this revision to Diff 84016.
lethalantidote marked an inline comment as done.
lethalantidote added a comment.

Addresses thakis' comments and adds a test.


https://reviews.llvm.org/D28543

Files:
  clang/lib/Sema/AnalysisBasedWarnings.cpp
  clang/test/Sema/uninit-variables.c


Index: clang/test/Sema/uninit-variables.c
===================================================================
--- clang/test/Sema/uninit-variables.c
+++ clang/test/Sema/uninit-variables.c
@@ -22,7 +22,7 @@
 int test4() {
   int x; // expected-note{{initialize the variable 'x' to silence this warning}}
   ++x; // expected-warning{{variable 'x' is uninitialized when used here}}
-  return x; 
+  return x;
 }
 
 int test5() {
@@ -442,6 +442,11 @@
 struct { struct { void *p; } a; } test55 = { { &test55.a }}; // no-warning
 struct { struct { void *p; } a; } test56 = { { &(test56.a) }}; // no-warning
 
+int test57() {
+  volatile int x;
+  return x; // no-warning
+}
+
 void uninit_in_loop() {
   int produce(void);
   void consume(int);
Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===================================================================
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -80,7 +80,7 @@
       }
 
       S.Diag(L, diag) << R1 << R2;
-      
+
       SourceLocation Open = SilenceableCondVal.getBegin();
       if (Open.isValid()) {
         SourceLocation Close = SilenceableCondVal.getEnd();
@@ -696,6 +696,9 @@
 
   switch (Use.getKind()) {
   case UninitUse::Always:
+    if (VD->getType().isVolatileQualified()) {
+      return;
+    }
     S.Diag(Use.getUser()->getLocStart(), diag::warn_uninit_var)
         << VD->getDeclName() << IsCapturedByBlock
         << Use.getUser()->getSourceRange();
@@ -864,7 +867,7 @@
 /// false.
 static bool DiagnoseUninitializedUse(Sema &S, const VarDecl *VD,
                                      const UninitUse &Use,
-                                     bool alwaysReportSelfInit = false) {
+                                     bool alwaysReportSelfInit = false) { 
   if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Use.getUser())) {
     // Inspect the initializer of the variable declaration which is
     // being referenced prior to its initialization. We emit


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28543.84016.patch
Type: text/x-patch
Size: 1990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170111/2eab7889/attachment.bin>


More information about the cfe-commits mailing list