libsdl-org/sdl2-compat

Compiler warnings in testgles2_sdf.c

icculus opened this issue · 7 comments

Not sure why this doesn't happen in SDL2 (or does it...?), but we should clean up these warnings in sdl2-compat's testgles2_sdf.c, and backport the fix to SDL2/SDL3.

[113/199] Building C object CMakeFiles/testgles2_sdf.dir/test/testgles2_sdf.c.o
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c: In function ‘loop’:
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:417:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
  417 |         SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
      |                                                          ~^~
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:417:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:417:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:418:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
  418 |         SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
      |                                                          ~^~
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:418:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:418:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:419:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
  419 |         SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
      |                                                          ~^~
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:419:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:419:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:420:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
  420 |         SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
      |                                                          ~^~
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:420:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:420:59: warning: operation on ‘f’ may be undefined [-Wsequence-point]
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c: In function ‘main’:
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:573:16: warning: implicit declaration of function ‘GetNearbyFilename’ [-Wimplicit-function-declaration]
  573 |         path = GetNearbyFilename(f);
      |                ^~~~~~~~~~~~~~~~~
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:573:14: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
  573 |         path = GetNearbyFilename(f);
      |              ^
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:738:44: warning: pointer targets in passing argument 2 of ‘process_shader’ differ in signedness [-Wpointer-sign]
  738 |         process_shader(&data->shader_vert, GLES2_VertexSrc_Default_, GL_VERTEX_SHADER);
      |                                            ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                            |
      |                                            const Uint8 * {aka const unsigned char *}
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:143:45: note: expected ‘const char *’ but argument is of type ‘const Uint8 *’ {aka ‘const unsigned char *’}
  143 | process_shader(GLuint *shader, const char * source, GLint shader_type)
      |                                ~~~~~~~~~~~~~^~~~~~
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:742:52: warning: pointer targets in passing argument 2 of ‘process_shader’ differ in signedness [-Wpointer-sign]
  742 |                 process_shader(&data->shader_frag, GLES2_FragmentSrc_TextureABGRSrc_SDF, GL_FRAGMENT_SHADER);
      |                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                    |
      |                                                    const Uint8 * {aka const unsigned char *}
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:143:45: note: expected ‘const char *’ but argument is of type ‘const Uint8 *’ {aka ‘const unsigned char *’}
  143 | process_shader(GLuint *shader, const char * source, GLint shader_type)
      |                                ~~~~~~~~~~~~~^~~~~~
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:747:48: warning: pointer targets in passing argument 2 of ‘process_shader’ differ in signedness [-Wpointer-sign]
  747 |             process_shader(&data->shader_frag, GLES2_FragmentSrc_TextureABGRSrc_, GL_FRAGMENT_SHADER);
      |                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                |
      |                                                const Uint8 * {aka const unsigned char *}
/home/icculus/projects/sdl2-compat/test/testgles2_sdf.c:143:45: note: expected ‘const char *’ but argument is of type ‘const Uint8 *’ {aka ‘const unsigned char *’}
  143 | process_shader(GLuint *shader, const char * source, GLint shader_type)
      |                                ~~~~~~~~~~~~~^~~~~~

I'm also getting this error on SDL3:

/home/maarten/programming/SDL/test/testgles2_sdf.c: In function ‘process_shader’:
/home/maarten/programming/SDL/test/testgles2_sdf.c:155:58: warning: implicit declaration of function ‘fflush’ [-Wimplicit-function-declaration]
  155 |         SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
      |                                                          ^~~~~~
/home/maarten/programming/SDL/test/testgles2_sdf.c:155:65: error: ‘stderr’ undeclared (first use in this function)
  155 |         SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
      |                                                                 ^~~~~~
/home/maarten/programming/SDL/test/testgles2_sdf.c:87:1: note: ‘stderr’ is defined in header ‘<stdio.h>’; did you forget to ‘#include <stdio.h>’?
   86 | #include "../src/render/opengles2/SDL_gles2funcs.h"
  +++ |+#include <stdio.h>
   87 | #undef SDL_PROC
/home/maarten/programming/SDL/test/testgles2_sdf.c:155:65: note: each undeclared identifier is reported only once for each function it appears in
  155 |         SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
      |                       

Does this show SDL_Log_Flush()` would be useful?

And testgles2_sdf wasn't being built in the sdl repo. No build == no error :)

Maybe we should just delete it then. :)

(Arguably, SDL_Log should flush by default, I'm actually surprised it doesn't...if it doesn't.)

Should it? Aren't you then introducing implicit synchronization when using multithreading?

We definitely shouldn't fflush() here. I also think we shouldn't generally flush the log, that would greatly reduce the performance for applications that are spewing lots of logging.

libsdl-org/SDL#6706 adds testgles_sdf.c back to the test matrix for SDL3

I think these are fixed in #9