tsan: fix bug in shadow reset introduced in D128909

Correct a bug in the code that resets shadow memory introduced as part
of a previous change for the Go race detector (D128909). The bug was
that only the most recently added shadow segment was being reset, as
opposed to the entire extent of the segment created so far. This
fixes a bug identified in Google internal testing (b/240733951).

Differential Revision: https://reviews.llvm.org/D131256

GitOrigin-RevId: 24a62bfe9a497bb494aae24e33f4d8349720a9c8
diff --git a/lib/tsan/rtl/tsan_rtl.cpp b/lib/tsan/rtl/tsan_rtl.cpp
index ff3bb33..db3d945 100644
--- a/lib/tsan/rtl/tsan_rtl.cpp
+++ b/lib/tsan/rtl/tsan_rtl.cpp
@@ -603,8 +603,8 @@
     // Second and subsequent calls map heap.
     if (shadow_end <= ctx->mapped_shadow_end)
       return;
-    if (ctx->mapped_shadow_begin < shadow_begin)
-      ctx->mapped_shadow_begin = shadow_begin;
+    if (!ctx->mapped_shadow_begin || ctx->mapped_shadow_begin > shadow_begin)
+       ctx->mapped_shadow_begin = shadow_begin;
     if (shadow_begin < ctx->mapped_shadow_end)
       shadow_begin = ctx->mapped_shadow_end;
     VPrintf(2, "MapShadow begin/end = (0x%zx-0x%zx)\n",