]> granicus.if.org Git - clang/commitdiff
Even if a constant's evaluated value is used, emit debug info for the constant variable.
authorDevang Patel <dpatel@apple.com>
Tue, 10 Aug 2010 07:24:25 +0000 (07:24 +0000)
committerDevang Patel <dpatel@apple.com>
Tue, 10 Aug 2010 07:24:25 +0000 (07:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110660 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h
lib/CodeGen/CGExprScalar.cpp
lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h
test/CodeGen/2010-08-10-DbgConstant.c [new file with mode: 0644]

index c54196cc27edb966ce8b77aded1701b996104d2f..5ec68c0ff00c180eda6403a37c5d9bb9127a5d36 100644 (file)
@@ -1801,6 +1801,17 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
                                     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 
index b20506d47031ecfb0bd837112156cb31b8afb5c2..4df2ab62f82f5b74711cfff6530677a1371db473 100644 (file)
@@ -181,6 +181,10 @@ public:
   /// 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,
index c9e4dbd14052cc8ee937e52077b983b98dc8ff44..f6f126a8a621c9c89b6a335e6cd2069c306a982a 100644 (file)
@@ -149,6 +149,7 @@ public:
     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);
index a3cd4f4c29c0e8793941510ba0e0e0a320a2c227..f992aa72e2e7a4e01b6d95b7d491d8d1ed178790 100644 (file)
@@ -1284,3 +1284,17 @@ llvm::Value *CodeGenFunction::getEHCleanupDestSlot() {
       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);
+}
index af7e0696f492b78d5fea13166092d0eb72b091b4..e0673d991742f2e07b1dc93566166185739a8472 100644 (file)
@@ -41,6 +41,7 @@ namespace llvm {
 }
 
 namespace clang {
+  class APValue;
   class ASTContext;
   class CXXDestructorDecl;
   class CXXTryStmt;
@@ -1372,7 +1373,7 @@ public:
   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
   //===--------------------------------------------------------------------===//
diff --git a/test/CodeGen/2010-08-10-DbgConstant.c b/test/CodeGen/2010-08-10-DbgConstant.c
new file mode 100644 (file)
index 0000000..2853685
--- /dev/null
@@ -0,0 +1,5 @@
+// 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); }