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
/// 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,
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);
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);
+}
}
namespace clang {
+ class APValue;
class ASTContext;
class CXXDestructorDecl;
class CXXTryStmt;
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
//===--------------------------------------------------------------------===//
--- /dev/null
+// RUN: %clang_cc1 -S -emit-llvm -g %s -o - | grep DW_TAG_constant
+
+static const unsigned int ro = 201;
+void bar(int);
+void foo() { bar(ro); }