Make sure volatile variables are emitted even if static. Fixes rdar://8315219
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112043 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 37ef59c..e9ca7dd 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -5606,6 +5606,10 @@
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.
diff --git a/test/CodeGen/volatile.c b/test/CodeGen/volatile.c
index 1a996de..a6c17b0 100644
--- a/test/CodeGen/volatile.c
+++ b/test/CodeGen/volatile.c
@@ -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 @@
(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;