decrease warning for -pedantic

This commit is contained in:
MITSUNARI Shigeo 2013-01-12 18:03:39 +09:00
parent b8a31fd932
commit 921aa019ae
9 changed files with 41 additions and 29 deletions

View file

@ -24,7 +24,7 @@ endif
all: $(TARGET)
CFLAGS_WARN=-Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith
CFLAGS_WARN=-Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -pedantic
CFLAGS=-g -O2 -fomit-frame-pointer -Wall -fno-operator-names -I../ $(CFLAGS_WARN)
@ -82,6 +82,7 @@ bf64 : bf.cpp $(XBYAK_INC)
memfunc : memfunc.cpp $(XBYAK_INC)
memfunc64 : memfunc.cpp $(XBYAK_INC)
toyvm : toyvm.cpp $(XBYAK_INC)
static_buf: static_buf.cpp $(XBYAK_INC)
static_buf64: static_buf.cpp $(XBYAK_INC)
test_util : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h
test_util2 : test_util.cpp $(XBYAK_INC) ../xbyak/xbyak_util.h

View file

@ -191,7 +191,7 @@ int main(int argc, char *argv[])
Brainfuck bf(ifs);
if (mode == 0) {
static int stack[128 * 1024];
((void (*)(void*, void*, int *))(const void*)bf.getCode())((void*)putchar, (void*)getchar, stack);
bf.getCode<void (*)(void*, void*, int *)>()(Xbyak::CastTo<void*>(putchar), Xbyak::CastTo<void*>(getchar), stack);
} else {
dump(bf.getCode(), bf.getSize());
}

View file

@ -192,7 +192,7 @@ int main(int argc, char *argv[])
Quantize jit(qTbl);
//printf("jit size=%d, ptr=%p\n", jit.getSize(), jit.getCode());
void (*quantize2)(uint32*, const uint32*, const uint32 *) = (void (*)(uint32*, const uint32*, const uint32 *))(const void*)jit.getCode();
void (*quantize2)(uint32*, const uint32*, const uint32 *) = jit.getCode<void (*)(uint32*, const uint32*, const uint32 *)>();
quantize(dest, src, qTbl);
quantize2(dest2, src, qTbl);

View file

