--- Merging (from foreign repository) r68152 into '.':
U    gcc/llvm-convert.cpp
U    gcc/llvm-debug.cpp
U    gcc/llvm-debug.h

Fix nondeterminism in whether line numbers got
generated near the beginning of a function.  Now
they do, an improvement.  This allows checking
in 67884 finally:

Enable debug info at -O.  I've fixed a lot of
bugs where -g affects optimization recently; there
are currently no such cases in the llvm testsuite or
a substantial amount of other code on Darwin, which
seems sufficient to turn it on.  Woot.  I make
no claims about the quality of the generated debug
info.

Any cases where you see -g affecting optimization can
now usefully be reported as bugs.  TEST=ipodbgopt should
test this in the llvm testsuite.

llvm-svn: 68154
diff --git a/llvm-gcc-4.2/gcc/llvm-convert.cpp b/llvm-gcc-4.2/gcc/llvm-convert.cpp
index 041de44..e7da908 100644
--- a/llvm-gcc-4.2/gcc/llvm-convert.cpp
+++ b/llvm-gcc-4.2/gcc/llvm-convert.cpp
@@ -668,7 +668,7 @@
   }
   if (TheDebugInfo) {
     TheDebugInfo->EmitStopPoint(Fn, Builder.GetInsertBlock());
-    TheDebugInfo->EmitRegionEnd(Builder.GetInsertBlock());
+    TheDebugInfo->EmitRegionEnd(Builder.GetInsertBlock(), true);
   }
   if (RetVals.empty())
     Builder.CreateRetVoid();
diff --git a/llvm-gcc-4.2/gcc/llvm-debug.cpp b/llvm-gcc-4.2/gcc/llvm-debug.cpp
index dec15c0..b4db0dc 100644
--- a/llvm-gcc-4.2/gcc/llvm-debug.cpp
+++ b/llvm-gcc-4.2/gcc/llvm-debug.cpp
@@ -273,10 +273,17 @@
 
 /// EmitRegionEnd - Constructs the debug code for exiting a declarative
 /// region - "llvm.dbg.region.end."
-void DebugInfo::EmitRegionEnd(BasicBlock *CurBB) {
+void DebugInfo::EmitRegionEnd(BasicBlock *CurBB, bool EndFunction) {
   assert(!RegionStack.empty() && "Region stack mismatch, stack empty!");
   DebugFactory.InsertRegionEnd(RegionStack.back(), CurBB);
   RegionStack.pop_back();
+  // Blocks get erased; clearing these is needed for determinism, and also
+  // a good idea if the next function gets inlined.
+  if (EndFunction) {
+    PrevBB = NULL;
+    PrevLineNo = 0;
+    PrevFullPath = NULL;
+  }
 }
 
 /// EmitDeclare - Constructs the debug code for allocation of a new variable.
@@ -307,13 +314,9 @@
 }
 
 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of 
-/// source line - "llvm.dbg.stoppoint."
+/// source line - "llvm.dbg.stoppoint."  Now enabled at -O.
 void DebugInfo::EmitStopPoint(Function *Fn, BasicBlock *CurBB) {
 
-  // Do not emit line number info, for now.
-  if (optimize)
-    return;
-
   // Don't bother if things are the same as last time.
   if (PrevLineNo == CurLineNo &&
       PrevBB == CurBB &&
diff --git a/llvm-gcc-4.2/gcc/llvm-debug.h b/llvm-gcc-4.2/gcc/llvm-debug.h
index fed50a7..8f25282 100644
--- a/llvm-gcc-4.2/gcc/llvm-debug.h
+++ b/llvm-gcc-4.2/gcc/llvm-debug.h
@@ -89,7 +89,7 @@
 
   /// EmitRegionEnd - Constructs the debug code for exiting a declarative
   /// region - "llvm.dbg.region.end."
-  void EmitRegionEnd(BasicBlock *CurBB);
+  void EmitRegionEnd(BasicBlock *CurBB, bool EndFunction);
 
   /// EmitDeclare - Constructs the debug code for allocation of a new variable.
   /// region - "llvm.dbg.declare."