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 1qHkKw-0005YN-7d for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Jul 2023 12:13:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qHkKv-0005EJ-3h for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Jul 2023 12:13:21 +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 1qHkKu-0005E9-MO for pgsql-hackers@lists.postgresql.org; Fri, 07 Jul 2023 12:13:20 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qHkKr-002X5m-7J for pgsql-hackers@postgresql.org; Fri, 07 Jul 2023 12:13:19 +0000 Received: from [10.4.12.61] (unknown [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: s.shinderuk@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 7EAC6E20E3C for ; Fri, 7 Jul 2023 15:13:14 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1688731994; bh=mkVLYo27Pftp1TyY8IrSBby3it2L/OxMeznvCihtWcs=; h=Message-ID:Date:User-Agent:From:Subject:To:From; b=TL+7J0/wK32IbYCjFZNOzPQPNW8cUu5CWxqvDlhg/b80MgVFuDZoPVj/hRqcDJtTk HhJE0zEjOOjppx67MafRbGSSD7WRmiXQTr7LGkd0xzO7OkUkb3bWcM7HCHt9xmO6mz z/OtXQZdX00I+tajQ0amLdY90tLVe2Wjfyg+pDSVRCYBeMHsBBurNOP7EKa2+mohj6 2KtY3HbE3u9un9SNIU4yT7SRe5zg4TVtm3vFxOLjzRcjNxaDLn3VAFJW3Rm/Mco0L7 E7XTNoeDkJeaLy6Zeaw42ocXNUkW4iRvIZTV7Jr1+WLetsuYJ+oPavU/C1gFXwqVez IOjvbFtGp4Njw== Content-Type: multipart/mixed; boundary="------------isDcY7jixIZ5oKvErutpSyAN" Message-ID: <2eda015b-7dff-47fd-d5e2-f1a9899b90a6@postgrespro.ru> Date: Fri, 7 Jul 2023 15:13:14 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Content-Language: en-US From: Sergey Shinderuk Subject: gcc -Wclobbered in PostgresMain To: PostgreSQL Hackers List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------isDcY7jixIZ5oKvErutpSyAN Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, hackers! While analyzing -Wclobbered warnings from gcc we found a true one in PostgresMain(): postgres.c: In function ‘PostgresMain’: postgres.c:4118:25: warning: variable ‘idle_in_transaction_timeout_enabled’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered] 4118 | bool idle_in_transaction_timeout_enabled = false; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ postgres.c:4119:25: warning: variable ‘idle_session_timeout_enabled’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered] 4119 | bool idle_session_timeout_enabled = false; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ These variables must be declared volatile, because they are read after longjmp(). send_ready_for_query declared there is volatile. Without volatile, these variables are kept in registers and restored by longjump(). I think, this is harmless because the error handling code calls disable_all_timeouts() anyway. But strictly speaking the code is invoking undefined behavior by reading those variables after longjmp(), so it's worth fixing. And for consistency with send_ready_for_query too. I believe, making them volatile doesn't affect performance in any way. I also moved firstchar's declaration inside the loop where it's used, to make it clear that this variable needn't be volatile and is not preserved after longjmp(). Best regards, -- Sergey Shinderuk https://postgrespro.com/ --------------isDcY7jixIZ5oKvErutpSyAN Content-Type: text/x-patch; charset=UTF-8; name="missing-volatile-longjmp.diff" Content-Disposition: attachment; filename="missing-volatile-longjmp.diff" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3Rjb3AvcG9zdGdyZXMuYyBiL3NyYy9iYWNrZW5k L3Rjb3AvcG9zdGdyZXMuYwppbmRleCAwMWI2Y2MxZjdkMy4uNTZkOGIwODE0YjUgMTAwNjQ0 Ci0tLSBhL3NyYy9iYWNrZW5kL3Rjb3AvcG9zdGdyZXMuYworKysgYi9zcmMvYmFja2VuZC90 Y29wL3Bvc3RncmVzLmMKQEAgLTQxMTEsMTIgKzQxMTEsMTEgQEAgUG9zdGdyZXNTaW5nbGVV c2VyTWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdLAogdm9pZAogUG9zdGdyZXNNYWluKGNv bnN0IGNoYXIgKmRibmFtZSwgY29uc3QgY2hhciAqdXNlcm5hbWUpCiB7Ci0JaW50CQkJZmly c3RjaGFyOwogCVN0cmluZ0luZm9EYXRhIGlucHV0X21lc3NhZ2U7CiAJc2lnam1wX2J1Zgls b2NhbF9zaWdqbXBfYnVmOwogCXZvbGF0aWxlIGJvb2wgc2VuZF9yZWFkeV9mb3JfcXVlcnkg PSB0cnVlOwotCWJvb2wJCWlkbGVfaW5fdHJhbnNhY3Rpb25fdGltZW91dF9lbmFibGVkID0g ZmFsc2U7Ci0JYm9vbAkJaWRsZV9zZXNzaW9uX3RpbWVvdXRfZW5hYmxlZCA9IGZhbHNlOwor CXZvbGF0aWxlIGJvb2wgaWRsZV9pbl90cmFuc2FjdGlvbl90aW1lb3V0X2VuYWJsZWQgPSBm YWxzZTsKKwl2b2xhdGlsZSBib29sIGlkbGVfc2Vzc2lvbl90aW1lb3V0X2VuYWJsZ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