|
From: Julian S. <js...@ac...> - 2015-03-27 17:11:22
|
Making all in gdbserver_tests
Making all in memcheck/tests/vbit-test
irops.c:1053:12: error: size of array 'ensure_complete' is negative
extern int ensure_complete[
^
Makefile:720: recipe for target 'vbit_test-irops.o' failed
make[2]: *** [vbit_test-irops.o] Error 1
/me thinks .. Uh huh .. Florian has been doing home-grown static
asserts :-)
This is good.
Except, there are dozens of places where I would like to have static asserts
generally available. Insanely enough, there is, in include/vki/vki-linux.h,
a definition of VKI_STATIC_ASSERT. Maybe we should pull it out, rename it
VG_STATIC_ASSERT, and make it generally available. What do you think?
J
|
|
From: Florian K. <fl...@ei...> - 2015-03-27 22:19:05
|
On 27.03.2015 18:11, Julian Seward wrote: > > /me thinks .. Uh huh .. Florian has been doing home-grown static > asserts :-) > Just this one :) > Except, there are dozens of places where I would like to have static asserts > generally available. Insanely enough, there is, in include/vki/vki-linux.h, > a definition of VKI_STATIC_ASSERT. Maybe we should pull it out, rename it > VG_STATIC_ASSERT, and make it generally available. What do you think? I didn't know about VKI_STATIC_ASSERT. include/vki wasn't a likely place to look for that sort of thing.. VKI_STATIC_ASSERT is used inside vki-linux.h so pulling it out is probably not ideal. It just creates a dependency as include/vki/*.h does not depend on valgrind headers right now. It's best to just leave it alone. Now, we want static asserts in VEX and valgrind. So we add VEX_STATIC_ASSERT to main_util.h and VG_STATIC_ASSERT in pub_tool_basics.h, like we do with LIKELY and friends. I like the implementation of VKI_STATIC_ASSERT (without the C++ mumbo-jumbo) better than what I came up with, as it avoids adding a symbol. So I would use that approach for VEX/VG_STATIC_ASSERT as well. Florian |
|
From: Matthias S. <zz...@ge...> - 2015-03-28 09:19:15
|
On 27.03.2015 23:18, Florian Krohm wrote: > > I like the implementation of VKI_STATIC_ASSERT (without the C++ > mumbo-jumbo) better than what I came up with, as it avoids adding a > symbol. So I would use that approach for VEX/VG_STATIC_ASSERT as well. Maybe it is possible to use static_assert (C++-11) or _Static_assert (should be in C11) if the compiler supports it. Only in other cases the code could fall back to a seperate implementation. Regards Matthias |
|
From: Florian K. <fl...@ei...> - 2015-03-28 18:46:47
|
On 28.03.2015 10:19, Matthias Schwarzott wrote: > On 27.03.2015 23:18, Florian Krohm wrote: >> >> I like the implementation of VKI_STATIC_ASSERT (without the C++ >> mumbo-jumbo) better than what I came up with, as it avoids adding a >> symbol. So I would use that approach for VEX/VG_STATIC_ASSERT as well. I spoke too fast. VKI_STATIC_ASSERT cannot be used on file scope. So it's out. > > Maybe it is possible to use static_assert (C++-11) or _Static_assert > (should be in C11) if the compiler supports it. C++'s static_assert cannot be used on file scope either. So I ended up using +// Poor man's static assert +#define STATIC_ASSERT(x) extern int VG_(VG_(VG_(unused)))[(x) ? 1 : -1] which works in all scopes (expect function parameter scope).. Florian |
|
From: Matthias S. <zz...@ge...> - 2015-03-28 20:04:28
|
On 28.03.2015 19:46, Florian Krohm wrote:
>
> C++'s static_assert cannot be used on file scope either.
c++'s static_assert and C's _Static_assert can be used at file scope.
As far as I could find out, they are declarations and so are allowed
inside functions, stucts, classes and blocks (including file scope in
and out of namespaces).
I tried it and it works quite nice:
#define STATIC_ASSERT(expr) _Static_assert(expr, "failed")
I added a bogus check, and the error message looks nicer:
In file included from pub_core_basics.h:40:0,
from m_cache.c:32:
../include/pub_tool_basics.h:380:1: error: static assertion failed: "failed"
STATIC_ASSERT(1==2);
^
The only missing piece is how to detect availability of this keyword.
Maybe a check for the gcc version is enough here.
Matthias
|
|
From: Julian S. <js...@ac...> - 2015-03-31 18:31:55
|
On 28/03/15 19:46, Florian Krohm wrote: > So I ended up using > +// Poor man's static assert > +#define STATIC_ASSERT(x) extern int VG_(VG_(VG_(unused)))[(x) ? 1 : -1] Excellent. There are a whole bunch of asserts, particularly to do with structure sizes, that we could pull out and turn into static asserts. If anyone has enthusiasm :) J |