diff options
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 60 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.h | 6 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 12 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 25 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 3 |
5 files changed, 48 insertions, 58 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 89e20590255..fe503982be3 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -3142,31 +3142,14 @@ CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) { } /// EmitGlobalVariable - Emit information about a global variable. -/// \param VarOrInit either the global variable itself or the initializer -/// \param D the global declaration -void CGDebugInfo::EmitGlobalVariable(llvm::Value *VarOrInit, +void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, const VarDecl *D) { assert(DebugKind >= CodeGenOptions::LimitedDebugInfo); // Create global variable debug descriptor. llvm::DIFile Unit = getOrCreateFile(D->getLocation()); unsigned LineNo = getLineNumber(D->getLocation()); - StringRef DeclName = D->getName(); - StringRef LinkageName; - bool IsLocalToUnit = true; - - // For deferred global variables, the current source location is usually - // where they are being referenced. Do not change the current source location - // to the place where they are declared, lest we get a bogus line table. - // FIXME: maybe we do not need to set the source location here at all. - if (llvm::GlobalVariable *Var = dyn_cast<llvm::GlobalVariable>(VarOrInit)) { - setLocation(D->getLocation()); - IsLocalToUnit = Var->hasInternalLinkage(); - if (D->getDeclContext() && !isa<FunctionDecl>(D->getDeclContext()) - && !isa<ObjCMethodDecl>(D->getDeclContext())) - LinkageName = Var->getName(); - if (LinkageName == DeclName) - LinkageName = StringRef(); - } + + setLocation(D->getLocation()); QualType T = D->getType(); if (T->isIncompleteArrayType()) { @@ -3178,11 +3161,18 @@ void CGDebugInfo::EmitGlobalVariable(llvm::Value *VarOrInit, T = CGM.getContext().getConstantArrayType(ET, ConstVal, ArrayType::Normal, 0); } + StringRef DeclName = D->getName(); + StringRef LinkageName; + if (D->getDeclContext() && !isa<FunctionDecl>(D->getDeclContext()) + && !isa<ObjCMethodDecl>(D->getDeclContext())) + LinkageName = Var->getName(); + if (LinkageName == DeclName) + LinkageName = StringRef(); llvm::DIDescriptor DContext = getContextDescriptor(dyn_cast<Decl>(D->getDeclContext())); llvm::DIGlobalVariable GV = DBuilder.createStaticVariable( DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit), - IsLocalToUnit, VarOrInit, + Var->hasInternalLinkage(), Var, getOrCreateStaticDataMemberDeclarationOrNull(D)); DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(GV))); } @@ -3213,16 +3203,26 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, Var->hasInternalLinkage(), Var); } -/// EmitEnumConstant - Emit debug info for an enumerator constant -void CGDebugInfo::EmitEnumConstant(const EnumConstantDecl *ECD) -{ +/// EmitGlobalVariable - Emit global variable's debug info. +void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, + llvm::Constant *Init) { assert(DebugKind >= CodeGenOptions::LimitedDebugInfo); - llvm::DIFile Unit = getOrCreateFile(ECD->getLocation()); - llvm::DIType Ty = getOrCreateType(ECD->getType(), Unit); - - const EnumDecl *ED = cast<EnumDecl>(ECD->getDeclContext()); - assert(isa<EnumType>(ED->getTypeForDecl()) && "Enum without EnumType?"); - Ty = getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit); + // Create the descriptor for the variable. + llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); + StringRef Name = VD->getName(); + llvm::DIType Ty = getOrCreateType(VD->getType(), Unit); + if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(VD)) { + const EnumDecl *ED = cast<EnumDecl>(ECD->getDeclContext()); + assert(isa<EnumType>(ED->getTypeForDecl()) && "Enum without EnumType?"); + Ty = getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit); + } + // Do not use DIGlobalVariable for enums. + if (Ty.getTag() == llvm::dwarf::DW_TAG_enumeration_type) + return; + llvm::DIGlobalVariable GV = DBuilder.createStaticVariable( + Unit, Name, Name, Unit, getLineNumber(VD->getLocation()), Ty, true, Init, + getOrCreateStaticDataMemberDeclarationOrNull(cast<VarDecl>(VD))); + DeclCache.insert(std::make_pair(VD->getCanonicalDecl(), llvm::WeakVH(GV))); } llvm::DIScope CGDebugInfo::getCurrentContextDescriptor(const Decl *D) { diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 9642a83dfdd..a8ba14b8b3f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -264,13 +264,13 @@ public: CGBuilderTy &Builder); /// EmitGlobalVariable - Emit information about a global variable. - void EmitGlobalVariable(llvm::Value *VarOrInit, const VarDecl *Decl); + void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); /// EmitGlobalVariable - Emit information about an objective-c interface. void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); - /// EmitEnumConstant - Emit information about an enumerator constant - void EmitEnumConstant(const EnumConstantDecl *ECD); + /// EmitGlobalVariable - Emit global variable's debug info. + void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init); /// \brief - Emit C++ using directive. void EmitUsingDirective(const UsingDirectiveDecl &UD); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 31da6df1efa..12aa0a2b7c4 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -967,9 +967,15 @@ CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) { // Emit as a constant. llvm::Constant *C = CGM.EmitConstantValue(result.Val, resultType, this); - // Make sure we emit a debug reference to the global variable or - // enumerator constant. - EmitValueDeclDbgValue(value, C); + // Make sure we emit a debug reference to the global variable. + // This should probably fire even for + if (isa<VarDecl>(value)) { + if (!getContext().DeclMustBeEmitted(cast<VarDecl>(value))) + EmitDeclRefExprDbgValue(refExpr, C); + } else { + assert(isa<EnumConstantDecl>(value)); + EmitDeclRefExprDbgValue(refExpr, C); + } // If we emitted a reference constant, we need to dereference that. if (resultIsReference) diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index c0357238d21..20352f9f685 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1376,27 +1376,12 @@ llvm::Value* CodeGenFunction::EmitVAListRef(const Expr* E) { return EmitLValue(E).getAddress(); } -void CodeGenFunction::EmitValueDeclDbgValue(const ValueDecl *Val, - llvm::Constant *Init) { +void CodeGenFunction::EmitDeclRefExprDbgValue(const DeclRefExpr *E, + llvm::Constant *Init) { assert (Init && "Invalid DeclRefExpr initializer!"); - CGDebugInfo *Dbg = getDebugInfo(); - if (!Dbg || - CGM.getCodeGenOpts().getDebugInfo() < CodeGenOptions::LimitedDebugInfo) - return; - - // Make sure we emit a debug reference to the global variable. - if (const VarDecl *VD = dyn_cast<VarDecl>(Val)) { - // Do not duplicate DIE entry for local variables; they are not deferred - // like global variables are. - if (VD->isFileVarDecl() && !getLangOpts().EmitAllDecls && - !getContext().DeclMustBeEmitted(Val)) - Dbg->EmitGlobalVariable(Init, VD); - - // Make sure we emit a debug reference to an enumerator constant. - } else { - assert(isa<EnumConstantDecl>(Val)); - Dbg->EmitEnumConstant(dyn_cast<EnumConstantDecl>(Val)); - } + if (CGDebugInfo *Dbg = getDebugInfo()) + if (CGM.getCodeGenOpts().getDebugInfo() >= CodeGenOptions::LimitedDebugInfo) + Dbg->EmitGlobalVariable(E->getDecl(), Init); } CodeGenFunction::PeepholeProtection diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 9913c68fcf8..20c0b82553c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -2047,8 +2047,7 @@ public: LValue EmitStmtExprLValue(const StmtExpr *E); LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); - void EmitValueDeclDbgValue(const ValueDecl *Val, llvm::Constant *Init); - + void EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::Constant *Init); //===--------------------------------------------------------------------===// // Scalar Expression Emission |