Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sf1FE-000DhI-PS for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Aug 2024 18:00:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sf1FD-006y3W-F0 for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Aug 2024 18:00:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sf1FD-006y3O-1s for pgsql-hackers@lists.postgresql.org; Fri, 16 Aug 2024 18:00:11 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sf1F6-0055Ov-P2 for pgsql-hackers@lists.postgresql.org; Fri, 16 Aug 2024 18:00:09 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-52efa16aad9so2830630e87.0 for ; Fri, 16 Aug 2024 11:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723831203; x=1724436003; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2BwO5OWcc3402A+Vij/3LMrS0FMOlNxMlTo5FbhyFWE=; b=HibfM+vRrpF2kYMUkVHe4Oy0fFmZ/JFxW5v/KLVnmw0eIcMJC4g957eX5VuT0RJqKD CstbZtIrcbK9FZujJOsRh/48A+Q8cG/wHw6yKDA+BMA+JjJ9G/PeUG2NTJ39ixnxrAn1 bCKf2Xtky95Ioys1yW3wKf7iEKvlGwErehyo3497V0C7GoE/e7CLywMg/LvZUYzcDoy4 yLCYYLoKS9ku3JrbVNmdYHDk1mUhMsSZnMwPYsGQnzL6HJ1CdT3fiS+VKYqUM/dsGV3K yZQzeuSuzTUSEvjKsfKBet8RH/ulI52QWmsZfc2s/ulBNgvbvK2iZT8sdZFg2DWIC38l Y8RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723831203; x=1724436003; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2BwO5OWcc3402A+Vij/3LMrS0FMOlNxMlTo5FbhyFWE=; b=wTHjppTSJU0JsPNrGRiq3FB0CkFmmh5HW6s0/iqt/f/ZUKe9bhpnQVXfb+DOtNQEim rgB1g3LZhN0ktE31ITBlYr5YpR8FrPMfFEHspq7vEYjr9G6Q7NAioGE4/DHZVFkxKROB 6H66AtDD7R66+v4biUTIdVXAdLWnZTOIlnTV7fDY1Enf45HGAHOxkdtCqPgUmgWqXF1w fJIPL1nBgeaLJC9vkk0B53kc0zmWEuCW042wPnfc0CAZSYXTh5xmY9/7e/Yt5UbDVxQO 0Ct4AzPLB+dF8zpoWN55K4lw78tk8xmMdHD6OghZ9VfKaf321DIjrW3tv5uFviguIoCy Xm6Q== X-Forwarded-Encrypted: i=1; AJvYcCXe6maaM+usE/QfVJPAnnsk5AhOJpZF+8X9sASbRqyaEIzD08VdFiqVHh+b2y48RT1h6OhMjSayD7xnFUo2sWRCluFgGN//7d4u5tHj84Mn7VoT X-Gm-Message-State: AOJu0YxEhnek7sUr+3AGxNjq+QPuKXsyA1AAdwikLih2VfRtnWM2/5Hw kbgTNbGy5vzjwF0OzjlSNGPD6QtzCqmWzl991y+RpXWgHy/OdN0W X-Google-Smtp-Source: AGHT+IHaOp802OqlljKRXBi5Q74aLX+bM9xPw1kf+Nh05/dd/dw6GrJwvqfiI29YXvyRfkpHttMbLQ== X-Received: by 2002:a05:6512:1082:b0:52e:f2a9:b21a with SMTP id 2adb3069b0e04-5331c69ff40mr2913275e87.19.1723831202303; Fri, 16 Aug 2024 11:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.19.198]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5330d424b11sm630756e87.261.2024.08.16.11.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Aug 2024 11:00:01 -0700 (PDT) Message-ID: Date: Fri, 16 Aug 2024 21:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Remove dependence on integer wrapping Content-Language: en-US To: Nathan Bossart , Joseph Koshakow Cc: jian he , Heikki Linnakangas , Matthew Kim , Tom Lane , PostgreSQL Hackers , Andres Freund References: <875ad3ec-f216-487e-baad-cdbaf32c1fcf@iki.fi> From: Alexander Lakhin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Nathan and Joe, 16.08.2024 19:52, Nathan Bossart wrote: > On Thu, Aug 15, 2024 at 10:49:46PM -0400, Joseph Koshakow wrote: >> This updated version LGTM, I agree it's a good use of pg_abs_s32(). > Committed. Thank you for working on that issue! I've tried `make check` with CC=gcc-13 CPPFLAGS="-O0 -ftrapv" and got a server crash: 2024-08-16 17:14:36.102 UTC postmaster[1982703] LOG:   (PID 1983867) was terminated by signal 6: Aborted 2024-08-16 17:14:36.102 UTC postmaster[1982703] DETAIL:  Failed process was running: select '[]'::jsonb ->> -2147483648; with the stack trace ... #5  0x0000556aec224a11 in __negvsi2 () #6  0x0000556aec046238 in jsonb_array_element_text (fcinfo=0x556aedd70240) at jsonfuncs.c:993 #7  0x0000556aebc90b68 in ExecInterpExpr (state=0x556aedd70160, econtext=0x556aedd706a0, isnull=0x7ffdf82211e4)     at execExprInterp.c:765 ... (gdb) f 6 #6  0x0000556aec046238 in jsonb_array_element_text (fcinfo=0x556aedd70240) at jsonfuncs.c:993 993                     if (-element > nelements) (gdb) p element $1 = -2147483648 Sp it looks like jsonb_array_element_text() still needs the same treatment as jsonb_array_element(). Moreover, I tried to use "-ftrapv" on 32-bit Debian and came across another failure: select '9223372036854775807'::int8 * 2147483648::int8; server closed the connection unexpectedly ... #4  0xb722226a in __GI_abort () at ./stdlib/abort.c:79 #5  0x004cb2e1 in __mulvdi3.cold () #6  0x00abe7ab in pg_mul_s64_overflow (a=9223372036854775807, b=2147483648, result=0xbff1da68)     at ../../../../src/include/common/int.h:264 #7  0x00abfbff in int8mul (fcinfo=0x14d9d04) at int8.c:496 #8  0x00782675 in ExecInterpExpr (state=0x14d9c4c, econtext=0x14da15c, isnull=0xbff1dc3f) at execExprInterp.c:765 Whilst select '9223372036854775807'::int8 * 2147483647::int8; emits ERROR:  bigint out of range I've also discovered another trap-triggering case for a 64-bit platform: select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1 union all select 1; server closed the connection unexpectedly ... #5  0x00005576cfb1c9f3 in __negvdi2 () #6  0x00005576cf627c68 in bms_singleton_member (a=0x5576d09f7fb0) at bitmapset.c:691 #7  0x00005576cf72be0f in fix_append_rel_relids (root=0x5576d09df198, varno=31, subrelids=0x5576d09f7fb0)     at prepjointree.c:3830 #8  0x00005576cf7278c2 in pull_up_simple_subquery (root=0x5576d09df198, jtnode=0x5576d09f7470, rte=0x5576d09de300,     lowest_outer_join=0x0, containing_appendrel=0x5576d09f7368) at prepjointree.c:1277 ... (gdb) f 6 #6  0x00005576cf627c68 in bms_singleton_member (a=0x5576d09f7fb0) at bitmapset.c:691 691                             if (result >= 0 || HAS_MULTIPLE_ONES(w)) (gdb) p/x w $1 = 0x8000000000000000 Best regards, Alexander