From 20275aa647c5733bc5b1929cba3fd1094c67fb1d Mon Sep 17 00:00:00 2001 From: Phil Christensen Date: Thu, 1 Dec 2016 03:53:23 -0800 Subject: fix permissive C++ code (MSVC /permissive-) (#8337) * fix permissive C++ code (MSVC /permissive-) These were found by the C++ compiler group when doing "Real world code" build tests using /permissive-. We are sharing these with you to help you clean up your code before the new version of the compiler comes out. For more information on /permissive- see https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/. ---------------------------- Under /permissive-, skipping the initialization of a variable is not allowed. As an extension the compiler allowed this when there was no destructor for the type. void func(bool b) { if(b) goto END; int value = 0; //error C2362: initialization of 'value' is skipped by 'goto END' int array[10]; //Okay, not initialized. //... value used here END: return; } Fix 1) Limit the scope of value: { int value = 0; //... value used here } END: Fix 2) Initialize/declare value before the 'goto' int value = 0; if(b) goto END; //... value used here END: Fix 3) Don't initialize value in the variable declaration. int value; value = 0 //... value used here END: ------------------- Alternative token representations. The following are reserved as alternative representations for operators: and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq //Can't use reserved names for variables: static int and = 0; // Change name (possibly to 'and_') void func() { _asm { xor edx,edx // xor is reserved, change to uppercase XOR or eax,eax // or is reserved, change to uppercase OR } } * Apply formatting patch. * fixes from code review. I addressed @janvorli requests from the pull request code review. --- src/vm/excep.cpp | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'src/vm/excep.cpp') diff --git a/src/vm/excep.cpp b/src/vm/excep.cpp index c161c47785..b7c55d38a7 100644 --- a/src/vm/excep.cpp +++ b/src/vm/excep.cpp @@ -9916,47 +9916,48 @@ PTR_EHWatsonBucketTracker GetWatsonBucketTrackerForPreallocatedException(OBJECTR goto doValidation; } - // Find the reference to the exception tracker corresponding to the preallocated exception, - // starting the search from the current exception tracker (2nd arg of NULL specifies that). -#if defined(WIN64EXCEPTIONS) - PTR_ExceptionTracker pEHTracker = NULL; - PTR_ExceptionTracker pPreviousEHTracker = NULL; + { + // Find the reference to the exception tracker corresponding to the preallocated exception, + // starting the search from the current exception tracker (2nd arg of NULL specifies that). + #if defined(WIN64EXCEPTIONS) + PTR_ExceptionTracker pEHTracker = NULL; + PTR_ExceptionTracker pPreviousEHTracker = NULL; #elif _TARGET_X86_ - PTR_ExInfo pEHTracker = NULL; - PTR_ExInfo pPreviousEHTracker = NULL; + PTR_ExInfo pEHTracker = NULL; + PTR_ExInfo pPreviousEHTracker = NULL; #else // !(_WIN64 || _TARGET_X86_) #error Unsupported platform #endif // _WIN64 - if (fStartSearchFromPreviousTracker) - { - // Get the exception tracker previous to the current one - pPreviousEHTracker = GetThread()->GetExceptionState()->GetCurrentExceptionTracker()->GetPreviousExceptionTracker(); + if (fStartSearchFromPreviousTracker) + { + // Get the exception tracker previous to the current one + pPreviousEHTracker = GetThread()->GetExceptionState()->GetCurrentExceptionTracker()->GetPreviousExceptionTracker(); + + // If there is no previous tracker to start from, then simply abort the search attempt. + // If we couldnt find the exception tracker, then buckets are not available + if (pPreviousEHTracker == NULL) + { + LOG((LF_EH, LL_INFO100, "GetWatsonBucketTrackerForPreallocatedException - Couldnt find the previous EHTracker to start the search from.\n")); + pWBTracker = NULL; + goto done; + } + } + + pEHTracker = GetEHTrackerForPreallocatedException(gc.oPreAllocThrowable, pPreviousEHTracker); - // If there is no previous tracker to start from, then simply abort the search attempt. // If we couldnt find the exception tracker, then buckets are not available - if (pPreviousEHTracker == NULL) + if (pEHTracker == NULL) { - LOG((LF_EH, LL_INFO100, "GetWatsonBucketTrackerForPreallocatedException - Couldnt find the previous EHTracker to start the search from.\n")); + LOG((LF_EH, LL_INFO100, "GetWatsonBucketTrackerForPreallocatedException - Couldnt find EHTracker for preallocated exception object.\n")); pWBTracker = NULL; goto done; } - } - pEHTracker = GetEHTrackerForPreallocatedException(gc.oPreAllocThrowable, pPreviousEHTracker); - - // If we couldnt find the exception tracker, then buckets are not available - if (pEHTracker == NULL) - { - LOG((LF_EH, LL_INFO100, "GetWatsonBucketTrackerForPreallocatedException - Couldnt find EHTracker for preallocated exception object.\n")); - pWBTracker = NULL; - goto done; + // Get the Watson Bucket Tracker from the exception tracker + pWBTracker = pEHTracker->GetWatsonBucketTracker(); } - - // Get the Watson Bucket Tracker from the exception tracker - pWBTracker = pEHTracker->GetWatsonBucketTracker(); - doValidation: _ASSERTE(pWBTracker != NULL); -- cgit v1.2.3