History

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.

Andrei Warkentin committed 9 years ago

Commit 63b2f901 parent 91cd14810 files · +17 −45Browse files

Unified · Split

10 files
  1. Makefile +1 −1
  2. arm-link.c +1 −1
  3. arm64-link.c +1 −1
  4. c67-link.c +1 −1
  5. i386-asm.c +5 −5
  6. i386-link.c +1 −1
  7. tcc.h +3 −2
  8. tccelf.c +1 −1
  9. tccpp.c +2 −31
  10. x86_64-link.c +1 −1
Makefile+1−1
@@ -69,7 +69,7 @@ else · 68 unmodified lines
69endif69endif
70 70
71ifeq ($(TARGETOS),Darwin)71ifeq ($(TARGETOS),Darwin)
72 CFLAGS += -Wl,-flat_namespace,-undefined,warning72 LDFLAGS += -flat_namespace -undefined warning
73 export MACOSX_DEPLOYMENT_TARGET:=10.273 export MACOSX_DEPLOYMENT_TARGET:=10.2
74endif74endif
75 75
arm-link.c+1−1
@@ -166,7 +166,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 165 unmodified lines
166 166
167void relocate_init(Section *sr) {}167void relocate_init(Section *sr) {}
168 168
169void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)169void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
170{170{
171 ElfW(Sym) *sym;171 ElfW(Sym) *sym;
172 int sym_index;172 int sym_index;
arm64-link.c+1−1
@@ -153,7 +153,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 152 unmodified lines
153 153
154void relocate_init(Section *sr) {}154void relocate_init(Section *sr) {}
155 155
156void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)156void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
157{157{
158 int sym_index = ELFW(R_SYM)(rel->r_info);158 int sym_index = ELFW(R_SYM)(rel->r_info);
159#ifdef DEBUG_RELOC159#ifdef DEBUG_RELOC
c67-link.c+1−1
@@ -96,7 +96,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 95 unmodified lines
96 96
97void relocate_init(Section *sr) {}97void relocate_init(Section *sr) {}
98 98
99void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)99void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
100{100{
101 switch(type) {101 switch(type) {
102 case R_C60_32:102 case R_C60_32:
i386-asm.c+5−5
@@ -221,7 +221,7 @@ static const uint8_t segment_prefixes[] = { · 220 unmodified lines
221static const ASMInstr asm_instrs[] = {221static const ASMInstr asm_instrs[] = {
222#define ALT(x) x222#define ALT(x) x
223/* This removes a 0x0f in the second byte */223/* This removes a 0x0f in the second byte */
224#define O(o) ((((o) & 0xff00) == 0x0f00) ? ((((o) >> 8) & ~0xff) | ((o) & 0xff)) : (o))224#define O(o) ((uint64_t) ((((o) & 0xff00) == 0x0f00) ? ((((o) >> 8) & ~0xff) | ((o) & 0xff)) : (o)))
225/* This constructs instr_type from opcode, type and group. */225/* This constructs instr_type from opcode, type and group. */
226#define T(o,i,g) ((i) | ((g) << OPC_GROUP_SHIFT) | ((((o) & 0xff00) == 0x0f00) ? OPC_0F : 0))226#define T(o,i,g) ((i) | ((g) << OPC_GROUP_SHIFT) | ((((o) & 0xff00) == 0x0f00) ? OPC_0F : 0))
227#define DEF_ASM_OP0(name, opcode)227#define DEF_ASM_OP0(name, opcode)
@@ -278,7 +278,7 @@ static inline int get_reg_shift(TCCState *s1) · 50 unmodified lines
278}278}
279 279
280#ifdef TCC_TARGET_X86_64280#ifdef TCC_TARGET_X86_64
281static int asm_parse_numeric_reg(int t, int *type)281static int asm_parse_numeric_reg(int t, unsigned int *type)
282{282{
283 int reg = -1;283 int reg = -1;
284 if (t >= TOK_IDENT && t < tok_ident) {284 if (t >= TOK_IDENT && t < tok_ident) {
@@ -317,7 +317,7 @@ static int asm_parse_numeric_reg(int t, int *type) · 32 unmodified lines
317}317}
318#endif318#endif
319 319
320static int asm_parse_reg(int *type)320static int asm_parse_reg(unsigned int *type)
321{321{
322 int reg = 0;322 int reg = 0;
323 *type = 0;323 *type = 0;
@@ -453,7 +453,7 @@ static void parse_operand(TCCState *s1, Operand *op) · 129 unmodified lines
453 op->e.pcrel = 0;453 op->e.pcrel = 0;
454 }454 }
455 if (tok == '(') {455 if (tok == '(') {
456 int type = 0;456 unsigned int type = 0;
457 next();457 next();
458 if (tok != ',') {458 if (tok != ',') {
459 op->reg = asm_parse_reg(&type);459 op->reg = asm_parse_reg(&type);
@@ -1688,7 +1688,7 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str) · 1228 unmodified lines
1688 int reg;1688 int reg;
1689 TokenSym *ts;1689 TokenSym *ts;
1690#ifdef TCC_TARGET_X86_641690#ifdef TCC_TARGET_X86_64
1691 int type;1691 unsigned int type;
1692#endif1692#endif
1693 1693
1694 if (!strcmp(str, "memory") ||1694 if (!strcmp(str, "memory") ||
i386-link.c+1−1
@@ -159,7 +159,7 @@ void relocate_init(Section *sr) · 158 unmodified lines
159 qrel = (ElfW_Rel *) sr->data;159 qrel = (ElfW_Rel *) sr->data;
160}160}
161 161
162void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)162void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
163{163{
164 int sym_index, esym_index;164 int sym_index, esym_index;
165 165
tcc.h+3−2
@@ -721,7 +721,8 @@ struct TCCState { · 720 unmodified lines
721 enum {721 enum {
722 LINE_MACRO_OUTPUT_FORMAT_GCC,722 LINE_MACRO_OUTPUT_FORMAT_GCC,
723 LINE_MACRO_OUTPUT_FORMAT_NONE,723 LINE_MACRO_OUTPUT_FORMAT_NONE,
724 LINE_MACRO_OUTPUT_FORMAT_STD724 LINE_MACRO_OUTPUT_FORMAT_STD,
725 LINE_MACRO_OUTPUT_FORMAT_P10 = 11
725 } Pflag; /* -P switch */726 } Pflag; /* -P switch */
726 char dflag; /* -dX value */727 char dflag; /* -dX value */
727 728
@@ -1446,7 +1447,7 @@ ST_FUNC int code_reloc (int reloc_type); · 718 unmodified lines
1446ST_FUNC int gotplt_entry_type (int reloc_type);1447ST_FUNC int gotplt_entry_type (int reloc_type);
1447ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);1448ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
1448ST_FUNC void relocate_init(Section *sr);1449ST_FUNC void relocate_init(Section *sr);
1449ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val);1450ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
1450ST_FUNC void relocate_plt(TCCState *s1);1451ST_FUNC void relocate_plt(TCCState *s1);
1451 1452
1452/* ------------ xxx-gen.c ------------ */1453/* ------------ xxx-gen.c ------------ */
tccelf.c+1−1
@@ -787,7 +787,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 786 unmodified lines
787 tgt += rel->r_addend;787 tgt += rel->r_addend;
788#endif788#endif
789 addr = s->sh_addr + rel->r_offset;789 addr = s->sh_addr + rel->r_offset;
790 relocate(s1, rel, type, ptr, addr, tgt);790 relocate(s1, rel, type, ptr, addr, tgt);
791 }791 }
792 /* if the relocation is allocated, we change its symbol table */792 /* if the relocation is allocated, we change its symbol table */
793 if (sr->sh_flags & SHF_ALLOC)793 if (sr->sh_flags & SHF_ALLOC)
tccpp.c+2−31
@@ -1021,35 +1021,6 @@ ST_FUNC void restore_parse_state(ParseState *s) · 1020 unmodified lines
1021 tokc = s->tokc;1021 tokc = s->tokc;
1022}1022}
1023 1023
1024/* return the number of additional 'ints' necessary to store the
1025 token */
1026static inline int tok_size(const int *p)
1027{
1028 switch(*p) {
1029 /* 4 bytes */
1030 case TOK_CINT:
1031 case TOK_CUINT:
1032 case TOK_CCHAR:
1033 case TOK_LCHAR:
1034 case TOK_CFLOAT:
1035 case TOK_LINENUM:
1036 return 1 + 1;
1037 case TOK_STR:
1038 case TOK_LSTR:
1039 case TOK_PPNUM:
1040 case TOK_PPSTR:
1041 return 1 + ((sizeof(CString) + ((CString *)(p+1))->size + 3) >> 2);
1042 case TOK_CDOUBLE:
1043 case TOK_CLLONG:
1044 case TOK_CULLONG:
1045 return 1 + 2;
1046 case TOK_CLDOUBLE:
1047 return 1 + LDOUBLE_SIZE / 4;
1048 default:
1049 return 1 + 0;
1050 }
1051}
1052
1053/* token string handling */1024/* token string handling */
1054 1025
1055ST_INLN void tok_str_new(TokenString *s)1026ST_INLN void tok_str_new(TokenString *s)
@@ -2615,7 +2586,7 @@ maybe_newline: · 1559 unmodified lines
2615 } else {2586 } else {
2616 /* slower case */2587 /* slower case */
2617 cstr_reset(&tokcstr);2588 cstr_reset(&tokcstr);
2618 cstr_cat(&tokcstr, p1, len);2589 cstr_cat(&tokcstr, (char *) p1, len);
2619 p--;2590 p--;
2620 PEEKC(c, p);2591 PEEKC(c, p);
2621 parse_ident_slow:2592 parse_ident_slow:
@@ -3732,7 +3703,7 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 1110 unmodified lines
3732 /* Credits to Fabrice Bellard's initial revision to demonstrate its3703 /* Credits to Fabrice Bellard's initial revision to demonstrate its
3733 capability to compile and run itself, provided all numbers are3704 capability to compile and run itself, provided all numbers are
3734 given as decimals. tcc -E -P10 will do. */3705 given as decimals. tcc -E -P10 will do. */
3735 if (s1->Pflag == 1 + 10)3706 if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_P10)
3736 parse_flags |= PARSE_FLAG_TOK_NUM, s1->Pflag = 1;3707 parse_flags |= PARSE_FLAG_TOK_NUM, s1->Pflag = 1;
3737 3708
3738#ifdef PP_BENCH3709#ifdef PP_BENCH
x86_64-link.c+1−1
@@ -157,7 +157,7 @@ void relocate_init(Section *sr) · 156 unmodified lines
157 qrel = (ElfW_Rel *) sr->data;157 qrel = (ElfW_Rel *) sr->data;
158}158}
159 159
160void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)160void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
161{161{
162 int sym_index, esym_index;162 int sym_index, esym_index;
163 163

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t