Even if a constant's evaluated value is used, emit debug info for the constant variable.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110660 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
index c54196c..5ec68c0 100644
--- a/lib/CodeGen/CGDebugInfo.cpp
+++ b/lib/CodeGen/CGDebugInfo.cpp
@@ -1801,6 +1801,17 @@
true/*definition*/, Var);
}
+void CGDebugInfo::EmitGlobalVariable(llvm::Constant *C, const ValueDecl *VD,
+ CGBuilderTy &Builder) {
+ // Create the descriptor for the variable.
+ llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
+ llvm::StringRef Name = VD->getName();
+ DebugFactory.CreateGlobalVariable(Unit, Name, Name, Name, Unit,
+ getLineNumber(VD->getLocation()),
+ getOrCreateType(VD->getType(), Unit),
+ true, true, C);
+}
+
/// getOrCreateNamesSpace - Return namespace descriptor for the given
/// namespace decl.
llvm::DINameSpace
diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h
index b20506d..4df2ab6 100644
--- a/lib/CodeGen/CGDebugInfo.h
+++ b/lib/CodeGen/CGDebugInfo.h
@@ -181,6 +181,10 @@
/// EmitGlobalVariable - Emit information about an objective-c interface.
void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
+ /// EmitGlobalVariable - Emit information about a constant.
+ void EmitGlobalVariable(llvm::Constant *C, const ValueDecl *VD,
+ CGBuilderTy &Builder);
+
private:
/// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index c9e4dbd..f6f126a 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -149,6 +149,7 @@
Expr::EvalResult Result;
if (E->Evaluate(Result, CGF.getContext()) && Result.Val.isInt()) {
assert(!Result.HasSideEffects && "Constant declref with side-effect?!");
+ CGF.EmitDeclRefExprDbgValue(E, Result.Val);
return llvm::ConstantInt::get(VMContext, Result.Val.getInt());
}
return EmitLoadOfLValue(E);
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index a3cd4f4..f992aa7 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -1284,3 +1284,17 @@
CreateTempAlloca(Builder.getInt32Ty(), "eh.cleanup.dest.slot");
return EHCleanupDest;
}
+
+void CodeGenFunction::EmitDeclRefExprDbgValue(const DeclRefExpr *E,
+ const APValue &AV) {
+ CGDebugInfo *Dbg = getDebugInfo();
+ if (!Dbg) return;
+
+ llvm::Constant *C = NULL;
+ if (AV.isInt())
+ C = llvm::ConstantInt::get(getLLVMContext(), AV.getInt());
+ else if (AV.isFloat())
+ C = llvm::ConstantFP::get(getLLVMContext(), AV.getFloat());
+ if (C)
+ Dbg->EmitGlobalVariable(C, E->getDecl(), Builder);
+}
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index af7e069..e0673d9 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -41,6 +41,7 @@
}
namespace clang {
+ class APValue;
class ASTContext;
class CXXDestructorDecl;
class CXXTryStmt;
@@ -1372,7 +1373,7 @@
LValue EmitStmtExprLValue(const StmtExpr *E);
LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E);
LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E);
-
+ void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &AV);
//===--------------------------------------------------------------------===//
// Scalar Expression Emission
//===--------------------------------------------------------------------===//