diff options
author | Devang Patel <dpatel@apple.com> | 2010-08-12 00:02:44 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-08-12 00:02:44 +0000 |
commit | caa23f0708c2c9a54b5ea42a3fb2723afa2f5801 (patch) | |
tree | 7faf7f307b96fae3f1d8255fadfb3797031c6d03 | |
parent | a3025fcd457fcff0cacb75f444d7e0e92e5bb1cd (diff) | |
download | bcm5719-llvm-caa23f0708c2c9a54b5ea42a3fb2723afa2f5801.tar.gz bcm5719-llvm-caa23f0708c2c9a54b5ea42a3fb2723afa2f5801.zip |
Emit debug info for static const class member.
llvm-svn: 110885
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 27 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/debug-info-class.cpp | 12 |
2 files changed, 37 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index bb9f1cbc8ad..6c1d321b124 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -553,7 +553,6 @@ CollectRecordFields(const RecordDecl *RD, llvm::DIFile Unit, I != E; ++I, ++FieldNo) { FieldDecl *Field = *I; llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); - llvm::StringRef FieldName = Field->getName(); // Ignore unnamed fields. Do not ignore unnamed records. @@ -573,7 +572,6 @@ CollectRecordFields(const RecordDecl *RD, llvm::DIFile Unit, Expr *BitWidth = Field->getBitWidth(); if (BitWidth) FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); - FieldAlign = CGM.getContext().getTypeAlign(FType); } @@ -894,6 +892,31 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, CollectCXXBases(CXXDecl, Unit, EltTys, FwdDecl); CollectVTableInfo(CXXDecl, Unit, EltTys); } + + // Collect static variables with initializers. + for (RecordDecl::decl_iterator I = RD->decls_begin(), E = RD->decls_end(); + I != E; ++I) + if (const VarDecl *V = dyn_cast<VarDecl>(*I)) { + if (const Expr *Init = V->getInit()) { + Expr::EvalResult Result; + if (Init->Evaluate(Result, CGM.getContext()) && Result.Val.isInt()) { + llvm::ConstantInt *CI + = llvm::ConstantInt::get(CGM.getLLVMContext(), Result.Val.getInt()); + + // Create the descriptor for static variable. + llvm::DIFile VUnit = getOrCreateFile(V->getLocation()); + llvm::StringRef VName = V->getName(); + llvm::DIType VTy = getOrCreateType(V->getType(), VUnit); + // Do not use DIGlobalVariable for enums. + if (VTy.getTag() != llvm::dwarf::DW_TAG_enumeration_type) { + DebugFactory.CreateGlobalVariable(FwdDecl, VName, VName, VName, VUnit, + getLineNumber(V->getLocation()), + VTy, true, true, CI); + } + } + } + } + CollectRecordFields(RD, Unit, EltTys); llvm::MDNode *ContainingType = NULL; if (CXXDecl) { diff --git a/clang/test/CodeGenCXX/debug-info-class.cpp b/clang/test/CodeGenCXX/debug-info-class.cpp new file mode 100644 index 00000000000..151c5f90534 --- /dev/null +++ b/clang/test/CodeGenCXX/debug-info-class.cpp @@ -0,0 +1,12 @@ +// RUN: %clang -emit-llvm -g -S %s -o - | grep HdrSize +struct A { + int one; + static const int HdrSize = 52; + int two; + A() { + int x = 1; + } +}; +int main() { + A a; +} |