Blame SOURCES/coreclr-clang13.patch

937df4
From 9a2857177a8a2a388298ad5674f6e5edd1e5b853 Mon Sep 17 00:00:00 2001
937df4
From: Jan Vorlicek <jan.vorlicek@volny.cz>
937df4
Date: Tue, 4 Jan 2022 23:51:52 +0100
937df4
Subject: [PATCH] Fix build with Clang 13 (#63314)
937df4
937df4
* Fix clang 13 induced runtime issues (#62170)
937df4
937df4
The clang 13 optimizer started to assume that "this" pointer is always
937df4
properly aligned. That lead to elimination of some code that was actually
937df4
needed.
937df4
It also takes pointer aliasing rules more strictly in one place in jit.
937df4
That caused the optimizer to falsely assume that a callee with an argument
937df4
passed by reference is not modifying that argument and used a stale
937df4
copy of the original value at the caller site.
937df4
937df4
This change fixes both of the issues. With this fix, runtime compiled
937df4
using clang 13 seems to be fully functional.
937df4
937df4
* Fix build with clang 13 (#60328)
937df4
---
937df4
 src/inc/corhlpr.h           | 8 ++++----
937df4
 src/jit/bitsetasshortlong.h | 4 ++--
937df4
 2 files changed, 6 insertions(+), 6 deletions(-)
937df4
937df4
diff --git a/src/inc/corhlpr.h b/src/inc/corhlpr.h
937df4
index 5b263a5382..c512069fca 100644
937df4
--- a/src/inc/corhlpr.h
937df4
+++ b/src/inc/corhlpr.h
937df4
@@ -335,7 +335,7 @@ struct COR_ILMETHOD_SECT
937df4
     const COR_ILMETHOD_SECT* Next() const   
937df4
     {
937df4
         if (!More()) return(0);
937df4
-        return ((COR_ILMETHOD_SECT*)(((BYTE *)this) + DataSize()))->Align();
937df4
+        return ((COR_ILMETHOD_SECT*)Align(((BYTE *)this) + DataSize()));
937df4
     }
937df4
 
937df4
     const BYTE* Data() const 
937df4
@@ -373,9 +373,9 @@ struct COR_ILMETHOD_SECT
937df4
         return((AsSmall()->Kind & CorILMethod_Sect_FatFormat) != 0); 
937df4
     }
937df4
 
937df4
-    const COR_ILMETHOD_SECT* Align() const        
937df4
+    static const void* Align(const void* p)
937df4
     { 
937df4
-        return((COR_ILMETHOD_SECT*) ((((UINT_PTR) this) + 3) & ~3));  
937df4
+        return((void*) ((((UINT_PTR) p) + 3) & ~3));
937df4
     }
937df4
 
937df4
 protected:
937df4
@@ -578,7 +578,7 @@ typedef struct tagCOR_ILMETHOD_FAT : IMAGE_COR_ILMETHOD_FAT
937df4
 
937df4
     const COR_ILMETHOD_SECT* GetSect() const {
937df4
         if (!More()) return (0);
937df4
-        return(((COR_ILMETHOD_SECT*) (GetCode() + GetCodeSize()))->Align());
937df4
+        return(((COR_ILMETHOD_SECT*) COR_ILMETHOD_SECT::Align(GetCode() + GetCodeSize())));
937df4
     }
937df4
 } COR_ILMETHOD_FAT;
937df4
 
937df4
diff --git a/src/jit/bitsetasshortlong.h b/src/jit/bitsetasshortlong.h
937df4
index 17e0e3a69c..0c40283ce5 100644
937df4
--- a/src/jit/bitsetasshortlong.h
937df4
+++ b/src/jit/bitsetasshortlong.h
937df4
@@ -346,7 +346,7 @@ public:
937df4
     {
937df4
         if (IsShort(env))
937df4
         {
937df4
-            (size_t&)out = (size_t)out & ((size_t)gen | (size_t)in);
937df4
+            out = (BitSetShortLongRep)((size_t)out & ((size_t)gen | (size_t)in));
937df4
         }
937df4
         else
937df4
         {
937df4
@@ -362,7 +362,7 @@ public:
937df4
     {
937df4
         if (IsShort(env))
937df4
         {
937df4
-            (size_t&)in = (size_t)use | ((size_t)out & ~(size_t)def);
937df4
+            in = (BitSetShortLongRep)((size_t)use | ((size_t)out & ~(size_t)def));
937df4
         }
937df4
         else
937df4
         {
937df4
-- 
937df4
2.34.1
937df4