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 1uc3YZ-008T61-IA for pgsql-committers@arkaria.postgresql.org; Wed, 16 Jul 2025 14:56:27 +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 1uc3YX-00B5pv-K8 for pgsql-committers@arkaria.postgresql.org; Wed, 16 Jul 2025 14:56:26 +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 1uc3YX-00B5pn-D4 for pgsql-committers@lists.postgresql.org; Wed, 16 Jul 2025 14:56:26 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uc3YW-007awv-0U; Wed, 16 Jul 2025 14:56:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 56GEuKDx1244429; Wed, 16 Jul 2025 10:56:20 -0400 From: Tom Lane To: David Rowley cc: Peter Eisentraut , Masahiko Sawada , pgsql-committers@lists.postgresql.org Subject: Re: pgsql: pg_logicalinspect: Fix possible crash when passing a directory p In-reply-to: References: <6c00a8b2-0c40-44f0-b603-f6ae28b7694a@eisentraut.org> Comments: In-reply-to David Rowley message dated "Fri, 21 Mar 2025 00:17:56 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1244427.1752677780.1@sss.pgh.pa.us> Date: Wed, 16 Jul 2025 10:56:20 -0400 Message-ID: <1244428.1752677780@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk [ this thread was referenced recently, bringing it back top-of-mind ] David Rowley writes: > On Thu, 13 Mar 2025 at 21:33, Peter Eisentraut wrote: >> Is there a way to reshuffle those conditionals to make this actually do >> something useful on MSVC? > I've just been experimenting with this and it seems the problem isn't > with pg_unreachable(), it's with the compiler not understanding that > the particular pg_unreachable() is always reached. > What's happening is down to the multi-eval protection code for elevel > in ereport_domain(). Because elevel is assigned to the variable > "elevel_" the compiler seems to lose its proof that the > pg_unreachable() is always reached. Adjusting that condition to use > the elevel parameter directly makes the warning disappear. Looking again at the code for ereport_domain(), I wondered if something like this would help MSVC see through it: #define ereport_domain(elevel, domain, ...) \ do { \ const int elevel_ = (elevel); \ + const bool is_error_ = (elevel_ >= ERROR); \ pg_prevent_errno_in_scope(); \ if (errstart(elevel_, domain)) \ __VA_ARGS__, errfinish(__FILE__, __LINE__, __func__); \ - if (elevel_ >= ERROR) \ + if (is_error_) \ pg_unreachable(); \ } while(0) This preserves single evaluation of the elevel parameter, and perhaps it'd move the needle on whether the compiler thinks is_error_ is a compile-time constant. I'm just guessing though, don't have this compiler to test with. regards, tom lane