tsan: Go runtime: support goroutine end event


git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@160282 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/tsan/go/test.c b/lib/tsan/go/test.c
index c27a94a..c6c21a1 100644
--- a/lib/tsan/go/test.c
+++ b/lib/tsan/go/test.c
@@ -2,6 +2,7 @@
 
 void __tsan_init();
 void __tsan_fini();
+void __tsan_event(int typ, int tid, void *pc, void *addr, int info);
 
 int goCallbackCommentPc(void *pc, char **img, char **rtn, char **file, int *l) {
   return 0;
@@ -9,6 +10,10 @@
 
 int main(void) {
   __tsan_init();
+  __tsan_event(1, 0, 0, &main, 0);  // READ
+  __tsan_event(11, 1, 0, 0, 0);  // THR_START
+  __tsan_event(11, 0, 0, &main, 0);  // READ
+  __tsan_event(13, 1, 0, 0, 0);  // THR_END
   printf("OK\n");
   __tsan_fini();
   return 0;
diff --git a/lib/tsan/go/tsan_go.cc b/lib/tsan/go/tsan_go.cc
index 13cc569..de69709 100644
--- a/lib/tsan/go/tsan_go.cc
+++ b/lib/tsan/go/tsan_go.cc
@@ -210,6 +210,12 @@
     thr->in_rtl--;
     break;
   }
+  case THR_END: {
+    thr->in_rtl++;
+    ThreadFinish(thr);
+    thr->in_rtl--;
+    break;
+  }
   default:
     Printf("Unknown event type %d\n", typ);
     Die();