]> granicus.if.org Git - clang/commitdiff
Debug info bug fix, function start wasn't getting generated correctly
authorDaniel Dunbar <daniel@zuster.org>
Sat, 18 Oct 2008 18:22:23 +0000 (18:22 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 18 Oct 2008 18:22:23 +0000 (18:22 +0000)
for Obj-C methods.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57769 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGDebugInfo.h
lib/CodeGen/CGObjC.cpp
lib/CodeGen/CodeGenFunction.cpp
lib/CodeGen/CodeGenFunction.h

index f326be276977798891c70ac901044bc64eec67da..e1889603ee76bf3f58473dd9cd3ee63a304d235c 100644 (file)
@@ -598,7 +598,8 @@ CGDebugInfo::getOrCreateType(QualType type, llvm::CompileUnitDesc *Unit)
 
 /// EmitFunctionStart - Constructs the debug code for entering a function -
 /// "llvm.dbg.func.start.".
-void CGDebugInfo::EmitFunctionStart(const FunctionDecl *FnDecl,
+void CGDebugInfo::EmitFunctionStart(const char *Name,
+                                    QualType ReturnType,
                                     llvm::Function *Fn,
                                     llvm::IRBuilder<> &Builder)
 {
@@ -611,8 +612,8 @@ void CGDebugInfo::EmitFunctionStart(const FunctionDecl *FnDecl,
   }
 
   // Get name information.
-  Subprogram->setName(FnDecl->getName());
-  Subprogram->setFullName(FnDecl->getName());
+  Subprogram->setName(Name);
+  Subprogram->setFullName(Name);
 
   // Gather location information.
   llvm::CompileUnitDesc *Unit = getOrCreateCompileUnit(CurLoc);
@@ -620,8 +621,7 @@ void CGDebugInfo::EmitFunctionStart(const FunctionDecl *FnDecl,
   uint64_t Loc = SM.getLogicalLineNumber(CurLoc);
 
   // Get Function Type.
-  QualType type = FnDecl->getResultType();
-  llvm::TypeDesc *SPTy = getOrCreateType(type, Unit);
+  llvm::TypeDesc *SPTy = getOrCreateType(ReturnType, Unit);
 
   Subprogram->setAnchor(SubprogramAnchor);
   Subprogram->setContext(Unit);
index 22a45ce8b5042a758b9ee21c6b51ecfa1bc87fbf..9352505a96d50b4be9aa80dd26c82907467fd739 100644 (file)
@@ -110,9 +110,9 @@ public:
   void EmitStopPoint(llvm::Function *Fn, BuilderType &Builder);
 
   /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
-  /// start of a new function
-  void EmitFunctionStart(const FunctionDecl *FnDecl, llvm::Function *Fn,
-                         BuilderType &Builder);
+  /// start of a new function.
+  void EmitFunctionStart(const char *Name, QualType ReturnType,
+                         llvm::Function *Fn, BuilderType &Builder);
   
   /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
   /// of a new block.  
index 0c45c555544fccbfadf6ffce9634989344c12299..c0260ad06b3a19c5bf115927070519c1e5012f51 100644 (file)
@@ -119,7 +119,7 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD) {
     Args.push_back(std::make_pair(IPD, IPD->getType()));
   }
 
-  StartFunction(OMD, OMD->getResultType(), Fn, Args);
+  StartFunction(OMD, OMD->getResultType(), Fn, Args, OMD->getLocEnd());
 }
 
 /// Generate an Objective-C method.  An Objective-C method is a C function with
@@ -127,13 +127,7 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD) {
 void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) {
   StartObjCMethod(OMD);
   EmitStmt(OMD->getBody());
-
-  const CompoundStmt *S = dyn_cast<CompoundStmt>(OMD->getBody());
-  if (S) {
-    FinishFunction(S->getRBracLoc());
-  } else {
-    FinishFunction();
-  }
+  FinishFunction(cast<CompoundStmt>(OMD->getBody())->getRBracLoc());
 }
 
 // FIXME: I wasn't sure about the synthesis approach. If we end up
index 12e468c12706c2c446c4a9569cc327aa75cd19a3..2ee08eae17ceb91e41e71222ba38b27af7718711 100644 (file)
@@ -98,7 +98,8 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
 
 void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy, 
                                     llvm::Function *Fn,
-                                    const FunctionArgList &Args) {
+                                    const FunctionArgList &Args,
+                                    SourceLocation StartLoc) {
   CurFuncDecl = D;
   FnRetTy = RetTy;
   CurFn = Fn;
@@ -122,11 +123,14 @@ void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy,
   
   // Emit subprogram debug descriptor.
   // FIXME: The cast here is a huge hack.
-  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
-    if (CGDebugInfo *DI = CGM.getDebugInfo()) {
-      if (CompoundStmt* body = dyn_cast<CompoundStmt>(FD->getBody()))
-        DI->setLocation(body->getLBracLoc());
-      DI->EmitFunctionStart(FD, CurFn, Builder);
+  if (CGDebugInfo *DI = CGM.getDebugInfo()) {
+    DI->setLocation(StartLoc);
+    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+      DI->EmitFunctionStart(FD->getName(), RetTy, CurFn, Builder);
+    } else {
+      // Just use LLVM function name.
+      DI->EmitFunctionStart(Fn->getName().c_str(), 
+                            RetTy, CurFn, Builder);
     }
   }
 
@@ -145,7 +149,8 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD,
                                     FProto->getArgType(i)));
   }
 
-  StartFunction(FD, FD->getResultType(), Fn, Args);
+  StartFunction(FD, FD->getResultType(), Fn, Args,
+                cast<CompoundStmt>(FD->getBody())->getLBracLoc());
 
   EmitStmt(FD->getBody());
   
index c0a5a44b69bd69f1bc006ddb57135ef72bbee618..d57efa94f5722ec0274472cb4cfc226d186070fa 100644 (file)
@@ -184,7 +184,8 @@ public:
                     llvm::Function *Fn);
   void StartFunction(const Decl *D, QualType RetTy, 
                      llvm::Function *Fn,
-                     const FunctionArgList &Args);
+                     const FunctionArgList &Args,
+                     SourceLocation StartLoc);
   void FinishFunction(SourceLocation EndLoc=SourceLocation());
 
   /// EmitFunctionProlog - Emit the target specific LLVM code to load