new file mode 100644
@@ -0,0 +1,53 @@
+From e00db6a8ee76f2618f38c0dde477cb111fb0df41 Mon Sep 17 00:00:00 2001
+From: Khem Raj <khem.raj@oss.qualcomm.com>
+Date: Fri, 16 Oct 2026 08:14:03 +0000
+Subject: [PATCH] printf: Avoid undefined behavior converting out of range
+ doubles
+
+format_int() casts the value to uintmax_t (or intmax_t) and then
+checks whether converting it back yields the original value to decide
+if it fits. A double that is out of range for the integer type makes
+the conversion itself undefined behavior, and clang folds the
+round-trip check away, so e.g. sprintf("%x", 2^64) prints
+0x8000000000000000 instead of falling back to %g. This makes the
+intformat test fail when gawk is built with clang.
+
+Check the range before doing the conversion instead.
+
+Upstream-Status: Pending
+Reported upstream: https://lists.gnu.org/archive/html/bug-gawk/2026-11/msg00028.html
+
+Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
+---
+diff --git a/printf.c b/printf.c
+index 02646928..590786c9 100644
+--- a/printf.c
++++ b/printf.c
+@@ -926,23 +926,23 @@ format_integer_digits(NODE *arg, struct flags *flags, bool *used_float)
+ chbuf = (flags->format == 'X' ? Uchbuf : lchbuf);
+
+ if (tmpval < 0) {
+- uval = (uintmax_t) (intmax_t) tmpval;
+- if ((AWKNUM)(intmax_t)uval != double_to_int(tmpval)) {
++ if (tmpval <= INTMAX_MIN) {
+ flags->format = 'g';
+ free((void *) buf);
+ *used_float = true;
+
+ return format_float(arg, flags);
+ }
++ uval = (uintmax_t) (intmax_t) tmpval;
+ } else {
+- uval = (uintmax_t) tmpval;
+- if ((AWKNUM)uval != double_to_int(tmpval)) {
++ if (tmpval >= UINTMAX_MAX) {
+ flags->format = 'g';
+ free((void *) buf);
+ *used_float = true;
+
+ return format_float(arg, flags);
+ }
++ uval = (uintmax_t) tmpval;
+ }
+
+ // generate the digits backwards.
@@ -28,6 +28,7 @@ PACKAGECONFIG[pma-if-64bit] = "--enable-pma,--disable-pma, "
SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.xz \
file://run-ptest \
file://0001-configure.ac-re-enable-disabled-printf-features.patch \
+ file://0002-printf-Avoid-undefined-behavior-converting-out-of-ra.patch \
"
SRC_URI[sha256sum] = "07f6f7342b7febe4313fc2c2542ad93d64fe20ad8717200109f105a826f5fd37"
format_int() relies on undefined behavior when converting out of range doubles to integers, which clang optimizes in a way that makes the intformat test fail. Add a patch to range check before converting. AI-Generated: Uses Claude Code Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com> --- v2: Use the patch suggested by gawk maintainer ( Arnold ) which also fixes the problem. ...efined-behavior-converting-out-of-ra.patch | 53 +++++++++++++++++++ meta/recipes-extended/gawk/gawk_5.4.1.bb | 1 + 2 files changed, 54 insertions(+) create mode 100644 meta/recipes-extended/gawk/gawk/0002-printf-Avoid-undefined-behavior-converting-out-of-ra.patch