Skip to content

Commit

Permalink
games-emulation/rmg: fix -Wstrict-aliasing warnings
Browse files Browse the repository at this point in the history
Upstream-Issue: gonetz/GLideN64#2877
Upstream-PR: gonetz/GLideN64#2884
Upstream-Commit: gonetz/GLideN64@a1320da
Upstream-Commit: Rosalie241/RMG@e68483f
Signed-off-by: orbea <orbea@riseup.net>
  • Loading branch information
orbea committed Nov 9, 2024
1 parent 62a640b commit ab49233
Show file tree
Hide file tree
Showing 3 changed files with 353 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
https://github.com/gonetz/GLideN64/issues/2877
https://github.com/gonetz/GLideN64/pull/2884
https://github.com/gonetz/GLideN64/commit/a1320da566c03503ea755447458bb2b79a610cb5
https://github.com/Rosalie241/RMG/commit/e68483fce2a977c07fee38e1d8d8f8dc22bb6072

From a1320da566c03503ea755447458bb2b79a610cb5 Mon Sep 17 00:00:00 2001
From: Sergey Lipskiy <gonetz@ngs.ru>
Date: Sat, 19 Oct 2024 16:18:29 +0700
Subject: [PATCH] Fix -Wstrict-aliasing warnings

---
Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp | 56 ++++++++++++++++++++++++------------------------
1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp b/Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp
index 4739ec31c..22edf608d 100644
--- a/Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp
+++ b/Source/3rdParty/mupen64plus-video-GLideN64/src/Textures.cpp
@@ -52,9 +52,9 @@ u32 GetCI4IA_RGBA4444(u16 offset, u16 x, u16 i, u8 palette)
const u8 color4B = Get4BitPaletteColor(offset, x, i);

if (x & 1)
- return IA88_RGBA4444(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF]);
+ return IA88_RGBA4444(static_cast<u16>(TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF] & 0xFFFF));
else
- return IA88_RGBA4444(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF]);
+ return IA88_RGBA4444(static_cast<u16>(TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF] & 0xFFFF));
}

u32 GetCI4IA_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
@@ -62,9 +62,9 @@ u32 GetCI4IA_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
const u8 color4B = Get4BitPaletteColor(offset, x, i);

if (x & 1)
- return IA88_RGBA8888(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF]);
+ return IA88_RGBA8888(static_cast<u16>(TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF] & 0xFFFF));
else
- return IA88_RGBA8888(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF]);
+ return IA88_RGBA8888(static_cast<u16>(TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF] & 0xFFFF));
}

u32 GetCI4RGBA_RGBA5551(u16 offset, u16 x, u16 i, u8 palette)
@@ -72,9 +72,9 @@ u32 GetCI4RGBA_RGBA5551(u16 offset, u16 x, u16 i, u8 palette)
const u8 color4B = Get4BitPaletteColor(offset, x, i);

if (x & 1)
- return RGBA5551_RGBA5551(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF]);
+ return RGBA5551_RGBA5551(static_cast<u16>(TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF] & 0xFFFF));
else
- return RGBA5551_RGBA5551(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF]);
+ return RGBA5551_RGBA5551(static_cast<u16>(TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF] & 0xFFFF));
}

u32 GetCI4RGBA_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
@@ -82,9 +82,9 @@ u32 GetCI4RGBA_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
const u8 color4B = Get4BitPaletteColor(offset, x, i);

if (x & 1)
- return RGBA5551_RGBA8888(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF]);
+ return RGBA5551_RGBA8888(static_cast<u16>(TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF] & 0xFFFF));
else
- return RGBA5551_RGBA8888(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF]);
+ return RGBA5551_RGBA8888(static_cast<u16>(TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF] & 0xFFFF));
}

u32 GetIA31_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
@@ -120,25 +120,25 @@ inline u8 Get8BitPaletteColor(u16 offset, u16 x, u16 i)
u32 GetCI8IA_RGBA4444(u16 offset, u16 x, u16 i, u8 palette)
{
const u8 color = Get8BitPaletteColor(offset, x, i);
- return IA88_RGBA4444(*(u16*)&TMEM[(0x100 + color) & 0x1FF]);
+ return IA88_RGBA4444(static_cast<u16>(TMEM[(0x100 + color) & 0x1FF] & 0xFFFF));
}

u32 GetCI8IA_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
{
const u8 color = Get8BitPaletteColor(offset, x, i);
- return IA88_RGBA8888(*(u16*)&TMEM[(0x100 + color) & 0x1FF]);
+ return IA88_RGBA8888(static_cast<u16>(TMEM[(0x100 + color) & 0x1FF] & 0xFFFF));
}

