tcc: fixup clang warnings

The O(xxx) stuff in i386-asm.c had me scratching my head. Extracting
the macro and trying it out in a separate program doesn't give
me any warnings, so I'm confused about what could be going on there.
Any cast will make things happy. I used a uint64_t to catch actual
cases of overflow, which will still cause a -Wconstant-conversion
warning.

Signed-off-by: Andrei Warkentin <andrey.warkentin@gmail.com>
master
Andrei Warkentin 2017-03-28 02:51:39 -04:00 committed by Andrei Warkentin
parent 91cd148a05
commit 63b2f907bd
10 changed files with 17 additions and 45 deletions

View File

@ -69,7 +69,7 @@ else
endif
ifeq ($(TARGETOS),Darwin)
CFLAGS += -Wl,-flat_namespace,-undefined,warning
LDFLAGS += -flat_namespace -undefined warning
export MACOSX_DEPLOYMENT_TARGET:=10.2
endif

View File

@ -166,7 +166,7 @@ ST_FUNC void relocate_plt(TCCState *s1)
void relocate_init(Section *sr) {}
void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
ElfW(Sym) *sym;
int sym_index;

View File

@ -153,7 +153,7 @@ ST_FUNC void relocate_plt(TCCState *s1)
void relocate_init(Section *sr) {}
void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
int sym_index = ELFW(R_SYM)(rel->r_info);
#ifdef DEBUG_RELOC

View File

@ -96,7 +96,7 @@ ST_FUNC void relocate_plt(TCCState *s1)
void relocate_init(Section *sr) {}
void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
switch(type) {
case R_C60_32:

View File

@ -221,7 +221,7 @@ static const uint8_t segment_prefixes[] = {
static const ASMInstr asm_instrs[] = {
#define ALT(x) x
/* This removes a 0x0f in the second byte */
#define O(o) ((((o) & 0xff00) == 0x0f00) ? ((((o) >> 8) & ~0xff) | ((o) & 0xff)) : (o))
#define O(o) ((uint64_t) ((((o) & 0xff00) == 0x0f00) ? ((((o) >> 8) & ~0xff) | ((o) & 0xff)) : (o)))
/* This constructs instr_type from opcode, type and group. */
#define T(o,i,g) ((i) | ((g) << OPC_GROUP_SHIFT) | ((((o) & 0xff00) == 0x0f00) ? OPC_0F : 0))
#define DEF_ASM_OP0(name, opcode)
@ -278,7 +278,7 @@ static inline int get_reg_shift(TCCState *s1)
}
#ifdef TCC_TARGET_X86_64
static int asm_parse_numeric_reg(int t, int *type)
static int asm_parse_numeric_reg(int t, unsigned int *type)
{
int reg = -1;
if (t >= TOK_IDENT && t < tok_ident) {
@ -317,7 +317,7 @@ static int asm_parse_numeric_reg(int t, int *type)
}
#endif
static int asm_parse_reg(int *type)
static int asm_parse_reg(unsigned int *type)
{
int reg = 0;
*type = 0;
@ -453,7 +453,7 @@ static void parse_operand(TCCState *s1, Operand *op)
op->e.pcrel = 0;
}
if (tok == '(') {
int type = 0;
unsigned int type = 0;
next();
if (tok != ',') {
op->reg = asm_parse_reg(&type);
@ -1688,7 +1688,7 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
int reg;
TokenSym *ts;
#ifdef TCC_TARGET_X86_64
int type;
unsigned int type;
#endif
if (!strcmp(str, "memory") ||

View File

@ -159,7 +159,7 @@ void relocate_init(Section *sr)
qrel = (ElfW_Rel *) sr->data;
}
void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
int sym_index, esym_index;

5
tcc.h
View File

@ -721,7 +721,8 @@ struct TCCState {
enum {
LINE_MACRO_OUTPUT_FORMAT_GCC,
LINE_MACRO_OUTPUT_FORMAT_NONE,
LINE_MACRO_OUTPUT_FORMAT_STD
LINE_MACRO_OUTPUT_FORMAT_STD,
LINE_MACRO_OUTPUT_FORMAT_P10 = 11
} Pflag; /* -P switch */
char dflag; /* -dX value */
@ -1446,7 +1447,7 @@ ST_FUNC int code_reloc (int reloc_type);
ST_FUNC int gotplt_entry_type (int reloc_type);
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
ST_FUNC void relocate_init(Section *sr);
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val);
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
ST_FUNC void relocate_plt(TCCState *s1);
/* ------------ xxx-gen.c ------------ */

View File

@ -787,7 +787,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
tgt += rel->r_addend;
#endif
addr = s->sh_addr + rel->r_offset;
relocate(s1, rel, type, ptr, addr, tgt);
relocate(s1, rel, type, ptr, addr, tgt);
}
/* if the relocation is allocated, we change its symbol table */
if (sr->sh_flags & SHF_ALLOC)

33
tccpp.c
View File

@ -1021,35 +1021,6 @@ ST_FUNC void restore_parse_state(ParseState *s)
tokc = s->tokc;
}
/* return the number of additional 'ints' necessary to store the
token */
static inline int tok_size(const int *p)
{
switch(*p) {
/* 4 bytes */
case TOK_CINT:
case TOK_CUINT:
case TOK_CCHAR:
case TOK_LCHAR:
case TOK_CFLOAT:
case TOK_LINENUM:
return 1 + 1;
case TOK_STR:
case TOK_LSTR:
case TOK_PPNUM:
case TOK_PPSTR:
return 1 + ((sizeof(CString) + ((CString *)(p+1))->size + 3) >> 2);
case TOK_CDOUBLE:
case TOK_CLLONG:
case TOK_CULLONG:
return 1 + 2;
case TOK_CLDOUBLE:
return 1 + LDOUBLE_SIZE / 4;
default:
return 1 + 0;
}
}
/* token string handling */
ST_INLN void tok_str_new(TokenString *s)
@ -2615,7 +2586,7 @@ maybe_newline:
} else {
/* slower case */
cstr_reset(&tokcstr);
cstr_cat(&tokcstr, p1, len);
cstr_cat(&tokcstr, (char *) p1, len);
p--;
PEEKC(c, p);
parse_ident_slow:
@ -3732,7 +3703,7 @@ ST_FUNC int tcc_preprocess(TCCState *s1)
/* Credits to Fabrice Bellard's initial revision to demonstrate its
capability to compile and run itself, provided all numbers are
given as decimals. tcc -E -P10 will do. */
if (s1->Pflag == 1 + 10)
if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_P10)
parse_flags |= PARSE_FLAG_TOK_NUM, s1->Pflag = 1;
#ifdef PP_BENCH

View File

@ -157,7 +157,7 @@ void relocate_init(Section *sr)
qrel = (ElfW_Rel *) sr->data;
}
void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{
int sym_index, esym_index;