Skip to content

Commit

Permalink
Fix clang 13 induced runtime issues (#62170)
Browse files Browse the repository at this point in the history
The clang 13 optimizer started to assume that "this" pointer is always
properly aligned. That lead to elimination of some code that was actually
needed.
It also takes pointer aliasing rules more strictly in one place in jit.
That caused the optimizer to falsely assume that a callee with an argument
passed by reference is not modifying that argument and used a stale
copy of the original value at the caller site.

This change fixes both of the issues. With this fix, runtime compiled
using clang 13 seems to be fully functional.
  • Loading branch information
janvorli committed Nov 30, 2021
1 parent 1281b91 commit a47e5d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/coreclr/inc/corhlpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ struct COR_ILMETHOD_SECT
const COR_ILMETHOD_SECT* Next() const
{
if (!More()) return(0);
return ((COR_ILMETHOD_SECT*)(((BYTE *)this) + DataSize()))->Align();
return ((COR_ILMETHOD_SECT*)Align(((BYTE *)this) + DataSize()));
}

const BYTE* Data() const
Expand Down Expand Up @@ -374,9 +374,9 @@ struct COR_ILMETHOD_SECT
return((AsSmall()->Kind & CorILMethod_Sect_FatFormat) != 0);
}

const COR_ILMETHOD_SECT* Align() const
static const void* Align(const void* p)
{
return((COR_ILMETHOD_SECT*) ((((UINT_PTR) this) + 3) & ~3));
return((void*) ((((UINT_PTR) p) + 3) & ~3));
}

protected:
Expand Down Expand Up @@ -579,7 +579,7 @@ typedef struct tagCOR_ILMETHOD_FAT : IMAGE_COR_ILMETHOD_FAT

const COR_ILMETHOD_SECT* GetSect() const {
if (!More()) return (0);
return(((COR_ILMETHOD_SECT*) (GetCode() + GetCodeSize()))->Align());
return(((COR_ILMETHOD_SECT*) COR_ILMETHOD_SECT::Align(GetCode() + GetCodeSize())));
}
} COR_ILMETHOD_FAT;

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/bitsetasshortlong.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class BitSetOps</*BitSetType*/ BitSetShortLongRep,
{
if (IsShort(env))
{
(size_t&)(int&) out = (size_t)out & ((size_t)gen | (size_t)in);
out = (BitSetShortLongRep)((size_t)out & ((size_t)gen | (size_t)in));
}
else
{
Expand All @@ -361,7 +361,7 @@ class BitSetOps</*BitSetType*/ BitSetShortLongRep,
{
if (IsShort(env))
{
(size_t&)(int&) in = (size_t)use | ((size_t)out & ~(size_t)def);
in = (BitSetShortLongRep)((size_t)use | ((size_t)out & ~(size_t)def));
}
else
{
Expand Down

0 comments on commit a47e5d1

Please sign in to comment.