u32 GetCI8RGBA_RGBA5551(u16 offset, u16 x, u16 i, u8 palette)
{
const u8 color = Get8BitPaletteColor(offset, x, i);
- return RGBA5551_RGBA5551(*(u16*)&TMEM[(0x100 + color) & 0x1FF]);
+ return RGBA5551_RGBA5551(static_cast<u16>(TMEM[(0x100 + color) & 0x1FF] & 0xFFFF));
}

u32 GetCI8RGBA_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
{
const u8 color = Get8BitPaletteColor(offset, x, i);
- return RGBA5551_RGBA8888(*(u16*)&TMEM[(0x100 + color) & 0x1FF]);
+ return RGBA5551_RGBA8888(static_cast<u16>(TMEM[(0x100 + color) & 0x1FF] & 0xFFFF));
}

u32 GetIA44_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
@@ -193,7 +193,7 @@ u32 GetI16_RGBA4444(u16 offset, u16 x, u16 i, u8 palette)
u32 GetCI16IA_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
{
const u16 tex = Get16BitColor(offset, x, i);
- const u16 col = (*(u16*)&TMEM[0x100 + (tex & 0xFF)]);
+ const u16 col = (static_cast<u16>(TMEM[0x100 + (tex & 0xFF)] & 0xFFFF));
const u16 c = col >> 8;
const u16 a = col & 0xFF;
return (a << 24) | (c << 16) | (c << 8) | c;
@@ -202,7 +202,7 @@ u32 GetCI16IA_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
u32 GetCI16IA_RGBA4444(u16 offset, u16 x, u16 i, u8 palette)
{
const u16 tex = Get16BitColor(offset, x, i);
- const u16 col = (*(u16*)&TMEM[0x100 + (tex & 0xFF)]);
+ const u16 col = (static_cast<u16>(TMEM[0x100 + (tex & 0xFF)] & 0xFFFF));
const u16 c = col >> 12;
const u16 a = col & 0x0F;
return (a << 12) | (c << 8) | (c << 4) | c;
@@ -303,9 +303,9 @@ u32 GetCI4IA_RGBA4444_BG(u64 *src, u16 x, u16 i, u8 palette)
u8 color4B = ((u8*)src)[(x >> 1) ^ (i << 1)];

if (x & 1)
- return IA88_RGBA4444(*(u16*)&TMEM[256 + (palette << 4) + (color4B & 0x0F)]);
+ return IA88_RGBA4444(static_cast<u16>(TMEM[256 + (palette << 4) + (color4B & 0x0F)] & 0xFFFF));
else
- return IA88_RGBA4444(*(u16*)&TMEM[256 + (palette << 4) + (color4B >> 4)]);
+ return IA88_RGBA4444(static_cast<u16>(TMEM[256 + (palette << 4) + (color4B >> 4)] & 0xFFFF));
}

u32 GetCI4IA_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
@@ -313,9 +313,9 @@ u32 GetCI4IA_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
u8 color4B = ((u8*)src)[(x >> 1) ^ (i << 1)];

if (x & 1)
- return IA88_RGBA8888(*(u16*)&TMEM[256 + (palette << 4) + (color4B & 0x0F)]);
+ return IA88_RGBA8888(static_cast<u16>(TMEM[256 + (palette << 4) + (color4B & 0x0F)] & 0xFFFF));
else
- return IA88_RGBA8888(*(u16*)&TMEM[256 + (palette << 4) + (color4B >> 4)]);
+ return IA88_RGBA8888(static_cast<u16>(TMEM[256 + (palette << 4) + (color4B >> 4)] & 0xFFFF));
}

u32 GetCI4RGBA_RGBA5551_BG(u64 *src, u16 x, u16 i, u8 palette)
@@ -323,9 +323,9 @@ u32 GetCI4RGBA_RGBA5551_BG(u64 *src, u16 x, u16 i, u8 palette)
u8 color4B = ((u8*)src)[(x >> 1) ^ (i << 1)];

if (x & 1)
- return RGBA5551_RGBA5551(*(u16*)&TMEM[256 + (palette << 4) + (color4B & 0x0F)]);
+ return RGBA5551_RGBA5551(static_cast<u16>(TMEM[256 + (palette << 4) + (color4B & 0x0F)] & 0xFFFF));
else
- return RGBA5551_RGBA5551(*(u16*)&TMEM[256 + (palette << 4) + (color4B >> 4)]);
+ return RGBA5551_RGBA5551(static_cast<u16>(TMEM[256 + (palette << 4) + (color4B >> 4)] & 0xFFFF));
}

u32 GetCI4RGBA_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
@@ -333,9 +333,9 @@ u32 GetCI4RGBA_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
u8 color4B = ((u8*)src)[(x >> 1) ^ (i << 1)];

