ubench.h
ubench.h copied to clipboard
ubench use `asm` instead of `__asm__` leads to compile fail
bug
ubench use asm instead of __asm__ leads to compile fail
reproduce
==> a1.c <==
#include "ubench.h"
UBENCH(foo, bar) {}
UBENCH_MAIN();
==> a2.c <==
#define asm __asm__
#include "ubench.h"
UBENCH(foo, bar) {}
UBENCH_MAIN();
actual
OK when -std=gnu17
% gcc -std=gnu17 a1.c -lm && echo OK
OK
compile fail when -std=c17
% gcc -std=c17 a1.c -lm && echo OK
In file included from a1.c:1:
a1.c: In function ‘ubench_do_nothing’:
ubench.h:882:5: error: ‘asm’ undeclared (first use in this function)
882 | asm volatile("" : : "r"(ptr), "m"(ptr) : "memory"); \
| ^~~
ubench.h:896:3: note: in expansion of macro ‘UBENCH_DECLARE_DO_NOTHING’
896 | UBENCH_DECLARE_DO_NOTHING() \
| ^~~~~~~~~~~~~~~~~~~~~~~~~
ubench.h:907:3: note: in expansion of macro ‘UBENCH_STATE’
907 | UBENCH_STATE(); \
| ^~~~~~~~~~~~
a1.c:4:1: note: in expansion of macro ‘UBENCH_MAIN’
4 | UBENCH_MAIN();
| ^~~~~~~~~~~
ubench.h:882:5: note: each undeclared identifier is reported only once for each function it appears in
882 | asm volatile("" : : "r"(ptr), "m"(ptr) : "memory"); \
| ^~~
ubench.h:896:3: note: in expansion of macro ‘UBENCH_DECLARE_DO_NOTHING’
896 | UBENCH_DECLARE_DO_NOTHING() \
| ^~~~~~~~~~~~~~~~~~~~~~~~~
ubench.h:907:3: note: in expansion of macro ‘UBENCH_STATE’
907 | UBENCH_STATE(); \
| ^~~~~~~~~~~~
a1.c:4:1: note: in expansion of macro ‘UBENCH_MAIN’
4 | UBENCH_MAIN();
| ^~~~~~~~~~~
ubench.h:882:9: error: expected ‘;’ before ‘volatile’
882 | asm volatile("" : : "r"(ptr), "m"(ptr) : "memory"); \
| ^~~~~~~~
ubench.h:896:3: note: in expansion of macro ‘UBENCH_DECLARE_DO_NOTHING’
896 | UBENCH_DECLARE_DO_NOTHING() \
| ^~~~~~~~~~~~~~~~~~~~~~~~~
ubench.h:907:3: note: in expansion of macro ‘UBENCH_STATE’
907 | UBENCH_STATE(); \
| ^~~~~~~~~~~~
a1.c:4:1: note: in expansion of macro ‘UBENCH_MAIN’
4 | UBENCH_MAIN();
| ^~~~~~~~~~~
workaround
% gcc -std=c17 a2.c -lm && echo OK
OK
Happy to accept a PR.