From 78d621fb72dd102f6c931a3d5d590d246385b8ba Mon Sep 17 00:00:00 2001
From: Jessica Clarke <jrtc27@jrtc27.com>
Date: Fri, 12 Aug 2022 23:41:25 +0100
Subject: [PATCH 8/8] Silence harmless warnings on CHERI by using INT2PTR where
 appropriate

On CHERI, pointers are implemented using unforgeable capabilities that
include bounds and permissions metadata to provide fine-grained spatial
and referential memory safety, as well as revocation by sweeping memory
to provide heap temporal memory safety. In order to ensure round trips
via (u)intptr_t preserve this metadata, (u)intptr_t are themselves
represented as capabilities, not plain integers. In order to catch
programming errors caused by using an integer type other than those to
hold a pointer, CHERI LLVM emits a warning by default whenever a plain
integer is cast directly to a pointer (except for integer constants, so
that idioms like (void *)-1 continue to work), since it is likely the
source of that cast should have been a (u)intptr_t instead. Three
instances of this warning remain when compiling for CHERI (note that
Tcl_SetHashValue internally casts to void *), all of which are harmless;
silence them by using INT2PTR.
---
 generic/tclCompCmdsSZ.c | 3 ++-
 generic/tclExecute.c    | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c
index cd1ca228a..16919f893 100644
--- a/generic/tclCompCmdsSZ.c
+++ b/generic/tclCompCmdsSZ.c
@@ -2435,7 +2435,8 @@ IssueSwitchJumpTable(
 		 * point to here.
 		 */
 
-		Tcl_SetHashValue(hPtr, CurrentOffset(envPtr) - jumpLocation);
+		Tcl_SetHashValue(hPtr,
+			INT2PTR(CurrentOffset(envPtr) - jumpLocation));
 	    }
 	    Tcl_DStringFree(&buffer);
 	} else {
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 52d13b93f..d32d71adf 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -6269,7 +6269,7 @@ TEBCresume(
 
 	TclNewObj(tmpPtr);
 	tmpPtr->internalRep.twoPtrValue.ptr1 = NULL;
-	tmpPtr->internalRep.twoPtrValue.ptr2 = (void *)iterMax;
+	tmpPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(iterMax);
 	PUSH_OBJECT(tmpPtr); /* iterCounts object */
 
 	/*
@@ -6314,7 +6314,7 @@ TEBCresume(
 	     * Set the variables and jump back to run the body
 	     */
 
-	    tmpPtr->internalRep.twoPtrValue.ptr1 =(void *)(iterNum + 1);
+	    tmpPtr->internalRep.twoPtrValue.ptr1 = INT2PTR(iterNum + 1);
 
 	    listTmpDepth = numLists + 1;
 
-- 
2.34.GIT

