]> granicus.if.org Git - clang/commitdiff
Make sure volatile variables are emitted even if static. Fixes rdar://8315219
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 25 Aug 2010 10:15:24 +0000 (10:15 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 25 Aug 2010 10:15:24 +0000 (10:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112043 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
test/CodeGen/volatile.c

index 37ef59cc36fc87d8b0fd8573372f0a2c29599aea..e9ca7ddb488abbf3460ee88e7f63ea485e3fd829 100644 (file)
@@ -5606,6 +5606,10 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
   if (VD->isThisDeclarationADefinition() == VarDecl::DeclarationOnly)
     return false;
 
+  // Always emit volatiles.
+  if (VD->getType().isVolatileQualified())
+    return true;
+
   // Structs that have non-trivial constructors or destructors are required.
 
   // FIXME: Handle references.
index 1a996defcf0107ed34fe502a20112add25905711..a6c17b00419e2269dbe382ab484e960a497d5660 100644 (file)
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -emit-llvm < %s -o %t
 // RUN: grep volatile %t | count 28
 // RUN: grep memcpy %t | count 7
+// RUN: %clang_cc1 %s -Wall -verify -emit-llvm -o - | FileCheck %s
 
 // The number 28 comes from the current codegen for volatile loads;
 // if this number changes, it's not necessarily something wrong, but
@@ -96,5 +97,9 @@ int main() {
   (void)vF2;
   vF2 = vF2;
   vF2 = vF2 = vF2;
-  vF2 = (vF2, vF2);
+  vF2 = (vF2, vF2); // expected-warning {{expression result unused}}
 }
+
+// Make sure this is emitted. rdar://8315219
+// CHECK: @gvx
+static volatile int gvx = 0;