Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQpDP-0005ua-5H for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Oct 2020 10:01:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kQpDM-0004qs-2v for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Oct 2020 10:01:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kQpDL-0004nN-KU for pgsql-hackers@lists.postgresql.org; Fri, 09 Oct 2020 10:01:27 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kQpDF-0006JD-Ls for pgsql-hackers@lists.postgresql.org; Fri, 09 Oct 2020 10:01:26 +0000 Received: by mail-pl1-x643.google.com with SMTP id d23so4221753pll.7 for ; Fri, 09 Oct 2020 03:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=+OHMt1asvS9f1EXl5p/mxprZ1RgRY6Kh0Vrs6lTM3VU=; b=AJWP34qY/cJMnKDs6saoOigLxtjpNXitfuzA0/50/6ck1b7Cf+wEZIvI6PQ7zSIVvS 9JHLq135+K/4ubu4DEyyIT/GnZU7t/u8XWFmPFxKiT33OqmwHcC561am9VFCcI1QILBi m6fCaW/ca+yRdsiNLFYmVszcf2jyhJSlwa8qc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=+OHMt1asvS9f1EXl5p/mxprZ1RgRY6Kh0Vrs6lTM3VU=; b=DdVjT1q6Oc5R6dN+Lbzh0cS7DfmQpBXci+VPMoAo4ohXTxar09LmeQZjCBk1b+NHXd AJnbzXKI+JZcNcdUOXqjWgqDu+7noJQuCdUZRZhRxySLrbJUuH+8YVL+RFn6MJOeunej 1caG+y9hIDiJINuAgW5BcRzBIsTvUlHZlxCTyC4idBdrl4IDjbNniaahSdi3SXbKAHA7 IvUxXA1Ood2LJw1Enb5QMo+P3Iy6nzITLsRRwBtcN5MfAsnKAbobcd/acFPjyopRdIpi Do1lfQe7e/jk65ZSIy5geE/jCXvjCdDw6GSu9o9zDslGYZeFiytJ7IYMfLfMON7LoDN7 WziQ== X-Gm-Message-State: AOAM5314d5PQCFmk3XR9SYsymUfM+K0WeMU/yeqFLwUoc9J1tj7ase32 PDUh3TmOI+K1/rOEv1UG94n1WQ== X-Google-Smtp-Source: ABdhPJx1i8sSOKW4FtUKUJ6fx6iLRP9NyfzusC7ibuiWe4ANKrpDKcwt+tl9nj9NVeQPDtE85e+h7A== X-Received: by 2002:a17:902:9a98:b029:d2:6232:e26c with SMTP id w24-20020a1709029a98b02900d26232e26cmr11747982plp.1.1602237680159; Fri, 09 Oct 2020 03:01:20 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::43]) by smtp.gmail.com with ESMTPSA id f204sm9893041pfa.189.2020.10.09.03.01.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Oct 2020 03:01:19 -0700 (PDT) Date: Fri, 9 Oct 2020 03:01:17 -0700 From: Noah Misch To: Christoph Berg Cc: pgsql-hackers@lists.postgresql.org Subject: Re: powerpc pg_atomic_compare_exchange_u32_impl: error: comparison of integer expressions of different signedness (Re: pgsql: For all ppc compilers, implement compare_exchange and) fetch_add Message-ID: <20201009100117.GA1550390@rfd.leadboat.com> References: <20201009092825.GD889580@msg.df7cb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20201009092825.GD889580@msg.df7cb.de> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Oct 09, 2020 at 11:28:25AM +0200, Christoph Berg wrote: > pg-cron on powerpc/ppc64/ppc64el is raising this warning inside the > ppc atomics: > > gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -g -O2 -fdebug-prefix-map=/<>=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -std=c99 -Wall -Wextra -Werror -Wno-unknown-warning-option -Wno-unused-parameter -Wno-maybe-uninitialized -Wno-implicit-fallthrough -Iinclude -I/usr/include/postgresql -I. -I./ -I/usr/include/postgresql/13/server -I/usr/include/postgresql/internal -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -c -o src/job_metadata.o src/job_metadata.c > In file included from /usr/include/postgresql/13/server/port/atomics.h:74, > from /usr/include/postgresql/13/server/utils/dsa.h:17, > from /usr/include/postgresql/13/server/nodes/tidbitmap.h:26, > from /usr/include/postgresql/13/server/access/genam.h:19, > from src/job_metadata.c:21: > /usr/include/postgresql/13/server/port/atomics/arch-ppc.h: In function ‘pg_atomic_compare_exchange_u32_impl’: > /usr/include/postgresql/13/server/port/atomics/arch-ppc.h:97:42: error: comparison of integer expressions of different signedness: ‘uint32’ {aka ‘unsigned int’} and ‘int’ [-Werror=sign-compare] > 97 | *expected <= PG_INT16_MAX && *expected >= PG_INT16_MIN) > | ^~ > src/job_metadata.c: At top level: > cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics > cc1: all warnings being treated as errors > > Looking at the pg_atomic_compare_exchange_u32_impl, this looks like a > genuine problem: > > static inline bool > pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, > uint32 *expected, uint32 newval) > ... > if (__builtin_constant_p(*expected) && > *expected <= PG_INT16_MAX && *expected >= PG_INT16_MIN) > > If *expected is an unsigned integer, comparing it to PG_INT16_MIN > which is a negative number doesn't make sense. > > src/include/c.h:#define PG_INT16_MIN (-0x7FFF-1) Agreed. I'll probably fix it like this: --- a/src/include/port/atomics/arch-ppc.h +++ b/src/include/port/atomics/arch-ppc.h @@ -96,3 +96,4 @@ pg_atomic_compare_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, if (__builtin_constant_p(*expected) && - *expected <= PG_INT16_MAX && *expected >= PG_INT16_MIN) + (int32) *expected <= PG_INT16_MAX && + (int32) *expected >= PG_INT16_MIN) __asm__ __volatile__( @@ -185,3 +186,4 @@ pg_atomic_compare_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, if (__builtin_constant_p(*expected) && - *expected <= PG_INT16_MAX && *expected >= PG_INT16_MIN) + (int64) *expected <= PG_INT16_MAX && + (int64) *expected >= PG_INT16_MIN) __asm__ __volatile__(