.
diff --git generic/tclBasic.c generic/tclBasic.c
index da8870d928..d02b8cb076 100644
--- generic/tclBasic.c
+++ generic/tclBasic.c
@@ -8816,6 +8816,13 @@ NRCoroutineExitCallback(
*----------------------------------------------------------------------
*/
+#ifdef _MSC_VER
+#include <intrin.h> /* for _AddressOfReturnAddress() */
+#endif
+#ifndef __has_builtin
+#define __has_builtin(x) 0 /* for non-clang compilers */
+#endif
+
int
TclNRCoroutineActivateCallback(
ClientData data[],
@@ -8824,8 +8831,20 @@ TclNRCoroutineActivateCallback(
{
CoroutineData *corPtr = (CoroutineData *)data[0];
int type = PTR2INT(data[1]);
- int numLevels, unused;
+ int numLevels;
+
+/*
+ * See bug 7371b6270b: Prefer an approach which works even when
+ * AddressSanitizer (ASan) use-after-return detection is enabled.
+ */
+#ifdef _MSC_VER
+ void *stackLevel = _AddressOfReturnAddress();
+#elif defined(__GNUC__) || __has_builtin(__builtin_frame_address)
+ void *stackLevel = __builtin_frame_address(0);
+#else
+ int unused;
int *stackLevel = &unused;
+#endif
if (!corPtr->stackLevel) {
/*