From 4628823864b2080c076117a1ae972d206cc63f92 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 8 Feb 2021 18:57:43 -0800 Subject: [PATCH] [release/3.1] Fix FC_NO_TAILCALL with newer compilers The C11 standard treats trivial infinite loops as undefined behavior and allows compilers to optimize them out completely. Add "volatile" on FC_NO_TAILCALL to defeat this optimization --- src/vm/ecall.cpp | 2 +- src/vm/fcall.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/ecall.cpp b/src/vm/ecall.cpp index dfeff95d6f92..c6216e837006 100644 --- a/src/vm/ecall.cpp +++ b/src/vm/ecall.cpp @@ -146,7 +146,7 @@ void ECall::PopulateManagedStringConstructors() static CrstStatic gFCallLock; // This variable is used to force the compiler not to tailcall a function. -int FC_NO_TAILCALL; +RAW_KEYWORD(volatile) int FC_NO_TAILCALL; #endif // !DACCESS_COMPILE diff --git a/src/vm/fcall.h b/src/vm/fcall.h index f15d22a166fa..b9fbb82dfb3c 100644 --- a/src/vm/fcall.h +++ b/src/vm/fcall.h @@ -928,7 +928,7 @@ void HCallAssert(void*& cache, void* target); // might do, which would otherwise confuse the epilog walker. // // * See #FC_INNER for more -extern int FC_NO_TAILCALL; +extern RAW_KEYWORD(volatile) int FC_NO_TAILCALL; #define FC_INNER_RETURN(type, expr) \ type __retVal = expr; \ while (0 == FC_NO_TAILCALL) { }; /* side effect the compile can't remove */ \