Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/coreclr/vm/excep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7310,6 +7310,7 @@ VOID DECLSPEC_NORETURN UnwindAndContinueRethrowHelperAfterCatch(Frame* pEntryFra
}
#endif // FEATURE_INTERPRETER
DispatchManagedException(orThrowable);
UNREACHABLE();
}
}
else
Expand Down
21 changes: 8 additions & 13 deletions src/coreclr/vm/exceptionhandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ static VOID UpdateContextForPropagationCallback(

extern void* g_hostingApiReturnAddress;

VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHardwareException)
VOID DispatchManagedException(PAL_SEHException& ex, bool isHardwareException)
{
if (!isHardwareException)
{
Expand Down Expand Up @@ -1563,7 +1563,7 @@ void NormalizeThrownObject(OBJECTREF *ppThrowable)
}
}

VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pExceptionContext, EXCEPTION_RECORD* pExceptionRecord)
VOID DispatchManagedException(OBJECTREF throwable, CONTEXT* pExceptionContext, EXCEPTION_RECORD* pExceptionRecord)
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
Expand Down Expand Up @@ -1639,11 +1639,9 @@ VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT* pE

GCPROTECT_END();
GCPROTECT_END();

UNREACHABLE();
}

VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable)
VOID DispatchManagedException(OBJECTREF throwable)
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
Expand All @@ -1653,10 +1651,9 @@ VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable)
ClrCaptureContext(&exceptionContext);

DispatchManagedException(throwable, &exceptionContext);
UNREACHABLE();
}

VOID DECLSPEC_NORETURN DispatchManagedException(RuntimeExceptionKind reKind)
VOID DispatchManagedException(RuntimeExceptionKind reKind)
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
Expand All @@ -1668,7 +1665,7 @@ VOID DECLSPEC_NORETURN DispatchManagedException(RuntimeExceptionKind reKind)
DispatchManagedException(throwable);
}

VOID DECLSPEC_NORETURN DispatchRethrownManagedException(CONTEXT* pExceptionContext)
VOID DispatchRethrownManagedException(CONTEXT* pExceptionContext)
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
Expand All @@ -1694,11 +1691,9 @@ VOID DECLSPEC_NORETURN DispatchRethrownManagedException(CONTEXT* pExceptionConte
DispatchExSecondPass(&exInfo);

GCPROTECT_END();

UNREACHABLE();
}

VOID DECLSPEC_NORETURN DispatchRethrownManagedException()
VOID DispatchRethrownManagedException()
{
STATIC_CONTRACT_THROWS;
STATIC_CONTRACT_GC_TRIGGERS;
Expand Down Expand Up @@ -4335,7 +4330,7 @@ static void InvokeSecondPass(ExInfo *pExInfo, uint idxStart)
InvokeSecondPass(pExInfo, idxStart, MaxTryRegionIdx);
}

void DECLSPEC_NORETURN DispatchExSecondPass(ExInfo *pExInfo)
void DispatchExSecondPass(ExInfo *pExInfo)
{
CONTRACTL
{
Expand Down Expand Up @@ -4399,7 +4394,7 @@ void DECLSPEC_NORETURN DispatchExSecondPass(ExInfo *pExInfo)

CallCatchFunclet(pExInfo->m_exception, (BYTE *)pCatchHandler, pFrameIter->m_crawl.GetRegisterSet(), pExInfo);
// CallCatchFunclet will resume after the catch and never return here.
UNREACHABLE();
//UNREACHABLE();
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commented-out UNREACHABLE() should be removed rather than left as a comment. Since this PR is specifically about removing NORETURN markings and UNREACHABLE() calls due to the compiler optimization issue, leaving this commented out is inconsistent with the other changes.

Suggested change
//UNREACHABLE();

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To better understand code flow, I believe it would be better to preserve all the UNREACHABLE statements as a comment, also explaining that this is a workaround for some unwinding issue.

}

//
Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/vm/exceptionhandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ CallDescrWorkerUnwindFrameChainHandler(IN PEXCEPTION_RECORD pExceptionRe

void NormalizeThrownObject(OBJECTREF *ppThrowable);

VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable, CONTEXT *pExceptionContext, EXCEPTION_RECORD *pExceptionRecord = NULL);
VOID DECLSPEC_NORETURN DispatchManagedException(OBJECTREF throwable);
VOID DECLSPEC_NORETURN DispatchManagedException(RuntimeExceptionKind reKind);
VOID DECLSPEC_NORETURN DispatchRethrownManagedException();
VOID DECLSPEC_NORETURN DispatchRethrownManagedException(CONTEXT* pExceptionContext);
VOID DispatchManagedException(OBJECTREF throwable, CONTEXT *pExceptionContext, EXCEPTION_RECORD *pExceptionRecord = NULL);
VOID DispatchManagedException(OBJECTREF throwable);
VOID DispatchManagedException(RuntimeExceptionKind reKind);
VOID DispatchRethrownManagedException();
VOID DispatchRethrownManagedException(CONTEXT* pExceptionContext);

void DECLSPEC_NORETURN DispatchExSecondPass(ExInfo *pExInfo);
void DispatchExSecondPass(ExInfo *pExInfo);

bool IsCallDescrWorkerInternalReturnAddress(PCODE pCode);

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/exceptmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ VOID DECLSPEC_NORETURN UnwindAndContinueResumeAfterCatch(TADDR resumeSP, TADDR r
#endif // FEATURE_INTERPRETER

#ifdef TARGET_UNIX
VOID DECLSPEC_NORETURN DispatchManagedException(PAL_SEHException& ex, bool isHardwareException);
VOID DispatchManagedException(PAL_SEHException& ex, bool isHardwareException);

#define INSTALL_MANAGED_EXCEPTION_DISPATCHER_EX \
PAL_SEHException exCopy; \
Expand Down
4 changes: 1 addition & 3 deletions src/coreclr/vm/interpexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3165,14 +3165,12 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr

pInterpreterFrame->SetIsFaulting(true);
DispatchManagedException(throwable);
UNREACHABLE();
break;
}
case INTOP_RETHROW:
{
pInterpreterFrame->SetIsFaulting(true);
DispatchRethrownManagedException();
UNREACHABLE();
break;
}
case INTOP_LOAD_EXCEPTION:
Expand Down Expand Up @@ -4131,7 +4129,7 @@ do \
GetThread()->GetExceptionState()->SetRaisingForeignException();
pInterpreterFrame->SetIsFaulting(true);
DispatchManagedException(exception);
UNREACHABLE();
break;
}
}

Expand Down