@ -27,7 +27,7 @@ struct Code : Xbyak::CodeGenerator {
inline int add(int a, int b)
{
return ((int (*)(int,int))(void*)buf)(a, b);
return Xbyak::CastTo<int (*)(int,int)>(buf)(a, b);
}
int main()

View file

@ -50,7 +50,7 @@ public:
#endif
ret();
}
int (*get() const)(int) { return (int (*)(int))(const void*)getCode(); }
int (*get() const)(int) { return getCode<int(*)(int)>(); }
};
class CallAtoi : public Xbyak::CodeGenerator {
@ -70,12 +70,12 @@ public:
#else
mov(eax, ptr [esp + 4]);
push(eax);
call((void*)atoi);
call(Xbyak::CastTo<void*>(atoi));
add(esp, 4);
#endif
ret();
}
int (*get() const)(const char *) { return (int (*)(const char *))(const void*)getCode(); }
int (*get() const)(const char *) { return getCode<int (*)(const char *)>(); }
};
class JmpAtoi : public Xbyak::CodeGenerator {
@ -88,10 +88,10 @@ public:
mov(rax, (size_t)atoi);
jmp(rax);
#else
jmp((void*)atoi);
jmp(Xbyak::CastTo<void*>(atoi));
#endif
}
int (*get() const)(const char *) { return (int (*)(const char *))(const void*)getCode(); }
int (*get() const)(const char *) { return getCode<int (*)(const char *)>(); }
};
struct Reset : public Xbyak::CodeGenerator {
@ -116,7 +116,7 @@ void testReset()
{
puts("testReset");
Reset code;
int (*f)(int) = (int (*)(int))code.getCode();
int (*f)(int) = code.getCode<int(*)(int)>();
for (int i = 0; i < 10; i++) {
code.init(i);
int v = f(i);
@ -137,7 +137,7 @@ int main()
#else
puts("32bit");
#endif
int (*func)(int) = (int (*)(int))(const void*)s.getCode();
int (*func)(int) = s.getCode<int (*)(int)>();
for (int i = 0; i <= 10; i++) {
printf("0 + ... + %d = %d\n", i, func(i));
}
@ -159,9 +159,9 @@ int main()
uint8 *p = CodeArray::getAlignedAddress(buf);
CodeArray::protect(p, codeSize, true);
Sample s(p, codeSize);
int (*func)(int) = (int (*)(int))(const void*)s.getCode();
if ((uint8*)func != p) {
fprintf(stderr, "internal error %p %p\n", p, func);
int (*func)(int) = s.getCode<int (*)(int)>();
if (Xbyak::CastTo<uint8*>(func) != p) {
fprintf(stderr, "internal error %p %p\n", p, Xbyak::CastTo<uint8*>(func));
return 1;
}
printf("0 + ... + %d = %d\n", 100, func(100));

View file

@ -50,7 +50,7 @@ void putCPUinfo()
if (cpu.has(Cpu::tPOPCNT)) {
const int n = 0x12345678; // bitcount = 13
const int ok = 13;
int r = ((int (*)())((const void*)PopCountTest(n).getCode()))();
int r = PopCountTest(n).getCode<int (*)()>()();
if (r == ok) {
puts("popcnt ok");
} else {
@ -71,7 +71,7 @@ struct EipTest : public Xbyak::CodeGenerator {
void putEip()
{
EipTest s;
int (*getEip)() = (int(*)())(const void*)s.getCode();
int (*getEip)() = s.getCode<int(*)()>();
printf("eip=%08x\n", getEip());
}
#endif

View file

@ -199,7 +199,7 @@ public:
push(reg[r]);
push('A' + r);
push((int)str);
call((void*)printf);
call(Xbyak::CastTo<void*>(printf));
add(esp, 4 * 4);
pop(ecx);
pop(edx);
@ -274,7 +274,7 @@ public:
}
void runByJIT()
{
((void (*)())(const void*)getCode())();
getCode<void (*)()>();
}
};

View file

@ -78,8 +78,9 @@ enum {
typedef unsigned __int64 uint64;
typedef __int64 sint64;
#else
typedef unsigned long long uint64;
typedef long long sint64;
#include <stdint.h>
typedef uint64_t uint64;
typedef int64_t sint64;
#endif
typedef unsigned int uint32;
typedef unsigned short uint16;
@ -183,13 +184,19 @@ inline void AlignedFree(void *p)
free(p);
#endif
}
template<class To, class From>
inline const To CastTo(From p) throw()
{
return (const To)(size_t)(p);
}
namespace inner {
enum { debug = 1 };
static const size_t ALIGN_PAGE_SIZE = 4096;
inline bool IsInDisp8(uint32 x) { return 0xFFFFFF80 <= x || x <= 0x7F; }
inline bool IsInInt32(uint64 x) { return 0xFFFFFFFF80000000ULL <= x || x <= 0x7FFFFFFFU; }
inline bool IsInInt32(uint64 x) { return ~uint64(0x7fffffffu) <= x || x <= 0x7FFFFFFFU; }
inline uint32 VerifyInInt32(uint64 x)
{
@ -572,7 +579,11 @@ public:
void dw(uint32 code) { db(code, 2); }
void dd(uint32 code) { db(code, 4); }
const uint8 *getCode() const { return top_; }
template<class F>
const F getCode() const { return CastTo<F>(top_); }
const uint8 *getCurr() const { return &top_[size_]; }
template<class F>
const F getCurr() const { return CastTo<F>(&top_[size_]); }
size_t getSize() const { return size_; }
void dump() const
{

View file

@ -233,25 +233,25 @@ self->L("@@");
int idx = out.getIdx();
switch (idx) {
case Xbyak::Operand::EAX:
self->call((void*)local::set_eip_to_eax);
self->call(CastTo<void*>(local::set_eip_to_eax));
break;
case Xbyak::Operand::ECX:
self->call((void*)local::set_eip_to_ecx);
self->call(CastTo<void*>(local::set_eip_to_ecx));
break;
case Xbyak::Operand::EDX:
self->call((void*)local::set_eip_to_edx);
self->call(CastTo<void*>(local::set_eip_to_edx));
break;
case Xbyak::Operand::EBX:
self->call((void*)local::set_eip_to_ebx);
self->call(CastTo<void*>(local::set_eip_to_ebx));
break;
case Xbyak::Operand::ESI:
self->call((void*)local::set_eip_to_esi);
self->call(CastTo<void*>(local::set_eip_to_esi));
break;
case Xbyak::Operand::EDI:
self->call((void*)local::set_eip_to_edi);
self->call(CastTo<void*>(local::set_eip_to_edi));
break;
case Xbyak::Operand::EBP:
self->call((void*)local::set_eip_to_ebp);
self->call(CastTo<void*>(local::set_eip_to_ebp));
break;
default:
assert(0);