Skip to content

Instantly share code, notes, and snippets.

@rfht
Forked from brynet/devilutionX-clang.diff
Last active June 29, 2019 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfht/4bb99a279c6572698cf49175d5c534ed to your computer and use it in GitHub Desktop.
Save rfht/4bb99a279c6572698cf49175d5c534ed to your computer and use it in GitHub Desktop.
devilutionX clang fixes
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56bf70f9..884ed0e7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,7 +35,7 @@ if(NIGHTLY_BUILD)
set(FASTER ON)
endif()
-if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
+if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD OR ${CMAKE_SYSTEM_NAME} STREQUAL OpenBSD)
set(ASAN OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DO_LARGEFILE=0 -Dstat64=stat -Dlstat64=lstat -Dlseek64=lseek -Doff64_t=off_t -Dfstat64=fstat -Dftruncate64=ftruncate")
endif()
@@ -283,7 +283,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Silence warnings about __int64 alignment hack not always being applicable
target_compile_options(devilutionx PRIVATE -Wno-ignored-attributes)
# Fix: error: cast from pointer to smaller type 'unsigned char' loses information
- target_compile_options(devilution PRIVATE -fms-extensions -fms-compatibility -fms-compatibility-version=19.00)
+ #target_compile_options(devilution PRIVATE -fms-extensions -fms-compatibility -fms-compatibility-version=19.00)
# Silence appfat.cpp warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
endif()
diff --git a/Source/engine.cpp b/Source/engine.cpp
index 219795e8..2cd5296c 100644
--- a/Source/engine.cpp
+++ b/Source/engine.cpp
@@ -518,14 +518,14 @@ void CelDecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nW
dst = pDecodeTo;
tbl = &pLightTbl[light_table_index * 256];
w = nWidth;
- shift = (BYTE)dst & 1;
+ shift = (uintptr_t)dst & 1;
for (; src != &pRLEBytes[nDataSize]; dst -= BUFFER_WIDTH + w, shift = (shift + 1) & 1) {
for (i = w; i;) {
width = *src++;
if (!(width & 0x80)) {
i -= width;
- if (((BYTE)dst & 1) == shift) {
+ if (((uintptr_t)dst & 1) == shift) {
if (!(width & 1)) {
goto L_ODD;
} else {
@@ -1311,7 +1311,7 @@ void Cel2DecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int n
dst = pDecodeTo;
tbl = &pLightTbl[light_table_index * 256];
w = nWidth;
- shift = (BYTE)dst & 1;
+ shift = (uintptr_t)dst & 1;
for (; src != &pRLEBytes[nDataSize]; dst -= BUFFER_WIDTH + w, shift = (shift + 1) & 1) {
for (i = w; i;) {
@@ -1319,7 +1319,7 @@ void Cel2DecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int n
if (!(width & 0x80)) {
i -= width;
if (dst < gpBufEnd) {
- if (((BYTE)dst & 1) == shift) {
+ if (((uintptr_t)dst & 1) == shift) {
if (!(width & 1)) {
goto L_ODD;
} else {
diff --git a/Source/fault.cpp b/Source/fault.cpp
index 5a4091ce..75a35b79 100644
--- a/Source/fault.cpp
+++ b/Source/fault.cpp
@@ -153,7 +153,7 @@ void fault_unknown_module(LPCVOID lpAddress, LPSTR lpModuleName, int iMaxLength,
if (dosHeader && dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
ntOffset = dosHeader->e_lfanew;
if (ntOffset) {
- ntHeader = (PIMAGE_NT_HEADERS)((DWORD)dosHeader + ntOffset);
+ ntHeader = (PIMAGE_NT_HEADERS)((uintptr_t)dosHeader + ntOffset);
if (ntHeader->Signature == IMAGE_NT_SIGNATURE) {
section = IMAGE_FIRST_SECTION(ntHeader);
numSections = ntHeader->FileHeader.NumberOfSections;
@@ -193,7 +193,7 @@ void fault_call_stack(void *instr, STACK_FRAME *stackFrame)
oldStackFrame = stackFrame;
stackFrame = stackFrame->pNext;
- if ((DWORD)stackFrame % 4 != 0)
+ if ((uintptr_t)stackFrame % 4 != 0)
break;
} while (stackFrame > oldStackFrame && !IsBadWritePtr(stackFrame, 8));
diff --git a/Source/init.cpp b/Source/init.cpp
index 5da55a72..ba22540d 100644
--- a/Source/init.cpp
+++ b/Source/init.cpp
@@ -123,7 +123,7 @@ void init_disable_screensaver(BOOLEAN disable)
// SystemParametersInfo() with SPI_SETSCREENSAVEACTIVE/SPI_SETPOWEROFFACTIVE/SPI_SETLOWPOWERACTIVE
v6 = disable;
- if (!RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ | KEY_WRITE, (PHKEY)&phkResult)) {
+ if (!RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ | KEY_WRITE, (uintptr_t)&phkResult)) {
if (v6) {
cbData = 16;
if (!RegQueryValueEx(phkResult, "ScreenSaveActive", 0, &Type, (LPBYTE)Data, &cbData))
diff --git a/Source/render.cpp b/Source/render.cpp
index 668769b4..c41f78b9 100644
--- a/Source/render.cpp
+++ b/Source/render.cpp
@@ -164,7 +164,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} while (i);
break;
case 1: // upper (top transparent), with lighting
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
do {
yy_32 = 32;
@@ -181,7 +181,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
}
if (dst < gpBufEnd)
return;
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
asm_trans_light_cel_0_2(width, tbl, &dst, &src);
} else {
asm_trans_light_cel_1_3(width, tbl, &dst, &src);
@@ -238,7 +238,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - xx_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -252,7 +252,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - yy_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -301,7 +301,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - xx_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -359,7 +359,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} while (i);
break;
case 9: // upper (top transparent), without lighting
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
yy_32 = 32;
LABEL_251:
xx_32 = 32;
@@ -383,7 +383,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
xx_32 -= width;
if (dst < gpBufEnd)
return;
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
chk_sh_and = width >> 1;
if (!(width & 1))
goto LABEL_258;
@@ -775,7 +775,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} while (i);
break;
case 1: // upper (top transparent), black
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
while (1) {
yy_32 = 32;
@@ -788,7 +788,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
if (dst < gpBufEnd)
return;
src += width;
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
chk_sh_and = width >> 1;
if (!(width & 1))
goto LABEL_378;
@@ -1386,7 +1386,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
++dst;
--i;
} while (i);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst -= 800;
--gpDrawMask;
--yy_32;
@@ -1471,7 +1471,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
xx_32 = 30;
while (dst >= gpBufEnd) {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -1480,7 +1480,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
if (dst < gpBufEnd)
break;
asm_cel_light_edge(32 - yy_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -1502,7 +1502,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
do {
if (dst < gpBufEnd)
break;
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
asm_trans_light_mask(32, tbl, &dst, &src, *gpDrawMask);
dst -= 800;
--gpDrawMask;
@@ -1516,7 +1516,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
xx_32 = 30;
while (dst >= gpBufEnd) {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -1526,7 +1526,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
if (dst < gpBufEnd)
break;
asm_trans_light_mask(32, tbl, &dst, &src, *gpDrawMask);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst -= 800;
--gpDrawMask;
--yy_32;
@@ -2107,7 +2107,7 @@ void drawUpperScreen(BYTE *pBuff)
xx_32 = 30;
while (dst >= gpBufEnd) {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -2116,7 +2116,7 @@ void drawUpperScreen(BYTE *pBuff)
if (dst < gpBufEnd)
break;
asm_cel_light_edge(32 - yy_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -2149,7 +2149,7 @@ void drawUpperScreen(BYTE *pBuff)
xx_32 = 30;
while (dst >= gpBufEnd) {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -2465,7 +2465,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} while (i);
break;
case 1: // lower (top transparent), black
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
LABEL_412:
yy_32 = 32;
@@ -2489,7 +2489,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
yy_32 -= width;
if (dst < gpBufEnd) {
src += width;
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
chk_sh_and = width >> 1;
if (!(width & 1))
goto LABEL_420;
@@ -2895,7 +2895,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} while (i);
break;
case 1: // lower (top transparent), with lighting
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
do {
yy_32 = 32;
@@ -2912,7 +2912,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
}
yy_32 -= width;
if (dst < gpBufEnd) {
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
asm_trans_light_cel_0_2(width, tbl, &dst, &src);
} else {
asm_trans_light_cel_1_3(width, tbl, &dst, &src);
@@ -3011,7 +3011,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - yy_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -3031,7 +3031,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - xx_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -3128,7 +3128,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - xx_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -3175,7 +3175,7 @@ LABEL_11:
} while (i);
break;
case 9: // lower (top transparent), without lighting
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
while (1) {
yy_32 = 32;
@@ -3186,7 +3186,7 @@ LABEL_11:
break;
yy_32 -= width;
if (dst < gpBufEnd) {
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
chk_sh_and = width >> 1;
if (!(width & 1))
goto LABEL_280;
@@ -4042,7 +4042,7 @@ void drawBottomArchesLowerScreen(BYTE *pBuff, unsigned int *pMask)
}
do {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -4096,7 +4096,7 @@ void drawBottomArchesLowerScreen(BYTE *pBuff, unsigned int *pMask)
do {
if (dst < gpBufEnd) {
asm_trans_light_mask(32, tbl, &dst, &src, *gpDrawMask);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
} else {
src += 32;
dst += 32;
@@ -4114,7 +4114,7 @@ void drawBottomArchesLowerScreen(BYTE *pBuff, unsigned int *pMask)
}
do {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -4396,7 +4396,7 @@ void drawBottomArchesLowerScreen(BYTE *pBuff, unsigned int *pMask)
++dst;
--i;
} while (i);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
} else {
src += 32;
dst += 32;
@@ -4821,7 +4821,7 @@ void drawLowerScreen(BYTE *pBuff)
}
do {
asm_cel_light_edge(32 - yy_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -4834,7 +4834,7 @@ void drawLowerScreen(BYTE *pBuff)
}
do {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -4901,7 +4901,7 @@ void drawLowerScreen(BYTE *pBuff)
}
do {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
diff --git a/SourceS/miniwin.h b/SourceS/miniwin.h
index a179852b..1740fdd2 100644
--- a/SourceS/miniwin.h
+++ b/SourceS/miniwin.h
@@ -3,7 +3,7 @@
#include <ctype.h>
#include <math.h>
// work around https://reviews.llvm.org/D51265
-#if defined(__APPLE__) || defined(__FreeBSD__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include "macos_stdarg.h"
#else
#include <stdarg.h>
@@ -17,6 +17,10 @@
#if !defined(_MSC_VER) && defined(DEVILUTION_ENGINE)
#if defined(__x86_64__) || defined(__i386__)
#include <x86intrin.h>
+#if defined(__clang__)
+#define _rotl(x, v) __builtin_rotateleft32(x, v)
+#define _rotr(x, v) __builtin_rotateright32(x, v)
+#endif
#else
unsigned int _rotl(unsigned int value, int shift);
unsigned int _rotr(unsigned int value, int shift);
diff --git a/defs.h b/defs.h
index 962ed34b..649cae7b 100644
--- a/defs.h
+++ b/defs.h
@@ -151,7 +151,7 @@
// Typedef for the function pointer
typedef void (*_PVFV)(void);
-#if defined(_MSC_VER) && !(defined(__APPLE__)|| defined(__FreeBSD__))
+#if defined(_MSC_VER) && !(defined(__APPLE__)|| defined(__FreeBSD__) || defined(__OpenBSD__))
// Define our segment names
#define SEGMENT_C_INIT ".CRT$XCU"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 56bf70f9..884ed0e7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,7 +35,7 @@ if(NIGHTLY_BUILD)
set(FASTER ON)
endif()
-if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)
+if(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD OR ${CMAKE_SYSTEM_NAME} STREQUAL OpenBSD)
set(ASAN OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DO_LARGEFILE=0 -Dstat64=stat -Dlstat64=lstat -Dlseek64=lseek -Doff64_t=off_t -Dfstat64=fstat -Dftruncate64=ftruncate")
endif()
@@ -283,7 +283,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Silence warnings about __int64 alignment hack not always being applicable
target_compile_options(devilutionx PRIVATE -Wno-ignored-attributes)
# Fix: error: cast from pointer to smaller type 'unsigned char' loses information
- target_compile_options(devilution PRIVATE -fms-extensions -fms-compatibility -fms-compatibility-version=19.00)
+ #target_compile_options(devilution PRIVATE -fms-extensions -fms-compatibility -fms-compatibility-version=19.00)
# Silence appfat.cpp warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
endif()
diff --git a/Source/engine.cpp b/Source/engine.cpp
index 219795e8..2cd5296c 100644
--- a/Source/engine.cpp
+++ b/Source/engine.cpp
@@ -518,14 +518,14 @@ void CelDecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int nW
dst = pDecodeTo;
tbl = &pLightTbl[light_table_index * 256];
w = nWidth;
- shift = (BYTE)dst & 1;
+ shift = (uintptr_t)dst & 1;
for (; src != &pRLEBytes[nDataSize]; dst -= BUFFER_WIDTH + w, shift = (shift + 1) & 1) {
for (i = w; i;) {
width = *src++;
if (!(width & 0x80)) {
i -= width;
- if (((BYTE)dst & 1) == shift) {
+ if (((uintptr_t)dst & 1) == shift) {
if (!(width & 1)) {
goto L_ODD;
} else {
@@ -1311,7 +1311,7 @@ void Cel2DecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int n
dst = pDecodeTo;
tbl = &pLightTbl[light_table_index * 256];
w = nWidth;
- shift = (BYTE)dst & 1;
+ shift = (uintptr_t)dst & 1;
for (; src != &pRLEBytes[nDataSize]; dst -= BUFFER_WIDTH + w, shift = (shift + 1) & 1) {
for (i = w; i;) {
@@ -1319,7 +1319,7 @@ void Cel2DecDatLightTrans(BYTE *pDecodeTo, BYTE *pRLEBytes, int nDataSize, int n
if (!(width & 0x80)) {
i -= width;
if (dst < gpBufEnd) {
- if (((BYTE)dst & 1) == shift) {
+ if (((uintptr_t)dst & 1) == shift) {
if (!(width & 1)) {
goto L_ODD;
} else {
diff --git a/Source/fault.cpp b/Source/fault.cpp
index 5a4091ce..75a35b79 100644
--- a/Source/fault.cpp
+++ b/Source/fault.cpp
@@ -153,7 +153,7 @@ void fault_unknown_module(LPCVOID lpAddress, LPSTR lpModuleName, int iMaxLength,
if (dosHeader && dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
ntOffset = dosHeader->e_lfanew;
if (ntOffset) {
- ntHeader = (PIMAGE_NT_HEADERS)((DWORD)dosHeader + ntOffset);
+ ntHeader = (PIMAGE_NT_HEADERS)((uintptr_t)dosHeader + ntOffset);
if (ntHeader->Signature == IMAGE_NT_SIGNATURE) {
section = IMAGE_FIRST_SECTION(ntHeader);
numSections = ntHeader->FileHeader.NumberOfSections;
@@ -193,7 +193,7 @@ void fault_call_stack(void *instr, STACK_FRAME *stackFrame)
oldStackFrame = stackFrame;
stackFrame = stackFrame->pNext;
- if ((DWORD)stackFrame % 4 != 0)
+ if ((uintptr_t)stackFrame % 4 != 0)
break;
} while (stackFrame > oldStackFrame && !IsBadWritePtr(stackFrame, 8));
diff --git a/Source/init.cpp b/Source/init.cpp
index 5da55a72..ba22540d 100644
--- a/Source/init.cpp
+++ b/Source/init.cpp
@@ -123,7 +123,7 @@ void init_disable_screensaver(BOOLEAN disable)
// SystemParametersInfo() with SPI_SETSCREENSAVEACTIVE/SPI_SETPOWEROFFACTIVE/SPI_SETLOWPOWERACTIVE
v6 = disable;
- if (!RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ | KEY_WRITE, (PHKEY)&phkResult)) {
+ if (!RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ | KEY_WRITE, (uintptr_t)&phkResult)) {
if (v6) {
cbData = 16;
if (!RegQueryValueEx(phkResult, "ScreenSaveActive", 0, &Type, (LPBYTE)Data, &cbData))
diff --git a/Source/render.cpp b/Source/render.cpp
index 668769b4..c41f78b9 100644
--- a/Source/render.cpp
+++ b/Source/render.cpp
@@ -164,7 +164,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} while (i);
break;
case 1: // upper (top transparent), with lighting
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
do {
yy_32 = 32;
@@ -181,7 +181,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
}
if (dst < gpBufEnd)
return;
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
asm_trans_light_cel_0_2(width, tbl, &dst, &src);
} else {
asm_trans_light_cel_1_3(width, tbl, &dst, &src);
@@ -238,7 +238,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - xx_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -252,7 +252,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - yy_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -301,7 +301,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - xx_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -359,7 +359,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} while (i);
break;
case 9: // upper (top transparent), without lighting
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
yy_32 = 32;
LABEL_251:
xx_32 = 32;
@@ -383,7 +383,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
xx_32 -= width;
if (dst < gpBufEnd)
return;
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
chk_sh_and = width >> 1;
if (!(width & 1))
goto LABEL_258;
@@ -775,7 +775,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
} while (i);
break;
case 1: // upper (top transparent), black
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
while (1) {
yy_32 = 32;
@@ -788,7 +788,7 @@ void drawTopArchesUpperScreen(BYTE *pBuff)
if (dst < gpBufEnd)
return;
src += width;
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
chk_sh_and = width >> 1;
if (!(width & 1))
goto LABEL_378;
@@ -1386,7 +1386,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
++dst;
--i;
} while (i);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst -= 800;
--gpDrawMask;
--yy_32;
@@ -1471,7 +1471,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
xx_32 = 30;
while (dst >= gpBufEnd) {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -1480,7 +1480,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
if (dst < gpBufEnd)
break;
asm_cel_light_edge(32 - yy_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -1502,7 +1502,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
do {
if (dst < gpBufEnd)
break;
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
asm_trans_light_mask(32, tbl, &dst, &src, *gpDrawMask);
dst -= 800;
--gpDrawMask;
@@ -1516,7 +1516,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
xx_32 = 30;
while (dst >= gpBufEnd) {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -1526,7 +1526,7 @@ void drawBottomArchesUpperScreen(BYTE *pBuff, unsigned int *pMask)
if (dst < gpBufEnd)
break;
asm_trans_light_mask(32, tbl, &dst, &src, *gpDrawMask);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst -= 800;
--gpDrawMask;
--yy_32;
@@ -2107,7 +2107,7 @@ void drawUpperScreen(BYTE *pBuff)
xx_32 = 30;
while (dst >= gpBufEnd) {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -2116,7 +2116,7 @@ void drawUpperScreen(BYTE *pBuff)
if (dst < gpBufEnd)
break;
asm_cel_light_edge(32 - yy_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -2149,7 +2149,7 @@ void drawUpperScreen(BYTE *pBuff)
xx_32 = 30;
while (dst >= gpBufEnd) {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
if (xx_32 < 0) {
@@ -2465,7 +2465,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} while (i);
break;
case 1: // lower (top transparent), black
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
LABEL_412:
yy_32 = 32;
@@ -2489,7 +2489,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
yy_32 -= width;
if (dst < gpBufEnd) {
src += width;
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
chk_sh_and = width >> 1;
if (!(width & 1))
goto LABEL_420;
@@ -2895,7 +2895,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} while (i);
break;
case 1: // lower (top transparent), with lighting
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
do {
yy_32 = 32;
@@ -2912,7 +2912,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
}
yy_32 -= width;
if (dst < gpBufEnd) {
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
asm_trans_light_cel_0_2(width, tbl, &dst, &src);
} else {
asm_trans_light_cel_1_3(width, tbl, &dst, &src);
@@ -3011,7 +3011,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - yy_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -3031,7 +3031,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - xx_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -3128,7 +3128,7 @@ void drawTopArchesLowerScreen(BYTE *pBuff)
} else {
asm_trans_light_cel_1_3(32 - xx_32, tbl, &dst, &src);
}
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -3175,7 +3175,7 @@ LABEL_11:
} while (i);
break;
case 9: // lower (top transparent), without lighting
- WorldBoolFlag = (unsigned char)pBuff & 1;
+ WorldBoolFlag = (uintptr_t)pBuff & 1;
xx_32 = 32;
while (1) {
yy_32 = 32;
@@ -3186,7 +3186,7 @@ LABEL_11:
break;
yy_32 -= width;
if (dst < gpBufEnd) {
- if (((unsigned char)dst & 1) == WorldBoolFlag) {
+ if (((uintptr_t)dst & 1) == WorldBoolFlag) {
chk_sh_and = width >> 1;
if (!(width & 1))
goto LABEL_280;
@@ -4042,7 +4042,7 @@ void drawBottomArchesLowerScreen(BYTE *pBuff, unsigned int *pMask)
}
do {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -4096,7 +4096,7 @@ void drawBottomArchesLowerScreen(BYTE *pBuff, unsigned int *pMask)
do {
if (dst < gpBufEnd) {
asm_trans_light_mask(32, tbl, &dst, &src, *gpDrawMask);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
} else {
src += 32;
dst += 32;
@@ -4114,7 +4114,7 @@ void drawBottomArchesLowerScreen(BYTE *pBuff, unsigned int *pMask)
}
do {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -4396,7 +4396,7 @@ void drawBottomArchesLowerScreen(BYTE *pBuff, unsigned int *pMask)
++dst;
--i;
} while (i);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
} else {
src += 32;
dst += 32;
@@ -4821,7 +4821,7 @@ void drawLowerScreen(BYTE *pBuff)
}
do {
asm_cel_light_edge(32 - yy_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[yy_32 - 800];
yy_32 += 2;
} while (yy_32 != 32);
@@ -4834,7 +4834,7 @@ void drawLowerScreen(BYTE *pBuff)
}
do {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
@@ -4901,7 +4901,7 @@ void drawLowerScreen(BYTE *pBuff)
}
do {
asm_cel_light_edge(32 - xx_32, tbl, &dst, &src);
- src += (unsigned char)src & 2;
+ src += (uintptr_t)src & 2;
dst = &dst[xx_32 - 800];
xx_32 -= 2;
} while (xx_32 >= 0);
diff --git a/SourceS/miniwin.h b/SourceS/miniwin.h
index a179852b..1740fdd2 100644
--- a/SourceS/miniwin.h
+++ b/SourceS/miniwin.h
@@ -3,7 +3,7 @@
#include <ctype.h>
#include <math.h>
// work around https://reviews.llvm.org/D51265
-#if defined(__APPLE__) || defined(__FreeBSD__)
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include "macos_stdarg.h"
#else
#include <stdarg.h>
@@ -17,6 +17,10 @@
#if !defined(_MSC_VER) && defined(DEVILUTION_ENGINE)
#if defined(__x86_64__) || defined(__i386__)
#include <x86intrin.h>
+#if defined(__clang__)
+#define _rotl(x, v) __builtin_rotateleft32(x, v)
+#define _rotr(x, v) __builtin_rotateright32(x, v)
+#endif
#else
unsigned int _rotl(unsigned int value, int shift);
unsigned int _rotr(unsigned int value, int shift);
diff --git a/defs.h b/defs.h
index 962ed34b..649cae7b 100644
--- a/defs.h
+++ b/defs.h
@@ -151,7 +151,7 @@
// Typedef for the function pointer
typedef void (*_PVFV)(void);
-#if defined(_MSC_VER) && !(defined(__APPLE__)|| defined(__FreeBSD__))
+#if defined(_MSC_VER) && !(defined(__APPLE__)|| defined(__FreeBSD__) || defined(__OpenBSD__))
// Define our segment names
#define SEGMENT_C_INIT ".CRT$XCU"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment