[cfe-commits] r94555 - in /cfe/trunk: include/clang/AST/Decl.h lib/CodeGen/CodeGenModule.cpp test/CodeGenCXX/static-data-member.cpp
Anders Carlsson
andersca at mac.com
Tue Jan 26 09:43:42 PST 2010
Author: andersca
Date: Tue Jan 26 11:43:42 2010
New Revision: 94555
URL: http://llvm.org/viewvc/llvm-project?rev=94555&view=rev
Log:
Use the right definition when emitting a global variable. Fixes PR5564.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/static-data-member.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=94555&r1=94554&r2=94555&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Jan 26 11:43:42 2010
@@ -620,6 +620,11 @@
/// initializer.
const Expr *getDefinition(const VarDecl *&Def) const;
+ const Expr *getDefinition() const {
+ const VarDecl* Definition;
+ return getDefinition(Definition);
+ }
+
void setThreadSpecified(bool T) { ThreadSpecified = T; }
bool isThreadSpecified() const {
return ThreadSpecified;
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=94555&r1=94554&r2=94555&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jan 26 11:43:42 2010
@@ -979,7 +979,9 @@
QualType ASTTy = D->getType();
bool NonConstInit = false;
- if (D->getInit() == 0) {
+ const Expr *InitExpr = D->getDefinition();
+
+ if (!InitExpr) {
// This is a tentative definition; tentative definitions are
// implicitly initialized with { 0 }.
//
@@ -992,10 +994,10 @@
assert(!ASTTy->isIncompleteType() && "Unexpected incomplete type");
Init = EmitNullConstant(D->getType());
} else {
- Init = EmitConstantExpr(D->getInit(), D->getType());
+ Init = EmitConstantExpr(InitExpr, D->getType());
if (!Init) {
- QualType T = D->getInit()->getType();
+ QualType T = InitExpr->getType();
if (getLangOptions().CPlusPlus) {
EmitCXXGlobalVarDeclInitFunc(D);
Init = EmitNullConstant(T);
Modified: cfe/trunk/test/CodeGenCXX/static-data-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/static-data-member.cpp?rev=94555&r1=94554&r2=94555&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/static-data-member.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/static-data-member.cpp Tue Jan 26 11:43:42 2010
@@ -1,4 +1,14 @@
// RUN: %clang_cc1 -emit-llvm -o - %s
+
+// CHECK: @_ZN1A1aE = constant i32 10
+
+// PR5564.
+struct A {
+ static const int a = 10;
+};
+
+const int A::a;
+
struct S {
static int i;
};
More information about the cfe-commits
mailing list