if (x & 1)
- return RGBA5551_RGBA8888(*(u16*)&TMEM[256 + (palette << 4) + (color4B & 0x0F)]);
+ return RGBA5551_RGBA8888(static_cast<u16>(TMEM[256 + (palette << 4) + (color4B & 0x0F)] & 0xFFFF));
else
- return RGBA5551_RGBA8888(*(u16*)&TMEM[256 + (palette << 4) + (color4B >> 4)]);
+ return RGBA5551_RGBA8888(static_cast<u16>(TMEM[256 + (palette << 4) + (color4B >> 4)] & 0xFFFF));
}

u32 GetIA31_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
@@ -368,22 +368,22 @@ u32 GetI4_RGBA4444_BG(u64 *src, u16 x, u16 i, u8 palette)

u32 GetCI8IA_RGBA4444_BG(u64 *src, u16 x, u16 i, u8 palette)
{
- return IA88_RGBA4444(*(u16*)&TMEM[256 + ((u8*)src)[x ^ (i << 1)]]);
+ return IA88_RGBA4444(static_cast<u16>(TMEM[256 + ((u8*)src)[x ^ (i << 1)]] & 0xFFFF));
}

u32 GetCI8IA_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
{
- return IA88_RGBA8888(*(u16*)&TMEM[256 + ((u8*)src)[x ^ (i << 1)]]);
+ return IA88_RGBA8888(static_cast<u16>(TMEM[256 + ((u8*)src)[x ^ (i << 1)]] & 0xFFFF));
}

u32 GetCI8RGBA_RGBA5551_BG(u64 *src, u16 x, u16 i, u8 palette)
{
- return RGBA5551_RGBA5551(*(u16*)&TMEM[256 + ((u8*)src)[x ^ (i << 1)]]);
+ return RGBA5551_RGBA5551(static_cast<u16>(TMEM[256 + ((u8*)src)[x ^ (i << 1)]] & 0xFFFF));
}

u32 GetCI8RGBA_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
{
- return RGBA5551_RGBA8888(*(u16*)&TMEM[256 + ((u8*)src)[x ^ (i << 1)]]);
+ return RGBA5551_RGBA8888(static_cast<u16>(TMEM[256 + ((u8*)src)[x ^ (i << 1)]] & 0xFFFF));
}

