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/ceemain.cpp | 16 +++++++------ src/vm/clrprivbinderwinrt.cpp | 11 +++++---- src/vm/encee.cpp | 15 ++++++------ src/vm/excep.cpp | 55 ++++++++++++++++++++++--------------------- src/vm/i386/cgenx86.cpp | 3 ++- src/vm/mlinfo.cpp | 4 +++- src/vm/util.cpp | 25 ++++++++++---------- src/vm/win32threadpool.cpp | 4 +++- 8 files changed, 73 insertions(+), 60 deletions(-) (limited to 'src/vm') diff --git a/src/vm/ceemain.cpp b/src/vm/ceemain.cpp index 67fa33cebb..b16d7972be 100644 --- a/src/vm/ceemain.cpp +++ b/src/vm/ceemain.cpp @@ -1933,15 +1933,17 @@ void STDMETHODCALLTYPE EEShutDownHelper(BOOL fIsDllUnloading) #endif #ifdef FEATURE_PREJIT - // If we're doing basic block profiling, we need to write the log files to disk. - - static BOOL fIBCLoggingDone = FALSE; - if (!fIBCLoggingDone) { - if (g_IBCLogger.InstrEnabled()) - Module::WriteAllModuleProfileData(true); + // If we're doing basic block profiling, we need to write the log files to disk. + + static BOOL fIBCLoggingDone = FALSE; + if (!fIBCLoggingDone) + { + if (g_IBCLogger.InstrEnabled()) + Module::WriteAllModuleProfileData(true); - fIBCLoggingDone = TRUE; + fIBCLoggingDone = TRUE; + } } #endif // FEATURE_PREJIT diff --git a/src/vm/clrprivbinderwinrt.cpp b/src/vm/clrprivbinderwinrt.cpp index b82d46cdab..b4fb45c083 100644 --- a/src/vm/clrprivbinderwinrt.cpp +++ b/src/vm/clrprivbinderwinrt.cpp @@ -287,7 +287,8 @@ HRESULT CLRPrivBinderWinRT::BindWinRTAssemblyByName( { STANDARD_VM_CONTRACT; HRESULT hr = S_OK; - ReleaseHolder pAssembly; + ReleaseHolder pAssembly; + LPWSTR wszFullTypeName = nullptr; #ifndef FEATURE_CORECLR NewArrayHolder wszAssemblySimpleName; #endif @@ -319,11 +320,13 @@ HRESULT CLRPrivBinderWinRT::BindWinRTAssemblyByName( IfFailGo(fusion::util::GetProperty(pAssemblyName, ASM_NAME_NAME, &wszAssemblySimpleName)); #else WCHAR wszAssemblySimpleName[_MAX_PATH]; - DWORD cchAssemblySimpleName = _MAX_PATH; - IfFailGo(pAssemblyName->GetName(&cchAssemblySimpleName, wszAssemblySimpleName)); + { + DWORD cchAssemblySimpleName = _MAX_PATH; + IfFailGo(pAssemblyName->GetName(&cchAssemblySimpleName, wszAssemblySimpleName)); + } #endif - LPWSTR wszFullTypeName = wcschr(wszAssemblySimpleName, W('!')); + wszFullTypeName = wcschr(wszAssemblySimpleName, W('!')); if (wszFullTypeName != nullptr) { diff --git a/src/vm/encee.cpp b/src/vm/encee.cpp index ca4e7fe553..7f12643340 100644 --- a/src/vm/encee.cpp +++ b/src/vm/encee.cpp @@ -149,7 +149,11 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( HRESULT hr = S_OK; HENUMInternal enumENC; - + + BYTE *pLocalILMemory = NULL; + IMDInternalImport *pMDImport = NULL; + IMDInternalImport *pNewMDImport = NULL; + CONTRACT_VIOLATION(GCViolation); // SafeComHolder goes to preemptive mode, which will trigger a GC SafeComHolder pIMDInternalImportENC; SafeComHolder pEmitter; @@ -175,8 +179,7 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( IfFailGo(hr); // Grab the current importer. - IMDInternalImport *pMDImport = GetMDImport(); - IMDInternalImport *pNewMDImport; + pMDImport = GetMDImport(); // Apply the EnC delta to this module's metadata. IfFailGo(pMDImport->ApplyEditAndContinue(pDeltaMD, cbDeltaMD, &pNewMDImport)); @@ -195,7 +198,7 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( IfFailGo(GetMetaDataPublicInterfaceFromInternal(pMDImport, IID_IMetaDataEmit, (void **)&pEmitter)); // Copy the deltaIL into our RVAable IL memory - BYTE *pLocalILMemory = new BYTE[cbDeltaIL]; + pLocalILMemory = new BYTE[cbDeltaIL]; memcpy(pLocalILMemory, pDeltaIL, cbDeltaIL); // Enumerate all of the EnC delta tokens @@ -203,7 +206,6 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( IfFailGo(pIMDInternalImportENC->EnumDeltaTokensInit(&enumENC)); mdToken token; - FieldDesc * pField = NULL; while (pIMDInternalImportENC->EnumNext(&enumENC, &token)) { STRESS_LOG3(LF_ENC, LL_INFO100, "EACM::AEAC: updated token 0x%x; type 0x%x; rid 0x%x\n", token, TypeFromToken(token), RidFromToken(token)); @@ -248,8 +250,7 @@ HRESULT EditAndContinueModule::ApplyEditAndContinue( // FieldDef token - add a new field LOG((LF_ENC, LL_INFO10000, "EACM::AEAC: Found field 0x%x\n", token)); - pField = LookupFieldDef(token); - if (pField) + if (LookupFieldDef(token)) { // Field already exists - just ignore for now continue; 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); diff --git a/src/vm/i386/cgenx86.cpp b/src/vm/i386/cgenx86.cpp index cefeeef0f0..8864b025ae 100644 --- a/src/vm/i386/cgenx86.cpp +++ b/src/vm/i386/cgenx86.cpp @@ -1784,13 +1784,14 @@ DWORD GetLogicalCpuCount() PAL_TRY(Param *, pParam, ¶m) { unsigned char buffer[16]; + DWORD* dwBuffer = NULL; DWORD maxCpuId = getcpuid(0, buffer); if (maxCpuId < 1) goto lDone; - DWORD* dwBuffer = (DWORD*)buffer; + dwBuffer = (DWORD*)buffer; if (dwBuffer[1] == 'uneG') { if (dwBuffer[3] == 'Ieni') { diff --git a/src/vm/mlinfo.cpp b/src/vm/mlinfo.cpp index ab2545296e..74bd536969 100644 --- a/src/vm/mlinfo.cpp +++ b/src/vm/mlinfo.cpp @@ -4865,6 +4865,8 @@ void ArrayMarshalInfo::InitForHiddenLengthArray(TypeHandle thElement) { STANDARD_VM_CONTRACT; + MethodTable *pMT = NULL; + // WinRT supports arrays of any WinRT-legal types if (thElement.IsArray()) { @@ -4877,7 +4879,7 @@ void ArrayMarshalInfo::InitForHiddenLengthArray(TypeHandle thElement) m_thElement = thElement; - MethodTable *pMT = thElement.GetMethodTable(); + pMT = thElement.GetMethodTable(); if (pMT->IsString()) { m_vtElement = VTHACK_HSTRING; diff --git a/src/vm/util.cpp b/src/vm/util.cpp index a7c264fb67..a96a56cd58 100644 --- a/src/vm/util.cpp +++ b/src/vm/util.cpp @@ -1950,17 +1950,18 @@ size_t GetLogicalProcessorCacheSizeFromOS() // Crack the information. Iterate through all the SLPI array entries for all processors in system. // Will return the greatest of all the processor cache sizes or zero - - size_t last_cache_size = 0; - - for (DWORD i=0; i < nEntries; i++) { - if (pslpi[i].Relationship == RelationCache) + size_t last_cache_size = 0; + + for (DWORD i=0; i < nEntries; i++) { - last_cache_size = max(last_cache_size, pslpi[i].Cache.Size); - } - } - cache_size = last_cache_size; + if (pslpi[i].Relationship == RelationCache) + { + last_cache_size = max(last_cache_size, pslpi[i].Cache.Size); + } + } + cache_size = last_cache_size; + } Exit: if(pslpi) @@ -1991,6 +1992,9 @@ DWORD GetLogicalCpuCountFromOS() DWORD nEntries = 0; + DWORD prevcount = 0; + DWORD count = 1; + // Try to use GetLogicalProcessorInformation API and get a valid pointer to the SLPI array if successful. Returns NULL // if API not present or on failure. SYSTEM_LOGICAL_PROCESSOR_INFORMATION *pslpi = IsGLPISupported(&nEntries) ; @@ -2001,9 +2005,6 @@ DWORD GetLogicalCpuCountFromOS() goto lDone; } - DWORD prevcount = 0; - DWORD count = 1; - for (DWORD j = 0; j < nEntries; j++) { if (pslpi[j].Relationship == RelationProcessorCore) diff --git a/src/vm/win32threadpool.cpp b/src/vm/win32threadpool.cpp index 98c7d3ea81..e8a05c383f 100644 --- a/src/vm/win32threadpool.cpp +++ b/src/vm/win32threadpool.cpp @@ -3679,6 +3679,8 @@ DWORD __stdcall ThreadpoolMgr::CompletionPortThreadStart(LPVOID lpArgs) BOOL fThreadInit = FALSE; Thread *pThread = NULL; + DWORD cpThreadWait = 0; + if (g_fEEStarted) { pThread = SetupThreadNoThrow(); if (pThread == NULL) { @@ -3713,7 +3715,7 @@ DWORD __stdcall ThreadpoolMgr::CompletionPortThreadStart(LPVOID lpArgs) ThreadCounter::Counts oldCounts; ThreadCounter::Counts newCounts; - DWORD cpThreadWait = CP_THREAD_WAIT; + cpThreadWait = CP_THREAD_WAIT; for (;; ) { Top: -- cgit v1.2.3