Skip to content

Commit

Permalink
Fix pal_assert.h when PAL_STDCPP_COMPAT defined (#64631)
Browse files Browse the repository at this point in the history
* Fix pal_assert.h for PAL_STDCPP_COMPAT
Improves #37310
  • Loading branch information
kant2002 authored Apr 14, 2022
1 parent b2ed250 commit 32e03eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
28 changes: 14 additions & 14 deletions src/coreclr/inc/corhlpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void __stdcall DecoderInit(void *pThis, COR_ILMETHOD *header)
#ifdef HOST_64BIT
if((((size_t) header) & 3) == 0) // header is aligned
#else
_ASSERTE((((size_t) header) & 3) == 0); // header is aligned
assert((((size_t) header) & 3) == 0); // header is aligned
#endif
{
*((COR_ILMETHOD_FAT *)decoder) = header->Fat;
Expand Down Expand Up @@ -129,18 +129,18 @@ unsigned __stdcall IlmethodEmit(unsigned size, COR_ILMETHOD_FAT* header,
}
else {
// Fat format
_ASSERTE((((size_t) outBuff) & 3) == 0); // header is dword aligned
assert((((size_t) outBuff) & 3) == 0); // header is dword aligned
COR_ILMETHOD_FAT* fatHeader = (COR_ILMETHOD_FAT*) outBuff;
outBuff += sizeof(COR_ILMETHOD_FAT);
*fatHeader = *header;
fatHeader->SetFlags(fatHeader->GetFlags() | CorILMethod_FatFormat);
_ASSERTE((fatHeader->GetFlags() & CorILMethod_FormatMask) == CorILMethod_FatFormat);
assert((fatHeader->GetFlags() & CorILMethod_FormatMask) == CorILMethod_FatFormat);
if (moreSections)
fatHeader->SetFlags(fatHeader->GetFlags() | CorILMethod_MoreSects);
fatHeader->SetSize(sizeof(COR_ILMETHOD_FAT) / 4);
}
#ifndef SOS_INCLUDE
_ASSERTE(&origBuff[size] == outBuff);
assert(&origBuff[size] == outBuff);
#endif // !SOS_INCLUDE
return(size);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ unsigned __stdcall SectEH_Emit(unsigned size, unsigned ehCount,
if (size == 0)
return(0);

_ASSERTE((((size_t) outBuff) & 3) == 0); // header is dword aligned
assert((((size_t) outBuff) & 3) == 0); // header is dword aligned
BYTE* origBuff = outBuff;
if (ehCount <= 0)
return 0;
Expand All @@ -234,11 +234,11 @@ unsigned __stdcall SectEH_Emit(unsigned size, unsigned ehCount,
fatClause->GetHandlerLength() > 0xFF) {
break; // fall through and generate as FAT
}
_ASSERTE((fatClause->GetFlags() & ~0xFFFF) == 0);
_ASSERTE((fatClause->GetTryOffset() & ~0xFFFF) == 0);
_ASSERTE((fatClause->GetTryLength() & ~0xFF) == 0);
_ASSERTE((fatClause->GetHandlerOffset() & ~0xFFFF) == 0);
_ASSERTE((fatClause->GetHandlerLength() & ~0xFF) == 0);
assert((fatClause->GetFlags() & ~0xFFFF) == 0);
assert((fatClause->GetTryOffset() & ~0xFFFF) == 0);
assert((fatClause->GetTryLength() & ~0xFF) == 0);
assert((fatClause->GetHandlerOffset() & ~0xFFFF) == 0);
assert((fatClause->GetHandlerLength() & ~0xFF) == 0);

COR_ILMETHOD_SECT_EH_CLAUSE_SMALL* smallClause = (COR_ILMETHOD_SECT_EH_CLAUSE_SMALL*)&EHSect->Clauses[i];
smallClause->SetFlags((CorExceptionFlag) fatClause->GetFlags());
Expand All @@ -259,7 +259,7 @@ unsigned __stdcall SectEH_Emit(unsigned size, unsigned ehCount,
EHSect->DataSize = (BYTE) EHSect->Size(ehCount);
#endif // !SOS_INCLUDE
EHSect->Reserved = 0;
_ASSERTE(EHSect->DataSize == EHSect->Size(ehCount)); // make sure didn't overflow
assert(EHSect->DataSize == EHSect->Size(ehCount)); // make sure didn't overflow
outBuff = (BYTE*) &EHSect->Clauses[ehCount];
// Set the offsets for the exception type tokens.
if (ehTypeOffsets)
Expand All @@ -268,7 +268,7 @@ unsigned __stdcall SectEH_Emit(unsigned size, unsigned ehCount,
COR_ILMETHOD_SECT_EH_CLAUSE_SMALL* smallClause = (COR_ILMETHOD_SECT_EH_CLAUSE_SMALL*)&EHSect->Clauses[i];
if (smallClause->GetFlags() == COR_ILEXCEPTION_CLAUSE_NONE)
{
_ASSERTE(! IsNilToken(smallClause->GetClassToken()));
assert(! IsNilToken(smallClause->GetClassToken()));
ehTypeOffsets[i] = (ULONG)((BYTE *)&smallClause->ClassToken - origBuff);
}
}
Expand All @@ -285,15 +285,15 @@ unsigned __stdcall SectEH_Emit(unsigned size, unsigned ehCount,
EHSect->SetDataSize(EHSect->Size(ehCount));
memcpy(EHSect->Clauses, clauses, ehCount * sizeof(COR_ILMETHOD_SECT_EH_CLAUSE_FAT));
outBuff = (BYTE*) &EHSect->Clauses[ehCount];
_ASSERTE(&origBuff[size] == outBuff);
assert(&origBuff[size] == outBuff);
// Set the offsets for the exception type tokens.
if (ehTypeOffsets)
{
for (unsigned int i = 0; i < ehCount; i++) {
COR_ILMETHOD_SECT_EH_CLAUSE_FAT* fatClause = (COR_ILMETHOD_SECT_EH_CLAUSE_FAT*)&EHSect->Clauses[i];
if (fatClause->GetFlags() == COR_ILEXCEPTION_CLAUSE_NONE)
{
_ASSERTE(! IsNilToken(fatClause->GetClassToken()));
assert(! IsNilToken(fatClause->GetClassToken()));
ehTypeOffsets[i] = (ULONG)((BYTE *)&fatClause->ClassToken - origBuff);
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/coreclr/inc/corhlpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define CORHLPR_TURNED_FPO_ON 1
#endif

#include <assert.h>
#include "cor.h"
#include "corhdr.h"
#include "corerror.h"
Expand Down Expand Up @@ -82,10 +83,6 @@ do { hr = (EXPR); if(FAILED(hr)) { goto LABEL; } } while (0)
#endif


#ifndef _ASSERTE
#define _ASSERTE(expr)
#endif

#if !BIGENDIAN
#define VAL16(x) x
#define VAL32(x) x
Expand Down Expand Up @@ -259,31 +256,31 @@ typedef struct tagCOR_ILMETHOD_SECT_EH_CLAUSE_SMALL : public IMAGE_COR_ILMETHOD_
return VAL16(TryOffset);
}
void SetTryOffset(DWORD Offset) {
_ASSERTE((Offset & ~0xffff) == 0);
assert((Offset & ~0xffff) == 0);
TryOffset = VAL16(Offset);
}

DWORD GetTryLength() const {
return TryLength;
}
void SetTryLength(DWORD Length) {
_ASSERTE((Length & ~0xff) == 0);
assert((Length & ~0xff) == 0);
TryLength = Length;
}

DWORD GetHandlerOffset() const {
return VAL16(HandlerOffset);
}
void SetHandlerOffset(DWORD Offset) {
_ASSERTE((Offset & ~0xffff) == 0);
assert((Offset & ~0xffff) == 0);
HandlerOffset = VAL16(Offset);
}

DWORD GetHandlerLength() const {
return HandlerLength;
}
void SetHandlerLength(DWORD Length) {
_ASSERTE((Length & ~0xff) == 0);
assert((Length & ~0xff) == 0);
HandlerLength = Length;
}

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/pal/inc/pal_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ extern "C" {

#endif // __cplusplus

#ifndef _ASSERTE
#if defined(_DEBUG)
#define _ASSERTE(e) do { \
if (!(e)) { \
fprintf (stderr, \
PAL_fprintf (PAL_get_stderr(PAL_get_caller), \
"ASSERT FAILED\n" \
"\tExpression: %s\n" \
"\tLocation: line %d in %s\n" \
Expand All @@ -48,6 +49,7 @@ extern "C" {
#else // !DEBUG
#define _ASSERTE(e) ((void)0)
#endif
#endif // _ASSERTE

#ifndef assert
#define assert(e) _ASSERTE(e)
Expand Down
2 changes: 2 additions & 0 deletions src/tests/profiler/native/rejitprofiler/ilrewriter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#define _ASSERTE(e) ((void)0)

#include <cstring>
#include <corhlpr.cpp>
#include "ilrewriter.h"
Expand Down

0 comments on commit 32e03eb

Please sign in to comment.