Repository: dotnet/runtime
File: src/coreclr/vm/prestub.cpp (C++)

Code before:
    // Argument registers are in the TransitionBlock
    // The stack arguments are right after the pTransitionBlock
    InterpThreadContext *threadContext = GetInterpThreadContext();
    int8_t *sp = threadContext->pStackPointer;

    InterpByteCodeStart* pInterpreterCode = dac_cast<PTR_InterpByteCodeStart>(byteCodeAddr);
#if (defined(PROFILING_SUPPORTED) || defined(DEBUGGER_SUPPORTED)) && !defined(FEATURE_PORTABLE_ENTRYPOINTS)
    void* thunkDataMaybe = nullptr;
#endif
#if defined(PROFILING_SUPPORTED)
    MethodDesc* methodDescToReportAsTransition = nullptr;
#endif

    if (pInterpreterCode->Method->unmanagedCallersOnly)
    {
        Thread* thread = GetThreadNULLOk();
        if (thread == NULL)
            CREATETHREAD_IF_NULL_FAILFAST(thread, W("Failed to setup new thread during reverse P/Invoke"));

        // Verify the current thread isn't in COOP mode.
        if (thread->PreemptiveGCDisabled())
            ReversePInvokeBadTransition();

#ifdef PROFILING_SUPPORTED
        if (CORProfilerTrackTransitions())
        {
            methodDescToReportAsTransition = pInterpreterCode->Method->methodHnd;
#ifndef FEATURE_PORTABLE_ENTRYPOINTS
            void* thunkDataMaybe = nullptr;
            if (pInterpreterCode->Method->publishSecretStubParam)
                thunkDataMaybe = GetMostRecentUMEntryThunkDataNonDestructive();
            if (thunkDataMaybe != NULL)
            {
                methodDescToReportAsTransition = ((UMEntryThunkData*)thunkDataMaybe)->GetMethod();
            }
#endif // FEATURE_PORTABLE_ENTRYPOINTS
            ProfilerUnmanagedToManagedTransitionMD(methodDescToReportAsTransition, COR_PRF_TRANSITION_CALL);
        }
#endif
#ifdef DEBUGGING_SUPPORTED
        if (g_TrapReturningThreads && CORDebuggerTraceCall())
        {
            void* thunkDataMaybe = nullptr;
            if (pInterpreterCode->Method->publishSecretStubParam)
                thunkDataMaybe = GetMostRecentUMEntryThunkDataNonDestructive();

            DebuggerTraceCall((void*)pInterpreterCode->GetByteCodes(), thunkDataMaybe);
        }
#endif // DEBUGGING_SUPPORTED
    }


Review comment (suggestion):
There's a variable shadowing issue here. The variable `thunkDataMaybe` is declared at line 1949 in the outer scope, but is re-declared at line 1970 within the PROFILING_SUPPORTED block, shadowing the outer variable. The outer declaration at line 1949 should be used instead of re-declaring it.

Code after:
    // Argument registers are in the TransitionBlock
    // The stack arguments are right after the pTransitionBlock
    InterpThreadContext *threadContext = GetInterpThreadContext();
    int8_t *sp = threadContext->pStackPointer;

    InterpByteCodeStart* pInterpreterCode = dac_cast<PTR_InterpByteCodeStart>(byteCodeAddr);
#if defined(PROFILING_SUPPORTED)
    MethodDesc* methodDescToReportAsTransition = nullptr;
#endif

    if (pInterpreterCode->Method->unmanagedCallersOnly)
    {
        Thread* thread = GetThreadNULLOk();
        if (thread == NULL)
            CREATETHREAD_IF_NULL_FAILFAST(thread, W("Failed to setup new thread during reverse P/Invoke"));

        // Verify the current thread isn't in COOP mode.
        if (thread->PreemptiveGCDisabled())
            ReversePInvokeBadTransition();

#ifdef PROFILING_SUPPORTED
        if (CORProfilerTrackTransitions())
        {
            methodDescToReportAsTransition = pInterpreterCode->Method->methodHnd;
#ifndef FEATURE_PORTABLE_ENTRYPOINTS
            void* thunkDataMaybe = nullptr;
            if (pInterpreterCode->Method->publishSecretStubParam)
                thunkDataMaybe = GetMostRecentUMEntryThunkDataNonDestructive();
            if (thunkDataMaybe != NULL)
            {
                methodDescToReportAsTransition = ((UMEntryThunkData*)thunkDataMaybe)->GetMethod();
            }
#endif // FEATURE_PORTABLE_ENTRYPOINTS
            ProfilerUnmanagedToManagedTransitionMD(methodDescToReportAsTransition, COR_PRF_TRANSITION_CALL);
        }
#endif
#ifdef DEBUGGING_SUPPORTED
        if (g_TrapReturningThreads && CORDebuggerTraceCall())
        {
            void* thunkDataMaybe = nullptr;
#ifndef FEATURE_PORTABLE_ENTRYPOINTS
            if (pInterpreterCode->Method->publishSecretStubParam)
                thunkDataMaybe = GetMostRecentUMEntryThunkDataNonDestructive();
#endif // FEATURE_PORTABLE_ENTRYPOINTS
            DebuggerTraceCall((void*)pInterpreterCode->GetByteCodes(), thunkDataMaybe);
        }
#endif // DEBUGGING_SUPPORTED
    }

    void* retVal;
    {