From ca989ecdecce09295d9280587ac876fb65d11a91 Mon Sep 17 00:00:00 2001 From: "Juan A. Suarez Romero" Date: Wed, 20 Aug 2025 16:35:03 +0200 Subject: [PATCH] glsl: disable UBSan vptr check for ir_instruction With UBSan enabled, we get the following issue: ``` ../src/compiler/glsl/ir.h:116:4: runtime error: member access within address 0x555637c62c10 which does not point to an object of type 'ir_instruction' 0x555637c62c10: note: object has invalid vptr 5f 76 61 6c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^~~~~~~~~~~~~~~~~~~~~~~ invalid vptr ``` This only happens the first time a ir_variable (which derives from ir_instruction) is created; next calls don't show the issue any more. The problem is with the following call in the `new()` operator: ``` ((ir_instruction*)((uintptr_t)p))->node_linalloc = ctx; ``` In this case, the ir_instruction structure is not fully constructed and thus UBSan complains about it. In the next calls, as the structure is now fully constructed it doesn't complain any more. The right approach would be fully creating the structure, and afterwards doing the context assignment. But this would require quite a lot of changes, passing the context through the constructors to assign it. A simpler solution is just disabling this check for this case, as we know what is happening. Signed-off-by: Juan A. Suarez Romero Reviewed-by: Yonggang Luo Part-of: --- src/compiler/glsl/ir.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h index f967ccb1d4b..edebf5f3ba4 100644 --- a/src/compiler/glsl/ir.h +++ b/src/compiler/glsl/ir.h @@ -113,9 +113,13 @@ public: */ linear_ctx *node_linalloc; - DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(ir_instruction, - ((ir_instruction*)((uintptr_t)p))->node_linalloc = ctx;, - UNREACHABLE("don't allocate ir_instruction with new[]");) + /* ir_instruction structure is not fully constructed the first time the + * new() operators are invoked, so UBSan shouldn't check vptrs. + */ + DECLARE_LINEAR_ZALLOC_CXX_OPERATORS_NO_SANITIZE(ir_instruction, + ((ir_instruction*)((uintptr_t)p))->node_linalloc = ctx;, + UNREACHABLE("don't allocate ir_instruction with new[]");, + VPTR) /** * GCC 4.7+ and clang warn when deleting an ir_instruction unless