From ce29457817253551f15d25d596c4837432cc472e Mon Sep 17 00:00:00 2001 From: bdebaere Date: Tue, 1 Oct 2019 08:45:04 -0500 Subject: [PATCH] Parenthesize macros (#23982) * Add parenthesis to parameters. * Revert changes to IS_UNWINDING. --- src/binder/bindinglog.cpp | 4 ++-- src/debug/di/rspriv.h | 2 +- src/debug/di/rstype.cpp | 2 +- src/debug/ee/controller.cpp | 2 +- src/debug/ee/debugger.h | 2 +- src/dlls/mscorrc/resource.h | 6 +++--- src/gc/gc.cpp | 2 +- src/gc/handletablepriv.h | 4 ++-- src/gc/handletablescan.cpp | 6 +++--- src/gc/objecthandle.h | 8 ++++---- src/ilasm/grammar_before.cpp | 4 ++-- src/ilasm/writer.cpp | 2 +- src/ildasm/dasm.cpp | 2 +- src/inc/clrprivbinderutil.h | 4 ++-- src/inc/corhdr.h | 8 ++++---- src/inc/debugmacros.h | 2 +- src/inc/eventtracebase.h | 4 ++-- src/inc/ex.h | 2 +- src/inc/palclr.h | 4 ++-- src/inc/sbuffer.h | 2 +- src/inc/utilcode.h | 16 ++++++++-------- src/jit/error.h | 2 +- src/jit/gentree.h | 10 +++++----- src/jit/instr.h | 4 ++-- src/jit/instrsxarch.h | 6 +++--- src/jit/register.h | 4 ++-- src/jit/simdcodegenxarch.cpp | 6 +++--- src/md/compiler/filtermanager.cpp | 2 +- src/md/debug_metadata.h | 2 +- src/md/runtime/metamodel.cpp | 2 +- src/utilcode/loadrc-impl.cpp | 4 ++-- src/utilcode/md5.cpp | 2 +- src/utilcode/sha1.cpp | 8 ++++---- src/vm/cachelinealloc.cpp | 2 +- src/vm/callhelpers.h | 2 +- src/vm/clrex.h | 2 +- src/vm/comcallablewrapper.cpp | 14 +++++++------- src/vm/dataimage.cpp | 2 +- src/vm/decodemd.cpp | 14 +++++++------- src/vm/eetwain.cpp | 2 +- src/vm/exceptmacros.h | 4 ++-- src/vm/fcall.h | 8 ++++---- src/vm/methodtable.h | 4 ++-- src/vm/mlinfo.h | 6 +++--- src/vm/object.h | 2 +- src/vm/threadsuspend.cpp | 4 ++-- src/vm/win32threadpool.cpp | 12 ++++++------ src/vm/win32threadpool.h | 2 +- src/zap/zapper.cpp | 4 ++-- 49 files changed, 112 insertions(+), 112 deletions(-) diff --git a/src/binder/bindinglog.cpp b/src/binder/bindinglog.cpp index 87c0c289eb9e..cfb7360c9316 100644 --- a/src/binder/bindinglog.cpp +++ b/src/binder/bindinglog.cpp @@ -28,9 +28,9 @@ #include "strsafe.h" #define SIZE_OF_TOKEN_INFORMATION \ - sizeof( TOKEN_USER ) \ + (sizeof( TOKEN_USER ) \ + sizeof( SID ) \ - + sizeof( ULONG ) * SID_MAX_SUB_AUTHORITIES + + sizeof( ULONG ) * SID_MAX_SUB_AUTHORITIES) #include "../dlls/mscorrc/fusres.h" diff --git a/src/debug/di/rspriv.h b/src/debug/di/rspriv.h index b06c125de583..723fcf26345b 100644 --- a/src/debug/di/rspriv.h +++ b/src/debug/di/rspriv.h @@ -52,7 +52,7 @@ struct MachineInfo; #include "eventchannel.h" #undef ASSERT -#define CRASH(x) _ASSERTE(!x) +#define CRASH(x) _ASSERTE(!(x)) #define ASSERT(x) _ASSERTE(x) // We want to keep the 'worst' HRESULT - if one has failed (..._E_...) & the diff --git a/src/debug/di/rstype.cpp b/src/debug/di/rstype.cpp index 8b7c29482087..0e1e9e49a50d 100644 --- a/src/debug/di/rstype.cpp +++ b/src/debug/di/rstype.cpp @@ -112,7 +112,7 @@ HRESULT CordbType::GetStaticFieldValue(mdFieldDef fieldDef, } // Combine E_T_s and rank together to get an id for the m_sharedtypes table -#define CORDBTYPE_ID(elementType,rank) ((unsigned int) elementType * (rank + 1) + 1) +#define CORDBTYPE_ID(elementType,rank) (((unsigned int) (elementType)) * ((rank) + 1) + 1) //----------------------------------------------------------------------------- diff --git a/src/debug/ee/controller.cpp b/src/debug/ee/controller.cpp index 9f0eaad0007b..11925cf32622 100644 --- a/src/debug/ee/controller.cpp +++ b/src/debug/ee/controller.cpp @@ -26,7 +26,7 @@ const char *GetTType( TraceType tt); -#define IsSingleStep(exception) (exception == EXCEPTION_SINGLE_STEP) +#define IsSingleStep(exception) ((exception) == EXCEPTION_SINGLE_STEP) diff --git a/src/debug/ee/debugger.h b/src/debug/ee/debugger.h index 2f3de72c5749..82b93935edee 100644 --- a/src/debug/ee/debugger.h +++ b/src/debug/ee/debugger.h @@ -51,7 +51,7 @@ #include "canary.h" #undef ASSERT -#define CRASH(x) _ASSERTE(!x) +#define CRASH(x) _ASSERTE(!(x)) #define ASSERT(x) _ASSERTE(x) diff --git a/src/dlls/mscorrc/resource.h b/src/dlls/mscorrc/resource.h index 2a5426624a55..9c7865a76050 100644 --- a/src/dlls/mscorrc/resource.h +++ b/src/dlls/mscorrc/resource.h @@ -12,9 +12,9 @@ #define MSG_FOR_URT_HR(hr) (0x6000 + (HRESULT_CODE(hr))) #define MAX_URT_HRESULT_CODE 0x3000 -#define HR_FOR_URT_MSG(code) ((code >=0x6000 && code <= 0x6000+MAX_URT_HRESULT_CODE) ? \ - MAKE_HRESULT(SEVERITY_ERROR, FACILITY_URT, code - 0x6000) : \ - code) +#define HR_FOR_URT_MSG(code) (((code) >=0x6000 && (code) <= 0x6000+MAX_URT_HRESULT_CODE) ? \ + MAKE_HRESULT(SEVERITY_ERROR, FACILITY_URT, (code) - 0x6000) : \ + (code)) #ifndef HRESULT_CODE #define HRESULT_CODE(hr) ((hr) & 0xFFFF) diff --git a/src/gc/gc.cpp b/src/gc/gc.cpp index ae7435b03329..9107804ce189 100644 --- a/src/gc/gc.cpp +++ b/src/gc/gc.cpp @@ -3941,7 +3941,7 @@ size_t gcard_of ( uint8_t*); //GC Flags #define GC_MARKED (size_t)0x1 -#define slot(i, j) ((uint8_t**)(i))[j+1] +#define slot(i, j) ((uint8_t**)(i))[(j)+1] #define free_object_base_size (plug_skew + sizeof(ArrayBase)) diff --git a/src/gc/handletablepriv.h b/src/gc/handletablepriv.h index c696431f775a..9f650fe180bf 100644 --- a/src/gc/handletablepriv.h +++ b/src/gc/handletablepriv.h @@ -40,13 +40,13 @@ // little-endian write barrier mask manipulation #define GEN_CLUMP_0_MASK (0x000000FF) - #define NEXT_CLUMP_IN_MASK(dw) (dw >> BITS_PER_BYTE) + #define NEXT_CLUMP_IN_MASK(dw) ((dw) >> BITS_PER_BYTE) #else // big-endian write barrier mask manipulation #define GEN_CLUMP_0_MASK (0xFF000000) - #define NEXT_CLUMP_IN_MASK(dw) (dw << BITS_PER_BYTE) + #define NEXT_CLUMP_IN_MASK(dw) ((dw) << BITS_PER_BYTE) #endif diff --git a/src/gc/handletablescan.cpp b/src/gc/handletablescan.cpp index 82aae2f72a04..0ed800b7cf77 100644 --- a/src/gc/handletablescan.cpp +++ b/src/gc/handletablescan.cpp @@ -184,10 +184,10 @@ If you change any of those algorithm, please verify it by this program: #define GEN_FULLGC PREFOLD_FILL_INTO_AGEMASK(GEN_AGE_LIMIT) -#define MAKE_CLUMP_MASK_ADDENDS(bytes) (bytes >> GEN_INC_SHIFT) -#define APPLY_CLUMP_ADDENDS(gen, addend) (gen + addend) +#define MAKE_CLUMP_MASK_ADDENDS(bytes) ((bytes) >> GEN_INC_SHIFT) +#define APPLY_CLUMP_ADDENDS(gen, addend) ((gen) + (addend)) -#define COMPUTE_CLUMP_MASK(gen, msk) (((gen & GEN_CLAMP) - msk) & GEN_MASK) +#define COMPUTE_CLUMP_MASK(gen, msk) ((((gen) & GEN_CLAMP) - (msk)) & GEN_MASK) #define COMPUTE_CLUMP_ADDENDS(gen, msk) MAKE_CLUMP_MASK_ADDENDS(COMPUTE_CLUMP_MASK(gen, msk)) #define COMPUTE_AGED_CLUMPS(gen, msk) APPLY_CLUMP_ADDENDS(gen, COMPUTE_CLUMP_ADDENDS(gen, msk)) diff --git a/src/gc/objecthandle.h b/src/gc/objecthandle.h index f1b5656265ca..f601e5cf8dbc 100644 --- a/src/gc/objecthandle.h +++ b/src/gc/objecthandle.h @@ -50,10 +50,10 @@ struct HandleTableBucket #define VHT_STRONG (0x00000400) // avoid using low byte so we don't overlap normal types #define VHT_PINNED (0x00000800) // avoid using low byte so we don't overlap normal types -#define IS_VALID_VHT_VALUE(flag) ((flag == VHT_WEAK_SHORT) || \ - (flag == VHT_WEAK_LONG) || \ - (flag == VHT_STRONG) || \ - (flag == VHT_PINNED)) +#define IS_VALID_VHT_VALUE(flag) (((flag) == VHT_WEAK_SHORT) || \ + ((flag) == VHT_WEAK_LONG) || \ + ((flag) == VHT_STRONG) || \ + ((flag) == VHT_PINNED)) GC_DAC_VISIBLE OBJECTREF GetDependentHandleSecondary(OBJECTHANDLE handle); diff --git a/src/ilasm/grammar_before.cpp b/src/ilasm/grammar_before.cpp index dd30416baefe..899eed18a55a 100644 --- a/src/ilasm/grammar_before.cpp +++ b/src/ilasm/grammar_before.cpp @@ -104,8 +104,8 @@ int nTemp=0; unsigned int uMethodBeginLine,uMethodBeginColumn; -#define ELEMENT_TYPE_VARFIXUP ELEMENT_TYPE_MAX+2 -#define ELEMENT_TYPE_MVARFIXUP ELEMENT_TYPE_MAX+3 +#define ELEMENT_TYPE_VARFIXUP (ELEMENT_TYPE_MAX+2) +#define ELEMENT_TYPE_MVARFIXUP (ELEMENT_TYPE_MAX+3) FIFO TyParFixupList; void FixupTyPars(PCOR_SIGNATURE pSig, ULONG cSig); diff --git a/src/ilasm/writer.cpp b/src/ilasm/writer.cpp index 0958f027218a..e6739ac21847 100644 --- a/src/ilasm/writer.cpp +++ b/src/ilasm/writer.cpp @@ -1208,7 +1208,7 @@ HRESULT Assembler::CreatePEFile(__in __nullterminated WCHAR *pwzOutputFilename) EmitUnresolvedCustomAttributes(); // Emit typedefs as special TypeSpecs { -#define ELEMENT_TYPE_TYPEDEF ELEMENT_TYPE_MAX+1 +#define ELEMENT_TYPE_TYPEDEF (ELEMENT_TYPE_MAX+1) TypeDefDescr* pTDD; unsigned __int8* pb; unsigned namesize; diff --git a/src/ildasm/dasm.cpp b/src/ildasm/dasm.cpp index 26ebe8f2db04..af3a58f244a4 100644 --- a/src/ildasm/dasm.cpp +++ b/src/ildasm/dasm.cpp @@ -967,7 +967,7 @@ void DumpTypelist(void* GUICookie) } } -#define ELEMENT_TYPE_TYPEDEF ELEMENT_TYPE_MAX+1 +#define ELEMENT_TYPE_TYPEDEF (ELEMENT_TYPE_MAX+1) BOOL EnumTypedefs() { HENUMInternal hEnum; diff --git a/src/inc/clrprivbinderutil.h b/src/inc/clrprivbinderutil.h index 023f72c6dfdd..2d6bfc6c01ad 100644 --- a/src/inc/clrprivbinderutil.h +++ b/src/inc/clrprivbinderutil.h @@ -42,8 +42,8 @@ class AssemblySpec; fail_op; \ } while (false) -#define VALIDATE_PTR_RET(val) VALIDATE_CONDITION(val != nullptr, return E_POINTER) -#define VALIDATE_PTR_THROW(val) VALIDATE_CONDITION(val != nullptr, ThrowHR(E_POINTER)) +#define VALIDATE_PTR_RET(val) VALIDATE_CONDITION((val) != nullptr, return E_POINTER) +#define VALIDATE_PTR_THROW(val) VALIDATE_CONDITION((val) != nullptr, ThrowHR(E_POINTER)) #define VALIDATE_ARG_RET(condition) VALIDATE_CONDITION(condition, return E_INVALIDARG) #define VALIDATE_ARG_THROW(condition) VALIDATE_CONDITION(condition, ThrowHR(E_INVALIDARG)) diff --git a/src/inc/corhdr.h b/src/inc/corhdr.h index 4b14d7fa061e..876734d67da8 100644 --- a/src/inc/corhdr.h +++ b/src/inc/corhdr.h @@ -1894,10 +1894,10 @@ typedef enum CorSaveSize } CorSaveSize; #endif -#define COR_IS_METHOD_MANAGED_IL(flags) ((flags & 0xf) == (miIL | miManaged)) -#define COR_IS_METHOD_MANAGED_OPTIL(flags) ((flags & 0xf) == (miOPTIL | miManaged)) -#define COR_IS_METHOD_MANAGED_NATIVE(flags) ((flags & 0xf) == (miNative | miManaged)) -#define COR_IS_METHOD_UNMANAGED_NATIVE(flags) ((flags & 0xf) == (miNative | miUnmanaged)) +#define COR_IS_METHOD_MANAGED_IL(flags) (((flags) & 0xf) == (miIL | miManaged)) +#define COR_IS_METHOD_MANAGED_OPTIL(flags) (((flags) & 0xf) == (miOPTIL | miManaged)) +#define COR_IS_METHOD_MANAGED_NATIVE(flags) (((flags) & 0xf) == (miNative | miManaged)) +#define COR_IS_METHOD_UNMANAGED_NATIVE(flags) (((flags) & 0xf) == (miNative | miUnmanaged)) // // Enum used with NATIVE_TYPE_ARRAY. diff --git a/src/inc/debugmacros.h b/src/inc/debugmacros.h index 540be99c7407..79087d501f1f 100644 --- a/src/inc/debugmacros.h +++ b/src/inc/debugmacros.h @@ -214,7 +214,7 @@ unsigned DbgGetEXETimeStamp(); // will not be coorelated with each other (9973 is prime). Returns false on a retail build #define DbgRandomOnHashAndExe(hash, fractionOn) \ (((DbgGetEXETimeStamp() * __LINE__ * ((hash) ? (hash) : 1)) % 9973) < \ - unsigned(fractionOn * 9973)) + unsigned((fractionOn) * 9973)) #define DbgRandomOnExe(fractionOn) DbgRandomOnHashAndExe(0, fractionOn) #define DbgRandomOnStringAndExe(string, fractionOn) DbgRandomOnHashAndExe(HashStringA(string), fractionOn) diff --git a/src/inc/eventtracebase.h b/src/inc/eventtracebase.h index 43147f5a6f5a..3ca2ff63279b 100644 --- a/src/inc/eventtracebase.h +++ b/src/inc/eventtracebase.h @@ -72,7 +72,7 @@ enum EtwThreadFlags // #define ETW_TRACING_INITIALIZED(RegHandle) \ - ((g_pEtwTracer && RegHandle) || EVENT_PIPE_ENABLED()) + ((g_pEtwTracer && (RegHandle)) || EVENT_PIPE_ENABLED()) // // Use this macro to check if an event is enabled @@ -558,7 +558,7 @@ extern "C" { // User defined callback // #define MCGEN_PRIVATE_ENABLE_CALLBACK(RequestCode, Context, InOutBufferSize, Buffer) \ - EtwCallback(NULL /* SourceId */, (RequestCode==WMI_ENABLE_EVENTS) ? EVENT_CONTROL_CODE_ENABLE_PROVIDER : EVENT_CONTROL_CODE_DISABLE_PROVIDER, 0 /* Level */, 0 /* MatchAnyKeyword */, 0 /* MatchAllKeyword */, NULL /* FilterData */, Context) + EtwCallback(NULL /* SourceId */, ((RequestCode)==WMI_ENABLE_EVENTS) ? EVENT_CONTROL_CODE_ENABLE_PROVIDER : EVENT_CONTROL_CODE_DISABLE_PROVIDER, 0 /* Level */, 0 /* MatchAnyKeyword */, 0 /* MatchAllKeyword */, NULL /* FilterData */, Context) // // User defined callback2 diff --git a/src/inc/ex.h b/src/inc/ex.h index ac40cbacdf56..1b5ea8d0b95e 100644 --- a/src/inc/ex.h +++ b/src/inc/ex.h @@ -747,7 +747,7 @@ class CAutoTryCleanup // // We also check the global override flag incase it has been set to force pre-V4 beahviour. "0" implies it has not // been overriden. -#define SET_CE_RETHROW_FLAG_FOR_EX_CATCH(expr) (((expr == TRUE) && \ +#define SET_CE_RETHROW_FLAG_FOR_EX_CATCH(expr) ((((expr) == TRUE) && \ (CLRConfig::GetConfigValue(CLRConfig::UNSUPPORTED_legacyCorruptedStateExceptionsPolicy) == 0) && \ IsProcessCorruptedStateException(GetCurrentExceptionCode(), FALSE))) diff --git a/src/inc/palclr.h b/src/inc/palclr.h index bba278b776fe..3f360d2eee1a 100644 --- a/src/inc/palclr.h +++ b/src/inc/palclr.h @@ -106,7 +106,7 @@ #else // Ports in progress - run-time asserts only #define PORTABILITY_WARNING(message) -#define PORTABILITY_ASSERT(message) _ASSERTE(false && message) +#define PORTABILITY_ASSERT(message) _ASSERTE(false && (message)) #endif #define DIRECTORY_SEPARATOR_CHAR_A '\\' @@ -473,7 +473,7 @@ // Executes the handler if the specified exception code matches // the one in the exception. Otherwise, returns EXCEPTION_CONTINUE_SEARCH. -#define PAL_EXCEPT_IF_EXCEPTION_CODE(dwExceptionCode) PAL_EXCEPT((GetExceptionCode() == dwExceptionCode)?EXCEPTION_EXECUTE_HANDLER:EXCEPTION_CONTINUE_SEARCH) +#define PAL_EXCEPT_IF_EXCEPTION_CODE(dwExceptionCode) PAL_EXCEPT((GetExceptionCode() == (dwExceptionCode))?EXCEPTION_EXECUTE_HANDLER:EXCEPTION_CONTINUE_SEARCH) #define PAL_CPP_TRY try #define PAL_CPP_ENDTRY diff --git a/src/inc/sbuffer.h b/src/inc/sbuffer.h index a5de4c3627e6..1544b3f8a240 100644 --- a/src/inc/sbuffer.h +++ b/src/inc/sbuffer.h @@ -46,7 +46,7 @@ // ================================================================================ #define ALIGNMENT(size) \ - (( (size^(size-1)) >> 1) +1) + (( ((size)^((size)-1)) >> 1) +1) #define ALIGN(size, align) \ (((size)+((align)-1)) & ~((align)-1)) diff --git a/src/inc/utilcode.h b/src/inc/utilcode.h index 88f70659c444..05661b111187 100644 --- a/src/inc/utilcode.h +++ b/src/inc/utilcode.h @@ -163,14 +163,14 @@ typedef LPSTR LPUTF8; #endif -#define IS_DIGIT(ch) ((ch >= W('0')) && (ch <= W('9'))) -#define DIGIT_TO_INT(ch) (ch - W('0')) -#define INT_TO_DIGIT(i) ((WCHAR)(W('0') + i)) +#define IS_DIGIT(ch) (((ch) >= W('0')) && ((ch) <= W('9'))) +#define DIGIT_TO_INT(ch) ((ch) - W('0')) +#define INT_TO_DIGIT(i) ((WCHAR)(W('0') + (i))) -#define IS_HEXDIGIT(ch) (((ch >= W('a')) && (ch <= W('f'))) || \ - ((ch >= W('A')) && (ch <= W('F')))) +#define IS_HEXDIGIT(ch) ((((ch) >= W('a')) && ((ch) <= W('f'))) || \ + (((ch) >= W('A')) && ((ch) <= W('F')))) #define HEXDIGIT_TO_INT(ch) ((towlower(ch) - W('a')) + 10) -#define INT_TO_HEXDIGIT(i) ((WCHAR)(W('a') + (i - 10))) +#define INT_TO_HEXDIGIT(i) ((WCHAR)(W('a') + ((i) - 10))) // Helper will 4 byte align a value, rounding up. @@ -965,10 +965,10 @@ inline HRESULT BadError(HRESULT hr) } #define TESTANDRETURNPOINTER(pointer) \ - TESTANDRETURN(pointer!=NULL, E_POINTER) + TESTANDRETURN((pointer)!=NULL, E_POINTER) #define TESTANDRETURNMEMORY(pointer) \ - TESTANDRETURN(pointer!=NULL, E_OUTOFMEMORY) + TESTANDRETURN((pointer)!=NULL, E_OUTOFMEMORY) #define TESTANDRETURNHR(hr) \ TESTANDRETURN(SUCCEEDED(hr), hr) diff --git a/src/jit/error.h b/src/jit/error.h index 18beb4b15190..36beb60d6890 100644 --- a/src/jit/error.h +++ b/src/jit/error.h @@ -204,7 +204,7 @@ extern void notYetImplemented(const char* msg, const char* file, unsigned line); #else // NYI not available; make it an assert. -#define NYI(msg) assert(!msg) +#define NYI(msg) assert(!(msg)) #define NYI_AMD64(msg) do { } while (0) #define NYI_ARM(msg) do { } while (0) #define NYI_ARM64(msg) do { } while (0) diff --git a/src/jit/gentree.h b/src/jit/gentree.h index 1d3799c8acf7..2250902f2555 100644 --- a/src/jit/gentree.h +++ b/src/jit/gentree.h @@ -391,11 +391,11 @@ struct GenTree #define NO_CSE (0) -#define IS_CSE_INDEX(x) (x != 0) -#define IS_CSE_USE(x) (x > 0) -#define IS_CSE_DEF(x) (x < 0) -#define GET_CSE_INDEX(x) ((x > 0) ? x : -x) -#define TO_CSE_DEF(x) (-x) +#define IS_CSE_INDEX(x) ((x) != 0) +#define IS_CSE_USE(x) ((x) > 0) +#define IS_CSE_DEF(x) ((x) < 0) +#define GET_CSE_INDEX(x) (((x) > 0) ? x : -(x)) +#define TO_CSE_DEF(x) (-(x)) signed char gtCSEnum; // 0 or the CSE index (negated if def) // valid only for CSE expressions diff --git a/src/jit/instr.h b/src/jit/instr.h index 75f1b592a7da..c53bc46b5139 100644 --- a/src/jit/instr.h +++ b/src/jit/instr.h @@ -276,8 +276,8 @@ enum emitAttr : unsigned #define EA_ATTR(x) ((emitAttr)(x)) #define EA_SIZE(x) ((emitAttr)(((unsigned)(x)) & EA_SIZE_MASK)) #define EA_SIZE_IN_BYTES(x) ((UNATIVE_OFFSET)(EA_SIZE(x))) -#define EA_SET_SIZE(x, sz) ((emitAttr)((((unsigned)(x)) & ~EA_SIZE_MASK) | sz)) -#define EA_SET_FLG(x, flg) ((emitAttr)(((unsigned)(x)) | flg)) +#define EA_SET_SIZE(x, sz) ((emitAttr)((((unsigned)(x)) & ~EA_SIZE_MASK) | (sz))) +#define EA_SET_FLG(x, flg) ((emitAttr)(((unsigned)(x)) | (flg))) #define EA_4BYTE_DSP_RELOC (EA_SET_FLG(EA_4BYTE, EA_DSP_RELOC_FLG)) #define EA_PTR_DSP_RELOC (EA_SET_FLG(EA_PTRSIZE, EA_DSP_RELOC_FLG)) #define EA_HANDLE_CNS_RELOC (EA_SET_FLG(EA_PTRSIZE, EA_CNS_RELOC_FLG)) diff --git a/src/jit/instrsxarch.h b/src/jit/instrsxarch.h index 2a8a54dd4ccd..0b98f4973ae4 100644 --- a/src/jit/instrsxarch.h +++ b/src/jit/instrsxarch.h @@ -159,15 +159,15 @@ INSTMUL(imul_15, "imul", IUM_RD, BAD_CODE, 0x4400003868, // So a 4-byte opcode would be something like this: // 0x22114433 -#define PACK3(byte1,byte2,byte3) ((byte1 << 16) | (byte2 << 24) | byte3) -#define PACK2(byte1,byte2) ((byte1 << 16) | byte2) +#define PACK3(byte1,byte2,byte3) (((byte1) << 16) | ((byte2) << 24) | (byte3)) +#define PACK2(byte1,byte2) (((byte1) << 16) | (byte2)) #define SSEFLT(c) PACK3(0xf3, 0x0f, c) #define SSEDBL(c) PACK3(0xf2, 0x0f, c) #define PCKDBL(c) PACK3(0x66, 0x0f, c) #define PCKFLT(c) PACK2(0x0f,c) // These macros encode extra byte that is implicit in the macro. -#define PACK4(byte1,byte2,byte3,byte4) ((byte1 << 16) | (byte2 << 24) | byte3 | (byte4 << 8)) +#define PACK4(byte1,byte2,byte3,byte4) (((byte1) << 16) | ((byte2) << 24) | (byte3) | ((byte4) << 8)) #define SSE38(c) PACK4(0x66, 0x0f, 0x38, c) #define SSE3A(c) PACK4(0x66, 0x0f, 0x3A, c) diff --git a/src/jit/register.h b/src/jit/register.h index 29f64de7efec..fafafb470957 100644 --- a/src/jit/register.h +++ b/src/jit/register.h @@ -69,10 +69,10 @@ REGALIAS(EDI, RDI) #ifdef _TARGET_AMD64_ #define XMMBASE 16 -#define XMMMASK(x) (__int64(1) << (x+XMMBASE)) +#define XMMMASK(x) (__int64(1) << ((x)+XMMBASE)) #else // !_TARGET_AMD64_ #define XMMBASE 8 -#define XMMMASK(x) (__int32(1) << (x+XMMBASE)) +#define XMMMASK(x) (__int32(1) << ((x)+XMMBASE)) #endif // !_TARGET_AMD64_ REGDEF(XMM0, 0+XMMBASE, XMMMASK(0), "mm0" ) diff --git a/src/jit/simdcodegenxarch.cpp b/src/jit/simdcodegenxarch.cpp index 7cea1e1dbcd3..f3e6abffae5a 100644 --- a/src/jit/simdcodegenxarch.cpp +++ b/src/jit/simdcodegenxarch.cpp @@ -32,9 +32,9 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // - bits 6 and 7 of the immediate indicate which source item to select (0..3) // - bits 4 and 5 of the immediate indicate which target item to insert into (0..3) // - bits 0 to 3 of the immediate indicate which target item to zero -#define INSERTPS_SOURCE_SELECT(i) (i << 6) -#define INSERTPS_TARGET_SELECT(i) (i << 4) -#define INSERTPS_ZERO(i) (1 << i) +#define INSERTPS_SOURCE_SELECT(i) ((i) << 6) +#define INSERTPS_TARGET_SELECT(i) ((i) << 4) +#define INSERTPS_ZERO(i) (1 << (i)) // getOpForSIMDIntrinsic: return the opcode for the given SIMD Intrinsic // diff --git a/src/md/compiler/filtermanager.cpp b/src/md/compiler/filtermanager.cpp index c8e9ac3e07cf..b2f59140285f 100644 --- a/src/md/compiler/filtermanager.cpp +++ b/src/md/compiler/filtermanager.cpp @@ -12,7 +12,7 @@ #include "stdafx.h" #include "filtermanager.h" -#define IsGlobalTypeDef(td) (td == TokenFromRid(mdtTypeDef, 1)) +#define IsGlobalTypeDef(td) ((td) == TokenFromRid(mdtTypeDef, 1)) //***************************************************************************** // Walk up to the containing tree and diff --git a/src/md/debug_metadata.h b/src/md/debug_metadata.h index cf1d312e5e41..afc860516f0b 100644 --- a/src/md/debug_metadata.h +++ b/src/md/debug_metadata.h @@ -71,7 +71,7 @@ #define INDEBUG_MD_COMMA(expr) #define Debug_ReportError(strMessage) - #define Debug_ReportInternalError(strMessage) _ASSERTE(!strMessage) + #define Debug_ReportInternalError(strMessage) _ASSERTE(!(strMessage)) #endif //!_DEBUG_METADATA // -------------------------------------------------------------------------------------- diff --git a/src/md/runtime/metamodel.cpp b/src/md/runtime/metamodel.cpp index 8f0ef83451a0..36fa7369e751 100644 --- a/src/md/runtime/metamodel.cpp +++ b/src/md/runtime/metamodel.cpp @@ -429,7 +429,7 @@ CMiniMdBase::encodeToken( //***************************************************************************** inline BYTE cbRID(ULONG ixMax) { return ixMax > USHRT_MAX ? (BYTE) sizeof(ULONG) : (BYTE) sizeof(USHORT); } -#define _CBTKN(cRecs,tkns) cbRID(cRecs << m_cb[lengthof(tkns)]) +#define _CBTKN(cRecs,tkns) cbRID((cRecs) << m_cb[lengthof(tkns)]) //***************************************************************************** // Constructor. diff --git a/src/utilcode/loadrc-impl.cpp b/src/utilcode/loadrc-impl.cpp index 2bae22aab589..2b13df0c3ed0 100644 --- a/src/utilcode/loadrc-impl.cpp +++ b/src/utilcode/loadrc-impl.cpp @@ -39,7 +39,7 @@ void SkipChars(MyString &str, MyStringIterator &i, WCHAR c1, WCHAR c2) { while ( #include typedef std::wstring MyString; typedef std::wstring::const_iterator MyStringIterator; -#define EndsWithChar(OBJ, CHAR) (*(OBJ.rbegin()) == CHAR) +#define EndsWithChar(OBJ, CHAR) (*(OBJ.rbegin()) == (CHAR)) #define AppendChar(OBJ, CHAR) (OBJ.push_back(CHAR)) #define AppendStr(OBJ, STR) (OBJ += STR) #define TrimLastChar(OBJ) (OBJ.resize(OBJ.size() - 1)) @@ -50,7 +50,7 @@ typedef std::wstring::const_iterator MyStringIterator; #define StrEndIter(OBJ) (OBJ.end()) #define FindNext(OBJ, ITER, CHAR) (ITER = std::find(ITER, OBJ.end(), CHAR)) #define MakeString(DST, OBJ, BEG, END) (DST = MyString(BEG, END)) -#define StrEquals(STR1, STR2) (STR1 == STR2) +#define StrEquals(STR1, STR2) ((STR1) == (STR2)) #define ClrGetEnvironmentVariable(var, res) GetEnvVar(L##var, res) bool FindLast(const MyString &str, MyStringIterator &iter, WCHAR c) { diff --git a/src/utilcode/md5.cpp b/src/utilcode/md5.cpp index 6901ddbf913d..8651e64d37d8 100644 --- a/src/utilcode/md5.cpp +++ b/src/utilcode/md5.cpp @@ -182,7 +182,7 @@ void MD5::GetHashValue(MD5HASHDATA* phash) #define H(x, y, z) ((x) ^ (y) ^ (z)) - #define I(x, y, z) ((y) ^ ((x) | (~z))) + #define I(x, y, z) ((y) ^ ((x) | (~(z)))) #define AC(ac) ((ULONG)(ac)) diff --git a/src/utilcode/sha1.cpp b/src/utilcode/sha1.cpp index c7993f26353b..9f45a62b11d2 100644 --- a/src/utilcode/sha1.cpp +++ b/src/utilcode/sha1.cpp @@ -85,14 +85,14 @@ static void SHA1_block(SHA1_CTX *ctx) msg80[i+1] = ROTATE32L(temp2, 1); } -#define ROUND1(B, C, D) ((D ^ (B & (C ^ D))) + sha1_round1) +#define ROUND1(B, C, D) (((D) ^ ((B) & ((C) ^ (D)))) + sha1_round1) // Equivalent to (B & C) | (~B & D). // (check cases B = 0 and B = 1) -#define ROUND2(B, C, D) ((B ^ C ^ D) + sha1_round2) +#define ROUND2(B, C, D) (((B) ^ (C) ^ (D)) + sha1_round2) -#define ROUND3(B, C, D) (((C & (B | D)) | (B & D)) + sha1_round3) +#define ROUND3(B, C, D) ((((C) & ((B) | (D))) | ((B) & (D))) + sha1_round3) -#define ROUND4(B, C, D) ((B ^ C ^ D) + sha1_round4) +#define ROUND4(B, C, D) (((B) ^ (C) ^ (D)) + sha1_round4) // Round 1 for (i = 0; i <= 20 - 5; i += 5) { diff --git a/src/vm/cachelinealloc.cpp b/src/vm/cachelinealloc.cpp index a797b1427e0c..45c68222b6a1 100644 --- a/src/vm/cachelinealloc.cpp +++ b/src/vm/cachelinealloc.cpp @@ -189,7 +189,7 @@ void *CCacheLineAllocator::GetCacheLine64() RETURN tempPtr; } -#define AllocSize 4096*16 +#define AllocSize (4096*16) ////////////////////////////////' /// Virtual Allocation for some more cache lines diff --git a/src/vm/callhelpers.h b/src/vm/callhelpers.h index 1d5333162c07..08f1a59bc08b 100644 --- a/src/vm/callhelpers.h +++ b/src/vm/callhelpers.h @@ -640,7 +640,7 @@ enum DispatchCallSimpleFlags // Arguments on x86 are passed backward #define ARGNUM_0 1 #define ARGNUM_1 0 -#define ARGNUM_N(n) __numArgs - n + 1 +#define ARGNUM_N(n) (__numArgs - (n) + 1) #else diff --git a/src/vm/clrex.h b/src/vm/clrex.h index e8ef895e9d2d..3fafb05c88ee 100644 --- a/src/vm/clrex.h +++ b/src/vm/clrex.h @@ -785,7 +785,7 @@ class EEFileLoadException : public EEException // This is explained in detail (alongwith relevant changes) in the implementation of RaiseTheException (in excep.cpp). #undef SET_CE_RETHROW_FLAG_FOR_EX_CATCH -#define SET_CE_RETHROW_FLAG_FOR_EX_CATCH(expr) ((expr == TRUE) && \ +#define SET_CE_RETHROW_FLAG_FOR_EX_CATCH(expr) (((expr) == TRUE) && \ (g_pConfig->LegacyCorruptedStateExceptionsPolicy() == false) && \ (CEHelper::IsProcessCorruptedStateException(GetCurrentExceptionCode(), FALSE) || \ (!__state.DidCatchCxx() && \ diff --git a/src/vm/comcallablewrapper.cpp b/src/vm/comcallablewrapper.cpp index a92cd0747044..6edd5d0aebb3 100644 --- a/src/vm/comcallablewrapper.cpp +++ b/src/vm/comcallablewrapper.cpp @@ -1687,15 +1687,15 @@ IUnknown* SimpleComCallWrapper::QIStandardInterface(Enum_StdInterfaces index) #include // improves CCW QI perf by ~10% #define IS_EQUAL_GUID(refguid,data1,data2,data3, data4,data5,data6,data7,data8,data9,data10,data11) \ - ((((DWORD*)&refguid)[0] == (data1)) && \ - (((DWORD*)&refguid)[1] == ((data3<<16)|data2)) && \ - (((DWORD*)&refguid)[2] == ((data7<<24)|(data6<<16)|(data5<<8)|data4)) && \ - (((DWORD*)&refguid)[3] == ((data11<<24)|(data10<<16)|(data9<<8)|data8))) \ + ((((DWORD*)&refguid)[0] == (data1)) && \ + (((DWORD*)&refguid)[1] == (((data3)<<16)|(data2))) && \ + (((DWORD*)&refguid)[2] == (((data7)<<24)|((data6)<<16)|((data5)<<8)|(data4))) && \ + (((DWORD*)&refguid)[3] == (((data11)<<24)|((data10)<<16)|((data9)<<8)|(data8)))) \ #define IS_EQUAL_GUID_LOW_12_BYTES(refguid,data1,data2,data3, data4,data5,data6,data7,data8,data9,data10,data11) \ - ((((DWORD*)&refguid)[1] == ((data3<<16)|data2)) && \ - (((DWORD*)&refguid)[2] == ((data7<<24)|(data6<<16)|(data5<<8)|data4)) && \ - (((DWORD*)&refguid)[3] == ((data11<<24)|(data10<<16)|(data9<<8)|data8))) \ + ((((DWORD*)&refguid)[1] == (((data3)<<16)|(data2))) && \ + (((DWORD*)&refguid)[2] == (((data7)<<24)|((data6)<<16)|((data5)<<8)|(data4))) && \ + (((DWORD*)&refguid)[3] == (((data11)<<24)|((data10)<<16)|((data9)<<8)|(data8)))) \ #define HANDLE_IID_INLINE(itfEnum,data1,data2,data3, data4,data5,data6,data7,data8,data9,data10,data11) \ CASE_IID_INLINE(itfEnum,data1,data2,data3, data4,data5,data6,data7,data8,data9,data10,data11) \ diff --git a/src/vm/dataimage.cpp b/src/vm/dataimage.cpp index 53a32b57cc07..162df7740dc9 100644 --- a/src/vm/dataimage.cpp +++ b/src/vm/dataimage.cpp @@ -27,7 +27,7 @@ #include "../zap/zapimport.h" #include "inlinetracking.h" -#define NodeTypeForItemKind(kind) ((ZapNodeType)(ZapNodeType_StoredStructure + kind)) +#define NodeTypeForItemKind(kind) ((ZapNodeType)(ZapNodeType_StoredStructure + (kind))) class ZapStoredStructure : public ZapNode { diff --git a/src/vm/decodemd.cpp b/src/vm/decodemd.cpp index 4fb4e18e4ca2..a086ed33c9de 100644 --- a/src/vm/decodemd.cpp +++ b/src/vm/decodemd.cpp @@ -63,17 +63,17 @@ const BYTE decoded_8[2] = {8, END_DECODED }; const BYTE decoded_9[2] = {9, END_DECODED }; const BYTE decoded_10[2] = {10, END_DECODED }; -#define INBITS(s) (s > MAX_HEADER) -#define INHEADER(s) (s <= MAX_HEADER) -#define PARTIALBITS(s) ((s>>8)&0xFF) +#define INBITS(s) ((s) > MAX_HEADER) +#define INHEADER(s) ((s) <= MAX_HEADER) +#define PARTIALBITS(s) (((s)>>8)&0xFF) #define NUMBERGOTTEN(s) (((s)>>16)&0xFF) -#define HEADER(s) ((s>>24)&0xFF) +#define HEADER(s) (((s)>>24)&0xFF) #define DECODING_HEADER(n) n #define DOING_BITS (MAX_HEADER+1) -#define DECODING_BITS(partial, got, header) (DOING_BITS+(partial<<8)+(got<<16)+(header<<24)) +#define DECODING_BITS(partial, got, header) (DOING_BITS+((partial)<<8)+((got)<<16)+((header)<<24)) #define DECODING_ERROR ((unsigned) -1) -#define MASK(len) (~(~0u <= last): \ - (duetime >= last || duetime <= now)) +#define TimeExpired(last,now,duetime) ((last) <= (now) ? \ + ((duetime) <= (now) && (duetime) >= (last)): \ + ((duetime) >= (last) || (duetime) <= (now))) -#define TimeInterval(end,start) ( end > start ? (end - start) : ((0xffffffff - start) + end + 1) ) +#define TimeInterval(end,start) ((end) > (start) ? ((end) - (start)) : ((0xffffffff - (start)) + (end) + 1)) // Returns the minimum of the remaining time to reach a timeout among all the waits DWORD ThreadpoolMgr::MinimumRemainingWait(LIST_ENTRY* waitInfo, unsigned int numWaits) diff --git a/src/vm/win32threadpool.h b/src/vm/win32threadpool.h index 058eaf460150..12b8e204808d 100644 --- a/src/vm/win32threadpool.h +++ b/src/vm/win32threadpool.h @@ -70,7 +70,7 @@ extern int (WINAPI * g_pufnNtQuerySystemInformation) (SYSTEM_INFORMATION_CLASS S #endif // !FEATURE_PAL #define FILETIME_TO_INT64(t) (*(__int64*)&(t)) -#define MILLI_TO_100NANO(x) (x * 10000) // convert from milliseond to 100 nanosecond unit +#define MILLI_TO_100NANO(x) ((x) * 10000) // convert from milliseond to 100 nanosecond unit /** * This type is supposed to be private to ThreadpoolMgr. diff --git a/src/zap/zapper.cpp b/src/zap/zapper.cpp index 66346d7d088c..6891220fc3a1 100644 --- a/src/zap/zapper.cpp +++ b/src/zap/zapper.cpp @@ -749,8 +749,8 @@ void Zapper::CleanupAssembly() // Stepping is masked out by GetSpecificCpuInfo() // #define CPU_X86_STEPPING(cpuType) (((cpuType) & 0x000F) ) -#define CPU_X86_USE_CMOV(cpuFeat) ((cpuFeat & 0x00008001) == 0x00008001) -#define CPU_X86_USE_SSE2(cpuFeat) ((cpuFeat & 0x04000000) == 0x04000000) +#define CPU_X86_USE_CMOV(cpuFeat) (((cpuFeat) & 0x00008001) == 0x00008001) +#define CPU_X86_USE_SSE2(cpuFeat) (((cpuFeat) & 0x04000000) == 0x04000000) // Values for CPU_X86_FAMILY(cpuType) #define CPU_X86_486 4