glsl: disable UBSan vptr check for ir_instruction
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

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 <jasuarez@igalia.com>
Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36884>
This commit is contained in:
Juan A. Suarez Romero 2025-08-20 16:35:03 +02:00 committed by Marge Bot
parent fa25e2de48
commit ca989ecdec

View file

@ -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