Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lot of -Wstrict-aliasing warnings #2877

Closed
orbea opened this issue Oct 7, 2024 · 3 comments · Fixed by #2884
Closed

Lot of -Wstrict-aliasing warnings #2877

orbea opened this issue Oct 7, 2024 · 3 comments · Fixed by #2884

Comments

@orbea
Copy link
Contributor

orbea commented Oct 7, 2024

OS: Gentoo
GLideN64: f4b0755
compiler: gcc version 13.3.1 20240614 (Gentoo 13.3.1_p20240614 p17)

When compiling GLideN64 there are a lot of -Wstrict-aliasing warnings, this can lead to unexpected behavior when building software and it would be great if it could be fixed.

It came up when updating RMG for the Gentoo repo. gentoo/gentoo#38837 (comment)

/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI4IA_RGBA4444(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:55:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   55 |                 return IA88_RGBA4444(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF]);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp:57:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   57 |                 return IA88_RGBA4444(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF]);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI4IA_RGBA8888(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:65:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   65 |                 return IA88_RGBA8888(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF]);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp:67:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   67 |                 return IA88_RGBA8888(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF]);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI4RGBA_RGBA5551(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:75:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   75 |                 return RGBA5551_RGBA5551(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF]);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp:77:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   77 |                 return RGBA5551_RGBA5551(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF]);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI4RGBA_RGBA8888(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:85:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   85 |                 return RGBA5551_RGBA8888(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B & 0x0F)) & 0x1FF]);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp:87:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   87 |                 return RGBA5551_RGBA8888(*(u16*)&TMEM[(0x100 + (palette << 4) + (color4B >> 4)) & 0x1FF]);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI8IA_RGBA4444(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:123:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  123 |         return IA88_RGBA4444(*(u16*)&TMEM[(0x100 + color) & 0x1FF]);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI8IA_RGBA8888(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:129:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  129 |         return IA88_RGBA8888(*(u16*)&TMEM[(0x100 + color) & 0x1FF]);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI8RGBA_RGBA5551(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:135:35: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  135 |         return RGBA5551_RGBA5551(*(u16*)&TMEM[(0x100 + color) & 0x1FF]);
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI8RGBA_RGBA8888(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:141:35: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  141 |         return RGBA5551_RGBA8888(*(u16*)&TMEM[(0x100 + color) & 0x1FF]);
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI16IA_RGBA8888(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:196:27: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  196 |         const u16 col = (*(u16*)&TMEM[0x100 + (tex & 0xFF)]);
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI16IA_RGBA4444(u16, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:205:27: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  205 |         const u16 col = (*(u16*)&TMEM[0x100 + (tex & 0xFF)]);
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI4IA_RGBA4444_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:306:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  306 |                 return IA88_RGBA4444(*(u16*)&TMEM[256 + (palette << 4) + (color4B & 0x0F)]);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp:308:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  308 |                 return IA88_RGBA4444(*(u16*)&TMEM[256 + (palette << 4) + (color4B >> 4)]);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI4IA_RGBA8888_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:316:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  316 |                 return IA88_RGBA8888(*(u16*)&TMEM[256 + (palette << 4) + (color4B & 0x0F)]);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp:318:39: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  318 |                 return IA88_RGBA8888(*(u16*)&TMEM[256 + (palette << 4) + (color4B >> 4)]);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI4RGBA_RGBA5551_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:326:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  326 |                 return RGBA5551_RGBA5551(*(u16*)&TMEM[256 + (palette << 4) + (color4B & 0x0F)]);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp:328:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  328 |                 return RGBA5551_RGBA5551(*(u16*)&TMEM[256 + (palette << 4) + (color4B >> 4)]);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI4RGBA_RGBA8888_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:336:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  336 |                 return RGBA5551_RGBA8888(*(u16*)&TMEM[256 + (palette << 4) + (color4B & 0x0F)]);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp:338:43: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  338 |                 return RGBA5551_RGBA8888(*(u16*)&TMEM[256 + (palette << 4) + (color4B >> 4)]);
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI8IA_RGBA4444_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:371:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  371 |         return IA88_RGBA4444(*(u16*)&TMEM[256 + ((u8*)src)[x ^ (i << 1)]]);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI8IA_RGBA8888_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:376:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  376 |         return IA88_RGBA8888(*(u16*)&TMEM[256 + ((u8*)src)[x ^ (i << 1)]]);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI8RGBA_RGBA5551_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:381:35: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  381 |         return RGBA5551_RGBA5551(*(u16*)&TMEM[256 + ((u8*)src)[x ^ (i << 1)]]);
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI8RGBA_RGBA8888_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:386:35: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  386 |         return RGBA5551_RGBA8888(*(u16*)&TMEM[256 + ((u8*)src)[x ^ (i << 1)]]);
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI16IA_RGBA8888_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:432:27: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  432 |         const u16 col = (*(u16*)&TMEM[256 + (tex & 0xFF)]);
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/GLideN64/src/Textures.cpp: In function ‘u32 GetCI16IA_RGBA4444_BG(u64*, u16, u16, u8)’:
/tmp/GLideN64/src/Textures.cpp:441:27: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  441 |         const u16 col = (*(u16*)&TMEM[256 + (tex & 0xFF)]);
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[134/134] Linking CXX shared library plugin/Release/mupen64plus-video-GLideN64.so
@gonetz
Copy link
Owner

gonetz commented Oct 19, 2024

@orbea please check, if #2884 fixes the problem.

@orbea
Copy link
Contributor Author

orbea commented Oct 19, 2024

@gonetz I tested the PR and there are no more warnings, it also seems to work fine at runtime. Thanks!

@gonetz
Copy link
Owner

gonetz commented Oct 20, 2024

Ok, merged.

orbea added a commit to orbea/gentoo that referenced this issue Oct 21, 2024
orbea added a commit to orbea/gentoo that referenced this issue Nov 3, 2024
orbea added a commit to orbea/gentoo that referenced this issue Nov 9, 2024
orbea added a commit to orbea/gentoo that referenced this issue Nov 9, 2024
orbea added a commit to orbea/gentoo that referenced this issue Nov 9, 2024
orbea added a commit to orbea/gentoo that referenced this issue Nov 9, 2024
orbea added a commit to orbea/gentoo that referenced this issue Nov 15, 2024
gentoo-bot pushed a commit to gentoo/gentoo that referenced this issue Nov 26, 2024
Upstream-Issue: gonetz/GLideN64#2877
Upstream-PR: gonetz/GLideN64#2884
Upstream-Commit: gonetz/GLideN64@a1320da
Upstream-Commit: Rosalie241/RMG@e68483f
Signed-off-by: orbea <[email protected]>
Closes: #39058
Signed-off-by: Eli Schwartz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants