[cfe-commits] r110660 - in /cfe/trunk: 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

Devang Patel dpatel at apple.com
Tue Aug 10 00:24:26 PDT 2010


Author: dpatel
Date: Tue Aug 10 02:24:25 2010
New Revision: 110660

URL: http://llvm.org/viewvc/llvm-project?rev=110660&view=rev
Log:
Even if a constant's evaluated value is used, emit debug info for the constant variable.

Added:
    cfe/trunk/test/CodeGen/2010-08-10-DbgConstant.c
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.h
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=110660&r1=110659&r2=110660&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Aug 10 02:24:25 2010
@@ -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 

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=110660&r1=110659&r2=110660&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue Aug 10 02:24:25 2010
@@ -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,

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=110660&r1=110659&r2=110660&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Aug 10 02:24:25 2010
@@ -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);

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=110660&r1=110659&r2=110660&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Aug 10 02:24:25 2010
@@ -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);
+}

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=110660&r1=110659&r2=110660&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Aug 10 02:24:25 2010
@@ -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
   //===--------------------------------------------------------------------===//

Added: cfe/trunk/test/CodeGen/2010-08-10-DbgConstant.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2010-08-10-DbgConstant.c?rev=110660&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/2010-08-10-DbgConstant.c (added)
+++ cfe/trunk/test/CodeGen/2010-08-10-DbgConstant.c Tue Aug 10 02:24:25 2010
@@ -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); }





More information about the cfe-commits mailing list