* [PATCH v3] gawk: Fix intformat ptest failure with clang
@ 2026-11-25 16:54 Khem Raj
2026-11-26 7:00 ` [OE-core] " Mathieu Dubois-Briand
0 siblings, 1 reply; 3+ messages in thread
From: Khem Raj @ 2026-11-25 16:54 UTC (permalink / raw)
To: openembedded-core; +Cc: Khem Raj
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.
v3: Update patch status as its now applied upstream
...efined-behavior-converting-out-of-ra.patch | 52 +++++++++++++++++++
meta/recipes-extended/gawk/gawk_5.4.1.bb | 1 +
2 files changed, 53 insertions(+)
create mode 100644 meta/recipes-extended/gawk/gawk/0002-printf-Avoid-undefined-behavior-converting-out-of-ra.patch
diff --git a/meta/recipes-extended/gawk/gawk/0002-printf-Avoid-undefined-behavior-converting-out-of-ra.patch b/meta/recipes-extended/gawk/gawk/0002-printf-Avoid-undefined-behavior-converting-out-of-ra.patch
new file mode 100644
index 0000000000..aa2b2c1de8
--- /dev/null
+++ b/meta/recipes-extended/gawk/gawk/0002-printf-Avoid-undefined-behavior-converting-out-of-ra.patch
@@ -0,0 +1,52 @@
+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: Backport [https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=58356d4681f7e9dc2f48f7dc099346dc3f03d441]
+
+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.
diff --git a/meta/recipes-extended/gawk/gawk_5.4.1.bb b/meta/recipes-extended/gawk/gawk_5.4.1.bb
index d3bf532528..ba28f8832a 100644
--- a/meta/recipes-extended/gawk/gawk_5.4.1.bb
+++ b/meta/recipes-extended/gawk/gawk_5.4.1.bb
@@ -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"
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [OE-core] [PATCH v3] gawk: Fix intformat ptest failure with clang
2026-11-25 16:54 [PATCH v3] gawk: Fix intformat ptest failure with clang Khem Raj
@ 2026-11-26 7:00 ` Mathieu Dubois-Briand
2026-11-26 7:02 ` Mathieu Dubois-Briand
0 siblings, 1 reply; 3+ messages in thread
From: Mathieu Dubois-Briand @ 2026-11-26 7:00 UTC (permalink / raw)
To: raj.khem, openembedded-core; +Cc: Khem Raj
On Wed Nov 25, 2026 at 5:54 PM CET, Khem Raj via openembedded-core wrote:
> 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>
> ---
Hi Khem,
Sorry, it looks like the v1 was merged. Can you send a patch update
instead?
Thanks,
Mathieu
--
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [OE-core] [PATCH v3] gawk: Fix intformat ptest failure with clang
2026-11-26 7:00 ` [OE-core] " Mathieu Dubois-Briand
@ 2026-11-26 7:02 ` Mathieu Dubois-Briand
0 siblings, 0 replies; 3+ messages in thread
From: Mathieu Dubois-Briand @ 2026-11-26 7:02 UTC (permalink / raw)
To: raj.khem, openembedded-core; +Cc: Khem Raj
On Thu Nov 26, 2026 at 8:00 AM CET, Mathieu Dubois-Briand wrote:
> On Wed Nov 25, 2026 at 5:54 PM CET, Khem Raj via openembedded-core wrote:
>> 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>
>> ---
>
> Hi Khem,
>
> Sorry, it looks like the v1 was merged. Can you send a patch update
> instead?
>
> Thanks,
> Mathieu
Sorry, I just saw you sent it already.
--
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-26 7:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 16:54 [PATCH v3] gawk: Fix intformat ptest failure with clang Khem Raj
2026-11-26 7:00 ` [OE-core] " Mathieu Dubois-Briand
2026-11-26 7:02 ` Mathieu Dubois-Briand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox