diff options
author | Phil Christensen <philc@microsoft.com> | 2016-12-01 03:53:23 -0800 |
---|---|---|
committer | Jan Vorlicek <janvorli@microsoft.com> | 2016-12-01 12:53:23 +0100 |
commit | 20275aa647c5733bc5b1929cba3fd1094c67fb1d (patch) | |
tree | 83175127d46a1eaf0071747a92876f3b3e43a6fa /src/md | |
parent | 3f4680c80dc510a96efa322054145a807480bab7 (diff) | |
download | coreclr-20275aa647c5733bc5b1929cba3fd1094c67fb1d.tar.gz coreclr-20275aa647c5733bc5b1929cba3fd1094c67fb1d.tar.bz2 coreclr-20275aa647c5733bc5b1929cba3fd1094c67fb1d.zip |
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.
Diffstat (limited to 'src/md')
-rw-r--r-- | src/md/ceefilegen/cceegen.cpp | 24 | ||||
-rw-r--r-- | src/md/winmd/adapter.cpp | 28 | ||||
-rw-r--r-- | src/md/winmd/winmdimport.cpp | 30 |
3 files changed, 49 insertions, 33 deletions
diff --git a/src/md/ceefilegen/cceegen.cpp b/src/md/ceefilegen/cceegen.cpp index 268093cd6b..0cf0780d15 100644 --- a/src/md/ceefilegen/cceegen.cpp +++ b/src/md/ceefilegen/cceegen.cpp @@ -572,18 +572,20 @@ HRESULT CCeeGen::emitMetaData(IMetaDataEmit *emitter, CeeSection* section, DWORD _ASSERTE(metaDataLen <= buffLen); #ifdef ENC_DELTA_HACK - extern int __cdecl fclose(FILE *); - WCHAR szFileName[256]; - DWORD len = GetEnvironmentVariable(W("COMP_ENC_EMIT"), szFileName, ARRAYSIZE(szFileName)); - _ASSERTE(len < (ARRAYSIZE(szFileName) + 6)); // +6 for the .dmeta - if (len > 0 && len < (ARRAYSIZE(szFileName) + 6)) { - wcscat_s(szFileName, ARRAYSIZE(szFileName), W(".dmeta")); - FILE *pDelta; - int ec = _wfopen_s(&pDelta, szFileName, W("wb")); - if (FAILED(ec)) { return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); } - fwrite(buffer, 1, metaDataLen, pDelta); - fclose(pDelta); + extern int __cdecl fclose(FILE *); + WCHAR szFileName[256]; + DWORD len = GetEnvironmentVariable(W("COMP_ENC_EMIT"), szFileName, ARRAYSIZE(szFileName)); + _ASSERTE(len < (ARRAYSIZE(szFileName) + 6)); // +6 for the .dmeta + if (len > 0 && len < (ARRAYSIZE(szFileName) + 6)) + { + wcscat_s(szFileName, ARRAYSIZE(szFileName), W(".dmeta")); + FILE *pDelta; + int ec = _wfopen_s(&pDelta, szFileName, W("wb")); + if (FAILED(ec)) { return HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); } + fwrite(buffer, 1, metaDataLen, pDelta); + fclose(pDelta); + } } #endif diff --git a/src/md/winmd/adapter.cpp b/src/md/winmd/adapter.cpp index 5b4d95cc7c..2c9dd1b9fd 100644 --- a/src/md/winmd/adapter.cpp +++ b/src/md/winmd/adapter.cpp @@ -88,6 +88,8 @@ HRESULT CheckIfWinMDAdapterNeeded(IMDCommon *pRawMDCommon) HRESULT hr; LPWSTR wszCorVersion = NULL; WinMDAdapter* pNewAdapter = NULL; + ULONG numAssemblyRefs = 0; + const char *szClrPortion = NULL; *ppAdapter = NULL; @@ -102,7 +104,7 @@ HRESULT CheckIfWinMDAdapterNeeded(IMDCommon *pRawMDCommon) //------------------------------------------------------------------------------------------------ LPCSTR szVersion; IfFailGo(pRawMDCommon->GetVersionString(&szVersion)); - const char *szClrPortion = strchr(szVersion, ';'); + szClrPortion = strchr(szVersion, ';'); if (szClrPortion) { pNewAdapter->m_scenario = kWinMDExp; @@ -148,7 +150,7 @@ HRESULT CheckIfWinMDAdapterNeeded(IMDCommon *pRawMDCommon) //------------------------------------------------------------------------------------------------ // Find an assemblyRef to mscorlib (required to exist in .winmd files precisely to make the adapter's job easier. //------------------------------------------------------------------------------------------------ - ULONG numAssemblyRefs = pNewAdapter->m_pRawMetaModelCommonRO->CommonGetRowCount(mdtAssemblyRef); + numAssemblyRefs = pNewAdapter->m_pRawMetaModelCommonRO->CommonGetRowCount(mdtAssemblyRef); pNewAdapter->m_assemblyRefMscorlib = 0; pNewAdapter->m_fReferencesMscorlibV4 = FALSE; for (ULONG rid = 1; rid <= numAssemblyRefs; rid++) @@ -860,10 +862,11 @@ WinMDAdapter::GetTypeRefProps( HRESULT hr; ULONG treatment; + ULONG treatmentClass; IfFailGo(GetTypeRefTreatment(tkTypeRef, &treatment)); _ASSERTE(treatment != kTrNotYetInitialized); - ULONG treatmentClass = treatment & kTrClassMask; + treatmentClass = treatment & kTrClassMask; if (treatmentClass == kTrClassWellKnownRedirected) { ULONG nRewritePairIndex = treatment & ~kTrClassMask; @@ -998,9 +1001,10 @@ WinMDAdapter::GetTypeRefRedirectedInfo( HRESULT hr; ULONG treatment; + ULONG treatmentClass; IfFailGo(GetTypeRefTreatment(tkTypeRef, &treatment)); - ULONG treatmentClass = treatment & kTrClassMask; + treatmentClass = treatment & kTrClassMask; if (treatmentClass == kTrClassWellKnownRedirected) { *pIndex = (RedirectedTypeIndex)(treatment & ~kTrClassMask); @@ -1278,11 +1282,14 @@ HRESULT WinMDAdapter::ModifyMethodProps(mdMethodDef tkMethodDef, /*[in, out]*/ D _ASSERTE(TypeFromToken(tkMethodDef) == mdtMethodDef); ULONG mdTreatment; + DWORD dwAttr; + DWORD dwImplFlags; + ULONG ulRVA; IfFailGo(GetMethodDefTreatment(tkMethodDef, &mdTreatment)); - DWORD dwAttr = pdwAttr ? *pdwAttr: 0; - DWORD dwImplFlags = pdwImplFlags ? *pdwImplFlags : 0; - ULONG ulRVA = pulRVA ? *pulRVA : 0; + dwAttr = pdwAttr ? *pdwAttr: 0; + dwImplFlags = pdwImplFlags ? *pdwImplFlags : 0; + ulRVA = pulRVA ? *pulRVA : 0; switch (mdTreatment & kMdTreatmentMask) { @@ -2400,9 +2407,12 @@ HRESULT WinMDAdapter::TranslateWinMDAttributeUsageAttribute(mdTypeDef tkTypeDefO { IfFailGo(COR_E_BADIMAGEFORMAT); } - DWORD wfTargetValue = *(DWORD*)(pbWFUsageBlob + 2); - *pClrTargetValue = ConvertToClrAttributeTarget(wfTargetValue); + { + DWORD wfTargetValue = *(DWORD*)(pbWFUsageBlob + 2); + *pClrTargetValue = ConvertToClrAttributeTarget(wfTargetValue); + } + // add AttributeTargets.Method, AttributeTargets.Constructor , AttributeTargets.Property, and AttributeTargets.Event if this is the VersionAttribute LPCSTR szNamespace; LPCSTR szName; diff --git a/src/md/winmd/winmdimport.cpp b/src/md/winmd/winmdimport.cpp index fe80bf0b04..cc983d2bfc 100644 --- a/src/md/winmd/winmdimport.cpp +++ b/src/md/winmd/winmdimport.cpp @@ -588,13 +588,15 @@ class WinMDImport : public IMetaDataImport2 *pmb = mdMethodDefNil; - // check to see if this is a vararg signature - PCCOR_SIGNATURE pvSigTemp = pvSigBlob; - if (isCallConv(CorSigUncompressCallingConv(pvSigTemp), IMAGE_CEE_CS_CALLCONV_VARARG)) { - // Get the fixed part of VARARG signature - IfFailGo(_GetFixedSigOfVarArg(pvSigBlob, cbSigBlob, &qbSig, &cbSigBlob)); - pvSigBlob = (PCCOR_SIGNATURE) qbSig.Ptr(); + // check to see if this is a vararg signature + PCCOR_SIGNATURE pvSigTemp = pvSigBlob; + if (isCallConv(CorSigUncompressCallingConv(pvSigTemp), IMAGE_CEE_CS_CALLCONV_VARARG)) + { + // Get the fixed part of VARARG signature + IfFailGo(_GetFixedSigOfVarArg(pvSigBlob, cbSigBlob, &qbSig, &cbSigBlob)); + pvSigBlob = (PCCOR_SIGNATURE) qbSig.Ptr(); + } } // now iterate all methods in td and compare name and signature @@ -1654,15 +1656,17 @@ class WinMDImport : public IMetaDataImport2 // Step 1: Call EnumAssemblyRefs with an empty buffer to create the HENUMInternal IfFailGo(m_pRawAssemblyImport->EnumAssemblyRefs(phEnum, NULL, 0, NULL)); - // Step 2: Increment the cound to include the extra assembly refs - HENUMInternal *phInternalEnum = static_cast<HENUMInternal*>(*phEnum); + { + // Step 2: Increment the count to include the extra assembly refs + HENUMInternal *phInternalEnum = static_cast<HENUMInternal*>(*phEnum); - _ASSERTE(phInternalEnum->m_EnumType == MDSimpleEnum); + _ASSERTE(phInternalEnum->m_EnumType == MDSimpleEnum); - _ASSERTE( phInternalEnum->m_ulCount == m_pWinMDAdapter->GetRawAssemblyRefCount()); - int n = m_pWinMDAdapter->GetExtraAssemblyRefCount(); - phInternalEnum->m_ulCount += n; - phInternalEnum->u.m_ulEnd += n; + _ASSERTE( phInternalEnum->m_ulCount == m_pWinMDAdapter->GetRawAssemblyRefCount()); + int n = m_pWinMDAdapter->GetExtraAssemblyRefCount(); + phInternalEnum->m_ulCount += n; + phInternalEnum->u.m_ulEnd += n; + } // Step 3: Call EnumAssemblyRefs again and pass in the modifed HENUMInternal and the real buffer IfFailGo(m_pRawAssemblyImport->EnumAssemblyRefs(phEnum, rAssemblyRefs, cMax, pcTokens)); |