Blame SOURCES/runtime-62170-clang13.patch

28e7ba
From a89c562f9389fdc2bb1356d3da782d0063951e14 Mon Sep 17 00:00:00 2001
28e7ba
From: Jan Vorlicek <jan.vorlicek@volny.cz>
28e7ba
Date: Tue, 30 Nov 2021 10:55:21 +0100
28e7ba
Subject: [PATCH] Fix clang 13 induced runtime issues (#62170)
28e7ba
28e7ba
The clang 13 optimizer started to assume that "this" pointer is always
28e7ba
properly aligned. That lead to elimination of some code that was actually
28e7ba
needed.
28e7ba
It also takes pointer aliasing rules more strictly in one place in jit.
28e7ba
That caused the optimizer to falsely assume that a callee with an argument
28e7ba
passed by reference is not modifying that argument and used a stale
28e7ba
copy of the original value at the caller site.
28e7ba
28e7ba
This change fixes both of the issues. With this fix, runtime compiled
28e7ba
using clang 13 seems to be fully functional.
28e7ba
---
28e7ba
 src/coreclr/src/inc/corhlpr.h           | 8 ++++----
28e7ba
 src/coreclr/src/jit/bitsetasshortlong.h | 4 ++--
28e7ba
 2 files changed, 6 insertions(+), 6 deletions(-)
28e7ba
28e7ba
diff --git a/src/coreclr/src/inc/corhlpr.h b/src/coreclr/src/inc/corhlpr.h
28e7ba
index 450514da95c..427e8cdc0ff 100644
28e7ba
--- a/src/coreclr/src/inc/corhlpr.h
28e7ba
+++ b/src/coreclr/src/inc/corhlpr.h
28e7ba
@@ -336,7 +336,7 @@ struct COR_ILMETHOD_SECT
28e7ba
     const COR_ILMETHOD_SECT* Next() const
28e7ba
     {
28e7ba
         if (!More()) return(0);
28e7ba
-        return ((COR_ILMETHOD_SECT*)(((BYTE *)this) + DataSize()))->Align();
28e7ba
+        return ((COR_ILMETHOD_SECT*)Align(((BYTE *)this) + DataSize()));
28e7ba
     }
28e7ba
 
28e7ba
     const BYTE* Data() const
28e7ba
@@ -374,9 +374,9 @@ struct COR_ILMETHOD_SECT
28e7ba
         return((AsSmall()->Kind & CorILMethod_Sect_FatFormat) != 0);
28e7ba
     }
28e7ba
 
28e7ba
-    const COR_ILMETHOD_SECT* Align() const
28e7ba
+    static const void* Align(const void* p)
28e7ba
     {
28e7ba
-        return((COR_ILMETHOD_SECT*) ((((UINT_PTR) this) + 3) & ~3));
28e7ba
+        return((void*) ((((UINT_PTR) p) + 3) & ~3));
28e7ba
     }
28e7ba
 
28e7ba
 protected:
28e7ba
@@ -579,7 +579,7 @@ typedef struct tagCOR_ILMETHOD_FAT : IMAGE_COR_ILMETHOD_FAT
28e7ba
 
28e7ba
     const COR_ILMETHOD_SECT* GetSect() const {
28e7ba
         if (!More()) return (0);
28e7ba
-        return(((COR_ILMETHOD_SECT*) (GetCode() + GetCodeSize()))->Align());
28e7ba
+        return(((COR_ILMETHOD_SECT*) COR_ILMETHOD_SECT::Align(GetCode() + GetCodeSize())));
28e7ba
     }
28e7ba
 } COR_ILMETHOD_FAT;
28e7ba
 
28e7ba
diff --git a/src/coreclr/src/jit/bitsetasshortlong.h b/src/coreclr/src/jit/bitsetasshortlong.h
28e7ba
index 078cdc810e9..4c52819853f 100644
28e7ba
--- a/src/coreclr/src/jit/bitsetasshortlong.h
28e7ba
+++ b/src/coreclr/src/jit/bitsetasshortlong.h
28e7ba
@@ -345,7 +345,7 @@ public:
28e7ba
     {
28e7ba
         if (IsShort(env))
28e7ba
         {
28e7ba
-            (size_t&)out = (size_t)out & ((size_t)gen | (size_t)in);
28e7ba
+            out = (BitSetShortLongRep)((size_t)out & ((size_t)gen | (size_t)in));
28e7ba
         }
28e7ba
         else
28e7ba
         {
28e7ba
@@ -361,7 +361,7 @@ public:
28e7ba
     {
28e7ba
         if (IsShort(env))
28e7ba
         {
28e7ba
-            (size_t&)in = (size_t)use | ((size_t)out & ~(size_t)def);
28e7ba
+            in = (BitSetShortLongRep)((size_t)use | ((size_t)out & ~(size_t)def));
28e7ba
         }
28e7ba
         else
28e7ba
         {
28e7ba
-- 
28e7ba
2.33.1
28e7ba