r600: Use container_of instead of direct pointer cast
Fixes strict aliasing violation: In function 'r600_init_resource_fields', inlined from 'r600_buffer_create' at ../src/gallium/drivers/r600/r600_buffer_common.c:578:2: ../src/gallium/drivers/r600/r600_buffer_common.c:139:48: warning: array subscript 'struct r600_texture[0]' is partly outside array bounds of 'unsigned char[264]' [-Warray-bounds] 139 | if ((res->b.b.target != PIPE_BUFFER && !rtex->surface.is_linear) || | ^~~~~~~~~~~~~~~~~~~~~~~~ In file included from ../src/util/os_memory.h:37, from ../src/util/u_memory.h:38, from ../src/gallium/include/pipe/p_state.h:47, from ../src/gallium/auxiliary/util/u_inlines.h:34, from ../src/gallium/auxiliary/pipebuffer/pb_buffer.h:49, from ../src/gallium/include/winsys/radeon_winsys.h:46, from ../src/gallium/drivers/r600/r600_pipe_common.h:37, from ../src/gallium/drivers/r600/r600_cs.h:33, from ../src/gallium/drivers/r600/r600_buffer_common.c:27: In function 'r600_alloc_buffer_struct', inlined from 'r600_buffer_create' at ../src/gallium/drivers/r600/r600_buffer_common.c:576:34: ../src/util/os_memory_stdc.h:41:27: note: object of size 264 allocated by 'malloc' 41 | #define os_malloc(_size) malloc(_size) | ^~~~~~~~~~~~~ ../src/util/u_memory.h:46:24: note: in expansion of macro 'os_malloc' 46 | #define MALLOC(_size) os_malloc(_size) | ^~~~~~~~~ ../src/util/u_memory.h:54:41: note: in expansion of macro 'MALLOC' 54 | #define MALLOC_STRUCT(T) (struct T *) MALLOC(sizeof(struct T)) | ^~~~~~ ../src/gallium/drivers/r600/r600_buffer_common.c:554:19: note: in expansion of macro 'MALLOC_STRUCT' 554 | rbuffer = MALLOC_STRUCT(r600_resource); | ^~~~~~~~~~~~~ Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21781>
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "r600_cs.h"
|
||||
#include "evergreen_compute.h"
|
||||
#include "compute_memory_pool.h"
|
||||
#include "util/macros.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "util/u_upload_mgr.h"
|
||||
#include <inttypes.h>
|
||||
@@ -107,7 +108,7 @@ void r600_init_resource_fields(struct r600_common_screen *rscreen,
|
||||
struct r600_resource *res,
|
||||
uint64_t size, unsigned alignment)
|
||||
{
|
||||
struct r600_texture *rtex = (struct r600_texture*)res;
|
||||
struct r600_texture *rtex = container_of(res, struct r600_texture, resource);
|
||||
|
||||
res->bo_size = size;
|
||||
res->bo_alignment = alignment;
|
||||
|
Reference in New Issue
Block a user