[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rockbox-cvs
Subject:    Suppress bogus GCC 12 -Waddress warnings for SKINOFFSETTOPTR
From:       rockbox-gerrit-noreply--- via rockbox-cvs <rockbox-cvs () lists ! haxx ! se>
Date:       2022-09-18 13:05:53
Message-ID: 202209181305.28ID5r143861529 () archos ! rockbox ! org
[Download RAW message or body]

commit 972c8c0ab6ef228401d30008cb3327d7764d3e62
Author: Aidan MacDonald <amachronic@protonmail.com>
Date:   Sun Sep 18 13:53:27 2022 +0100

    Suppress bogus GCC 12 -Waddress warnings for SKINOFFSETTOPTR
    
    This appears to be a bug in GCC 12 due to more aggressive -Waddress
    warnings. According to the GCC documentation, the warning should be
    suppressed because the "problem" code is coming from a macro, but it
    doesn't happen for cases like "if(!SKINOFFSETTOPTR(...))" where the
    macro is negated.
    
    Assigning the result of SKINOFFSETTOPTR() to a temporary and checking
    that suppresses the warning.
    
    Change-Id: Ia37a1e06a454d29032bb8128a2f059b149ea2b83

diff --git a/lib/skin_parser/skin_parser.h b/lib/skin_parser/skin_parser.h
index fc15aff1be..4f613d219d 100644
--- a/lib/skin_parser/skin_parser.h
+++ b/lib/skin_parser/skin_parser.h
@@ -33,8 +33,19 @@ extern "C"
 /* Use this type and macro to convert a pointer from the
  * skin buffer to a useable pointer */
 typedef long skinoffset_t;
-#define SKINOFFSETTOPTR(base, offset) ((offset) < 0 ? NULL : ((void*)&base[offset]))
-#define PTRTOSKINOFFSET(base, pointer) ((pointer) ? ((void*)pointer-(void*)base) : -1)
+/*
+ * The statement-expression here is needed to work around a
+ * bogus -Waddress warning produced by GCC 12 when this macro
+ * is used like "if (!SKINOFFSETTOPTR(...))".
+ *
+ * Related:
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102967
+ * https://godbolt.org/z/YEY4Yzdnf
+ */
+#define SKINOFFSETTOPTR(base, offset) \
+    ({ void *__p = ((offset) < 0 ? NULL : ((void*)&base[offset])); __p; })
+#define PTRTOSKINOFFSET(base, pointer) \
+    ((pointer) ? ((void*)pointer-(void*)base) : -1)
 /* Use this macro when declaring a variable to self-document the code.
  * type is the actual type being pointed to (i.e OFFSETTYPE(char*) foo )
  * 
-- 
rockbox-cvs mailing list
rockbox-cvs@lists.haxx.se
https://lists.haxx.se/listinfo/rockbox-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic