noop-renderer: Make sure buffer access doesn't get optimised out

noop-renderer needs to actually access the buffer content, to ensure
that the bad-buffer test works. This was previously done using a
volatile variable, but clang rightly pointed out that the variable
access had no effect (since the volatile stack variable was never read
from, and the source is not volatile), so 9b0b5b57dd changed it to be
explicitly marked it as unused to suppress the compiler warning.

Unfortunately suppressing the warning still leaves the compiler free to
optimise out the access.

Replace the variable decorations with actually using the result of the
read, so we can be really sure that it's never going to be optimised
away.

Signed-off-by: Daniel Stone <daniels@collabora.com>
dev
Daniel Stone 2 years ago committed by Pekka Paalanen
parent 19278569a3
commit 450ec38d79
  1. 30
      libweston/noop-renderer.c

@ -31,6 +31,11 @@
#include <libweston/libweston.h> #include <libweston/libweston.h>
#include "libweston-internal.h" #include "libweston-internal.h"
struct noop_renderer {
struct weston_renderer base;
unsigned char seed; /* see comment in attach() */
};
static int static int
noop_renderer_read_pixels(struct weston_output *output, noop_renderer_read_pixels(struct weston_output *output,
pixman_format_code_t format, void *pixels, pixman_format_code_t format, void *pixels,
@ -55,10 +60,12 @@ noop_renderer_flush_damage(struct weston_surface *surface,
static void static void
noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer) noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
{ {
struct noop_renderer *renderer =
wl_container_of(es->compositor->renderer, renderer, base);
struct wl_shm_buffer *shm_buffer; struct wl_shm_buffer *shm_buffer;
uint8_t *data; uint8_t *data;
uint32_t size, i, height, stride; uint32_t size, i, height, stride;
__attribute__((unused)) int unused = 0; unsigned char unused = 0;
if (!buffer) if (!buffer)
return; return;
@ -90,11 +97,18 @@ noop_renderer_attach(struct weston_surface *es, struct weston_buffer *buffer)
unused ^= data[i]; unused ^= data[i];
wl_shm_buffer_end_access(shm_buffer); wl_shm_buffer_end_access(shm_buffer);
/* Make sure that our unused is actually used, otherwise the compiler
* is free to notice that our reads have no effect and elide them. */
renderer->seed = unused;
} }
static void static void
noop_renderer_destroy(struct weston_compositor *ec) noop_renderer_destroy(struct weston_compositor *ec)
{ {
struct noop_renderer *renderer =
wl_container_of(ec->renderer, renderer, base);
weston_log("no-op renderer SHM seed: %d\n", renderer->seed);
free(ec->renderer); free(ec->renderer);
ec->renderer = NULL; ec->renderer = NULL;
} }
@ -102,18 +116,18 @@ noop_renderer_destroy(struct weston_compositor *ec)
WL_EXPORT int WL_EXPORT int
noop_renderer_init(struct weston_compositor *ec) noop_renderer_init(struct weston_compositor *ec)
{ {
struct weston_renderer *renderer; struct noop_renderer *renderer;
renderer = zalloc(sizeof *renderer); renderer = zalloc(sizeof *renderer);
if (renderer == NULL) if (renderer == NULL)
return -1; return -1;
renderer->read_pixels = noop_renderer_read_pixels; renderer->base.read_pixels = noop_renderer_read_pixels;
renderer->repaint_output = noop_renderer_repaint_output; renderer->base.repaint_output = noop_renderer_repaint_output;
renderer->flush_damage = noop_renderer_flush_damage; renderer->base.flush_damage = noop_renderer_flush_damage;
renderer->attach = noop_renderer_attach; renderer->base.attach = noop_renderer_attach;
renderer->destroy = noop_renderer_destroy; renderer->base.destroy = noop_renderer_destroy;
ec->renderer = renderer; ec->renderer = &renderer->base;
return 0; return 0;
} }

Loading…
Cancel
Save