From 97e30c29daf7164c6cfed4843f4635f0e80e4527 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Fri, 2 Apr 2021 19:17:46 +1100 Subject: [PATCH] Add some more #pragma's for GCC to ignore warnings --- cmd/wuffs-c/release.go | 15 +++++++++------ internal/cgen/base/fundamental-public.h | 8 +------- internal/cgen/data/data.go | 2 +- release/c/wuffs-unsupported-snapshot.c | 23 ++++++++++------------- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/cmd/wuffs-c/release.go b/cmd/wuffs-c/release.go index 5c47b534..b68bc5db 100644 --- a/cmd/wuffs-c/release.go +++ b/cmd/wuffs-c/release.go @@ -167,17 +167,20 @@ const grSingleFileGuidance = ` const grPragmaPush = ` // Wuffs' C code is generated automatically, not hand-written. These warnings' // costs outweigh the benefits. -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#pragma clang diagnostic ignored "-Wunused-function" +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wunreachable-code" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-parameter" #endif ` const grPragmaPop = ` -#ifdef __clang__ -#pragma clang diagnostic pop +#if defined(__GNUC__) +#pragma GCC diagnostic pop #endif ` diff --git a/internal/cgen/base/fundamental-public.h b/internal/cgen/base/fundamental-public.h index 4031acdf..fb38c14f 100644 --- a/internal/cgen/base/fundamental-public.h +++ b/internal/cgen/base/fundamental-public.h @@ -182,18 +182,12 @@ wuffs_base__cpu_arch__have_x86_sse42() { // Wuffs assumes that: // - converting a uint32_t to a size_t will never overflow. // - converting a size_t to a uint64_t will never overflow. -#ifdef __WORDSIZE +#if defined(__WORDSIZE) #if (__WORDSIZE != 32) && (__WORDSIZE != 64) #error "Wuffs requires a word size of either 32 or 64 bits" #endif #endif -#if defined(__clang__) -#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD __attribute__((unused)) -#else -#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD -#endif - // Clang also defines "__GNUC__". #if defined(__GNUC__) #define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused)) diff --git a/internal/cgen/data/data.go b/internal/cgen/data/data.go index 7b7dbec3..013b3b7a 100644 --- a/internal/cgen/data/data.go +++ b/internal/cgen/data/data.go @@ -63,7 +63,7 @@ const BaseFundamentalPublicH = "" + "// ---------------- CPU Architecture\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_arm_crc32() {\n#if defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)\n return true;\n#else\n return false;\n#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)\n}\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_arm_neon() {\n#if defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)\n return true;\n#else\n return false;\n#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)\n}\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_x86_sse42() {\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n // GCC defines these macros but MSVC does not.\n // - bit_PCLMUL = (1 << 1)\n // - bit_POPCNT = (1 << 23)\n // - bit_SSE4_2 = (1 << 20)\n const unsigned int sse42_ecx1 = 0x00900002;\n\n // clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).\n#if defined(__GNUC__)\n unsigned int eax1 = 0;\n unsigned int ebx1 = 0;\n unsigned int ecx1 = 0;\n unsigned int edx1 = 0;\n if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1)) {\n return (ecx1 & sse42_ecx1) == sse42_" + "ecx1;\n }\n#elif defined(_MSC_VER) // defined(__GNUC__)\n int x[4];\n __cpuid(x, 1);\n return (((unsigned int)(x[2])) & sse42_ecx1) == sse42_ecx1;\n#else\n#error \"WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler\"\n#endif // defined(__GNUC__); defined(_MSC_VER)\n#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)\n return false;\n}\n\n" + "" + - "// ---------------- Fundamentals\n\n// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#ifdef __WORDSIZE\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n#endif\n\n#if defined(__clang__)\n#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD __attribute__((unused))\n#else\n#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD\n#endif\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))\n#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n#else\n#define WUFFS_BASE__POTENTIALLY_UNUSED\n#define WUFFS_BASE__WARN_UNUSED_RESULT\n#endif\n\n" + + "// ---------------- Fundamentals\n\n// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#if defined(__WORDSIZE)\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n#endif\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))\n#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n#else\n#define WUFFS_BASE__POTENTIALLY_UNUSED\n#define WUFFS_BASE__WARN_UNUSED_RESULT\n#endif\n\n" + "" + "// --------\n\n// Options (bitwise or'ed together) for wuffs_foo__bar__initialize functions.\n\n#define WUFFS_INITIALIZE__DEFAULT_OPTIONS ((uint32_t)0x00000000)\n\n// WUFFS_INITIALIZE__ALREADY_ZEROED means that the \"self\" receiver struct value\n// has already been set to all zeroes.\n#define WUFFS_INITIALIZE__ALREADY_ZEROED ((uint32_t)0x00000001)\n\n// WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED means that, absent\n// WUFFS_INITIALIZE__ALREADY_ZEROED, only some of the \"self\" receiver struct\n// value will be set to all zeroes. Internal buffers, which tend to be a large\n// proportion of the struct's size, will be left uninitialized. Internal means\n// that the buffer is contained by the receiver struct, as opposed to being\n// passed as a separately allocated \"work buffer\".\n//\n// For more detail, see:\n// https://github.com/google/wuffs/blob/main/doc/note/initialization.md\n#define WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED \\\n ((uint32_t)0x00000002)\n\n" + "" + diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 263fa8ab..bff05196 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -10,10 +10,13 @@ // Wuffs' C code is generated automatically, not hand-written. These warnings' // costs outweigh the benefits. -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" -#pragma clang diagnostic ignored "-Wunused-function" +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wunreachable-code" +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-parameter" #endif // Copyright 2017 The Wuffs Authors. @@ -216,18 +219,12 @@ wuffs_base__cpu_arch__have_x86_sse42() { // Wuffs assumes that: // - converting a uint32_t to a size_t will never overflow. // - converting a size_t to a uint64_t will never overflow. -#ifdef __WORDSIZE +#if defined(__WORDSIZE) #if (__WORDSIZE != 32) && (__WORDSIZE != 64) #error "Wuffs requires a word size of either 32 or 64 bits" #endif #endif -#if defined(__clang__) -#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD __attribute__((unused)) -#else -#define WUFFS_BASE__POTENTIALLY_UNUSED_FIELD -#endif - // Clang also defines "__GNUC__". #if defined(__GNUC__) #define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused)) @@ -39812,8 +39809,8 @@ done: #endif // WUFFS_IMPLEMENTATION -#ifdef __clang__ -#pragma clang diagnostic pop +#if defined(__GNUC__) +#pragma GCC diagnostic pop #endif #endif // WUFFS_INCLUDE_GUARD