u32 GetIA44_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
@@ -429,7 +429,7 @@ u32 GetI16_RGBA4444_BG(u64 *src, u16 x, u16 i, u8 palette)
u32 GetCI16IA_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
{
const u16 tex = ((u16*)src)[x^i];
- const u16 col = (*(u16*)&TMEM[256 + (tex & 0xFF)]);
+ const u16 col = (static_cast<u16>(TMEM[256 + (tex & 0xFF)] & 0xFFFF));
const u16 c = col >> 8;
const u16 a = col & 0xFF;
return (a << 24) | (c << 16) | (c << 8) | c;
@@ -438,7 +438,7 @@ u32 GetCI16IA_RGBA8888_BG(u64 *src, u16 x, u16 i, u8 palette)
u32 GetCI16IA_RGBA4444_BG(u64 *src, u16 x, u16 i, u8 palette)
{
const u16 tex = ((u16*)src)[x^i];
- const u16 col = (*(u16*)&TMEM[256 + (tex & 0xFF)]);
+ const u16 col = (static_cast<u16>(TMEM[256 + (tex & 0xFF)] & 0xFFFF));
const u16 c = col >> 12;
const u16 a = col & 0x0F;
return (a << 12) | (c << 8) | (c << 4) | c;
145 changes: 145 additions & 0 deletions games-emulation/rmg/rmg-0.6.6-r2.ebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Copyright 2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

CARGO_OPTIONAL=1

CRATES="
cc@1.0.83
cfg-if@1.0.0
libc@0.2.152
libloading@0.7.4
libusb1-sys@0.6.4
once_cell@1.19.0
pkg-config@0.3.29
proc-macro2@1.0.78
quote@1.0.35
rusb@0.9.3
serde@1.0.195
serde_derive@1.0.195
syn@2.0.48
toml@0.5.11
unicode-ident@1.0.12
vcpkg@0.2.15
winapi-i686-pc-windows-gnu@0.4.0
winapi-x86_64-pc-windows-gnu@0.4.0
winapi@0.3.9
"

inherit cargo cmake toolchain-funcs xdg

MY_PN="${PN^^}"
MY_P="${MY_PN}-${PV}"
DESCRIPTION="Rosalie's Mupen GUI"
HOMEPAGE="https://github.com/Rosalie241/RMG"
if [[ "${PV}" == *9999 ]] ; then
inherit git-r3
EGIT_REPO_URI="https://github.com/Rosalie241/${MY_PN}.git"
else
SRC_URI="
https://github.com//Rosalie241/${MY_PN}/archive/v${PV}/${MY_P}.tar.gz \
-> ${P}.tar.gz
rust-plugin? ( ${CARGO_CRATE_URIS} )
"
S="${WORKDIR}/${MY_P}"
KEYWORDS="~amd64"
fi

LICENSE="
BSD-2 CC0-1.0 GPL-2 GPL-3 MIT ZLIB public-domain
angrylion-plugin? ( XMAME )
rust-plugin? ( ISC Unicode-DFS-2016 )
"
SLOT="0"
IUSE="angrylion-plugin discord dynarec rust-plugin"

DEPEND="
dev-libs/hidapi
dev-qt/qtbase:6[gui,opengl,vulkan,widgets]
dev-qt/qtsvg:6
media-libs/freetype
media-libs/libpng:=
media-libs/libsamplerate
media-libs/libsdl2[haptic,joystick,opengl,sound,vulkan]
media-libs/speexdsp
sys-libs/zlib[minizip(+)]
virtual/opengl
rust-plugin? ( dev-libs/libusb:1 )
"
RDEPEND="${DEPEND}"
BDEPEND="
virtual/pkgconfig
dynarec? ( dev-lang/nasm )
rust-plugin? ( ${RUST_DEPEND} )
"

PATCHES=(
"${FILESDIR}"/${PN}-0.5.6-parallel-rdp-standalone-musl.patch
# Use pkg-config(1) for SDL2 and don't depend on which(1)
"${FILESDIR}"/${P}-mupen64plus-core-sdl-pkgconfig.patch
# https://bugs.gentoo.org/941889
"${FILESDIR}"/${P}-mupen64plus-input-raphnetraw-pkgconfig.patch
# https://github.com/gonetz/GLideN64/issues/2877
"${FILESDIR}"/${P}-mupen64plus-video-GLideN64-strict-aliasing.patch
)

pkg_setup() {
QA_FLAGS_IGNORED="/usr/$(get_libdir)/RMG/Plugin/Input/libmupen64plus_input_gca.so"
use rust-plugin && rust_pkg_setup
}

src_unpack() {
if [[ "${PV}" == *9999 ]] ; then
git-r3_src_unpack
if use rust-plugin; then
S="${S}"/Source/3rdParty/mupen64plus-input-gca \
cargo_live_src_unpack
fi
else
if use rust-plugin; then
cargo_src_unpack
else
default
fi
fi
}

src_prepare() {
cmake_src_prepare

# Don't install unused 3rdParty code
rm -r "${S}"/Source/3rdParty/fmt || die

# Don't install XMAME licensed code
if ! use angrylion-plugin; then
rm -r "${S}"/Source/3rdParty/mupen64plus-video-angrylion-plus || die
fi

# Don't install pre-compiled binaries
rm -r "${S}"/Source/3rdParty/vosk-api || die

# Enable verbose make(1) output
sed -e 's/CC=/V=1 CC=/' -i "${S}"/Source/3rdParty/CMakeLists.txt || die
}

src_configure() {
export PKG_CONFIG="$(tc-getPKG_CONFIG)"
export PKG_CONFIG_ALLOW_CROSS=1

local mycmakeargs=(
-DAPPIMAGE_UPDATER=OFF
-DDISCORD_RPC=$(usex discord)
-DNO_ASM=$(usex dynarec OFF ON)
-DNO_RUST=$(usex rust-plugin OFF ON)
-DPORTABLE_INSTALL=OFF
-DUPDATER=OFF
-DUSE_ANGRYLION=$(usex angrylion-plugin)
-DUSE_CCACHE=OFF
-DUSE_LIBFMT=OFF # Use std::format
-DUSE_LTO=OFF
-DVRU=OFF # Precompiled binaries
)

cmake_src_configure
}
9 changes: 1 addition & 8 deletions games-emulation/rmg/rmg-9999.ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CRATES="
winapi@0.3.9
"

inherit cargo cmake flag-o-matic toolchain-funcs xdg
inherit cargo cmake toolchain-funcs xdg

MY_PN="${PN^^}"
MY_P="${MY_PN}-${PV}"
Expand Down Expand Up @@ -118,13 +118,6 @@ src_prepare() {
}

src_configure() {
# -Werror=strict-aliasing
# https://github.com/gonetz/GLideN64/issues/2877
#
# Disable strict-aliasing until its handled upstream.
append-flags -fno-strict-aliasing
filter-lto

export PKG_CONFIG="$(tc-getPKG_CONFIG)"
export PKG_CONFIG_ALLOW_CROSS=1

Expand Down

0 comments on commit ab49233

Please sign in to comment.