Created attachment 248689 [details] devel/qt5-script diff fixing optimisation issue with Clang (or whatever the order of cause and effect is) Cf. bug #265989 The attached patch (taken from OpenBSD, https://github.com/openbsd/ports/blob/e10f7e1a39f85873183c232462850449f777e16f/x11/qt5/qtscript/patches/patch-src_3rdparty_javascriptcore_JavaScriptCore_interpreter_CallFrame_h) fixes, at least on FreeBSD 14, the problem reported with cad/qcad in bug #265989 (and presumably other things using qtscript).
Should this also be reported to Clang, since it's Clang that miscompiles devel/qt5-script.
My first impression is clang is within its rights to break this code. The JS implementation tries to store metadata bits in the low bits of a pointer type. The compiler is allowed to assume that the low bits of a pointer value are zero. (Assuming the pointed-to type has alignment rules, which is normally the case.) LLVM itself uses a wrapper class instead of an illegal pointer value. The wrapper class stores the pointer+tag combination as an integer and provides a getter method to return an untagged pointer.
(In reply to John F. Carr from comment #2) I see. In this case this should be reported to the devel/qt5-script upstream. They should stop using hacks and do the same thing properly. Yuri
Here is an example: struct S { long alignment; int this_lowbit(); }; int S::this_lowbit() { return reinterpret_cast<signed long>(this) & 1; } The method this_lowbit always returns zero with optimization enabled.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=9e3ff8f0b99e7b3074f3e83c954a0395185f63f0 commit 9e3ff8f0b99e7b3074f3e83c954a0395185f63f0 Author: Tomas Tevesz <ice@extreme.hu> AuthorDate: 2024-03-22 21:16:49 +0000 Commit: Gleb Popov <arrowd@FreeBSD.org> CommitDate: 2024-03-22 21:18:36 +0000 devel/qt5-script: Prevent clang from optimizing the code with undefined behavior PR: 277236 Obtained from: OpenBSD ports devel/qt5-script/Makefile | 2 +- ...criptcore_JavaScriptCore_interpreter_CallFrame.h (new) | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
Pushed, thanks.