From 3fe01158335d43ed133755aaffd41270c5e7af1a Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 4 Jun 2025 14:33:53 -0400
Subject: [PATCH v1 2/2] Use pg_assume() to avoid compiler warning below
 exec_set_found()

The warning, visible when building with -O3 and a recent-ish gcc, is due to
gcc not realizing that found is a byvalue type and therefore will never be
interpreted as a varlena type.

Discussion: https://postgr.es/m/3prdb6hkep3duglhsujrn52bkvnlkvhc54fzvph2emrsm4vodl@77yy6j4hkemb
Discussion: https://postgr.es/m/20230316172818.x6375uvheom3ibt2%40awork3.anarazel.de
Discussion: https://postgr.es/m/20240207203138.sknifhlppdtgtxnk%40awork3.anarazel.de
---
 src/pl/plpgsql/src/pl_exec.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index bb99781c56e..ecac29e830b 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -8606,6 +8606,15 @@ exec_set_found(PLpgSQL_execstate *estate, bool state)
 	PLpgSQL_var *var;
 
 	var = (PLpgSQL_var *) (estate->datums[estate->found_varno]);
+
+	/*
+	 * The pg_assume() avoids a spurious warning with some compilers due to
+	 * compiler not realizing the VARATT_IS_EXTERNAL_NON_EXPANDED() branch in
+	 * assign_simple_var() will never be reached, due to "found" being a
+	 * boolean, a byvalue type.
+	 */
+	pg_assume(var->datatype->typlen != -1);
+
 	assign_simple_var(estate, var, BoolGetDatum(state), false, false);
 }
 
-- 
2.48.1.76.g4e746b1a31.dirty

