Make debugging information usable.  This is barebones, but it makes -g 
actually work (instead of crashing llc), and there's enough info emitted 
to get line number information in gdb. This should hopefully be helpful 
for debugging non-working programs.

I got rid of the begin/endregion calls because the implementation wasn't 
working; someone who knows the debugging info a bit better might try to 
add it. I really have no clue how a compiler is supposed to emit them.

This commit shouldn't have any effect without -g.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51404 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index e4332f6..b17572c 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -13,6 +13,7 @@
 
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CGDebugInfo.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/AST/AST.h"
 #include "llvm/CallingConv.h"
@@ -197,7 +198,16 @@
                                          EntryBB);
   
   Builder.SetInsertPoint(EntryBB);
-  
+
+  CGDebugInfo *DI = CGM.getDebugInfo();
+  if (DI) {
+    CompoundStmt* body = cast<CompoundStmt>(CurFuncDecl->getBody());
+    if (body->getLBracLoc().isValid()) {
+      DI->setLocation(body->getLBracLoc());
+    }
+    DI->EmitFunctionStart(CurFn, Builder);
+  }
+
   // Emit allocs for param decls.  Give the LLVM Argument nodes names.
   llvm::Function::arg_iterator AI = CurFn->arg_begin();
   
@@ -221,6 +231,15 @@
   if (isDummyBlock(BB))
     BB->eraseFromParent();
   else {
+    CGDebugInfo *DI = CGM.getDebugInfo();
+    if (DI) {
+      CompoundStmt* body = cast<CompoundStmt>(CurFuncDecl->getBody());
+      if (body->getRBracLoc().isValid()) {
+        DI->setLocation(body->getRBracLoc());
+      }
+      DI->EmitFunctionEnd(CurFn, Builder);
+    }
+
     // FIXME: if this is C++ main, this should return 0.
     if (CurFn->getReturnType() == llvm::Type::VoidTy)
       Builder.CreateRetVoid();