Blame SOURCES/runtime-62170-clang13.patch

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