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
6969 endif
7070
7171 ifeq ($(TARGETOS),Darwin)
72− CFLAGS += -Wl,-flat_namespace,-undefined,warning
72+ LDFLAGS += -flat_namespace -undefined warning
7373 export MACOSX_DEPLOYMENT_TARGET:=10.2
7474 endif
7575
arm-link.c+1−1
@@ -166,7 +166,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 165 unmodified lines
166166
167167 void relocate_init(Section *sr) {}
168168
169−void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
169+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
170170 {
171171 ElfW(Sym) *sym;
172172 int sym_index;
arm64-link.c+1−1
@@ -153,7 +153,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 152 unmodified lines
153153
154154 void relocate_init(Section *sr) {}
155155
156−void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
156+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
157157 {
158158 int sym_index = ELFW(R_SYM)(rel->r_info);
159159 #ifdef DEBUG_RELOC
c67-link.c+1−1
@@ -96,7 +96,7 @@ ST_FUNC void relocate_plt(TCCState *s1) · 95 unmodified lines
9696
9797 void relocate_init(Section *sr) {}
9898
99−void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
99+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
100100 {
101101 switch(type) {
102102 case R_C60_32:
i386-asm.c+5−5
@@ -221,7 +221,7 @@ static const uint8_t segment_prefixes[] = { · 220 unmodified lines
221221 static const ASMInstr asm_instrs[] = {
222222 #define ALT(x) x
223223 /* 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)))
225225 /* This constructs instr_type from opcode, type and group. */
226226 #define T(o,i,g) ((i) | ((g) << OPC_GROUP_SHIFT) | ((((o) & 0xff00) == 0x0f00) ? OPC_0F : 0))
227227 #define DEF_ASM_OP0(name, opcode)
@@ -278,7 +278,7 @@ static inline int get_reg_shift(TCCState *s1) · 50 unmodified lines
278278 }
279279
280280 #ifdef TCC_TARGET_X86_64
281−static int asm_parse_numeric_reg(int t, int *type)
281+static int asm_parse_numeric_reg(int t, unsigned int *type)
282282 {
283283 int reg = -1;
284284 if (t >= TOK_IDENT && t < tok_ident) {
@@ -317,7 +317,7 @@ static int asm_parse_numeric_reg(int t, int *type) · 32 unmodified lines
317317 }
318318 #endif
319319
320−static int asm_parse_reg(int *type)
320+static int asm_parse_reg(unsigned int *type)
321321 {
322322 int reg = 0;
323323 *type = 0;
@@ -453,7 +453,7 @@ static void parse_operand(TCCState *s1, Operand *op) · 129 unmodified lines
453453 op->e.pcrel = 0;
454454 }
455455 if (tok == '(') {
456− int type = 0;
456+ unsigned int type = 0;
457457 next();
458458 if (tok != ',') {
459459 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
16881688 int reg;
16891689 TokenSym *ts;
16901690 #ifdef TCC_TARGET_X86_64
1691− int type;
1691+ unsigned int type;
16921692 #endif
16931693
16941694 if (!strcmp(str, "memory") ||
i386-link.c+1−1
@@ -159,7 +159,7 @@ void relocate_init(Section *sr) · 158 unmodified lines
159159 qrel = (ElfW_Rel *) sr->data;
160160 }
161161
162−void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
162+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
163163 {
164164 int sym_index, esym_index;
165165
tcc.h+3−2
@@ -721,7 +721,8 @@ struct TCCState { · 720 unmodified lines
721721 enum {
722722 LINE_MACRO_OUTPUT_FORMAT_GCC,
723723 LINE_MACRO_OUTPUT_FORMAT_NONE,
724− LINE_MACRO_OUTPUT_FORMAT_STD
724+ LINE_MACRO_OUTPUT_FORMAT_STD,
725+ LINE_MACRO_OUTPUT_FORMAT_P10 = 11
725726 } Pflag; /* -P switch */
726727 char dflag; /* -dX value */
727728
@@ -1446,7 +1447,7 @@ ST_FUNC int code_reloc (int reloc_type); · 718 unmodified lines
14461447 ST_FUNC int gotplt_entry_type (int reloc_type);
14471448 ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
14481449 ST_FUNC void relocate_init(Section *sr);
1449−ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val);
1450+ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
14501451 ST_FUNC void relocate_plt(TCCState *s1);
14511452
14521453 /* ------------ xxx-gen.c ------------ */
tccelf.c+1−1
@@ -787,7 +787,7 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 786 unmodified lines
787787 tgt += rel->r_addend;
788788 #endif
789789 addr = s->sh_addr + rel->r_offset;
790− relocate(s1, rel, type, ptr, addr, tgt);
790+ relocate(s1, rel, type, ptr, addr, tgt);
791791 }
792792 /* if the relocation is allocated, we change its symbol table */
793793 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
10211021 tokc = s->tokc;
10221022 }
10231023
1024−/* return the number of additional 'ints' necessary to store the
1025− token */
1026−static 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−
10531024 /* token string handling */
10541025
10551026 ST_INLN void tok_str_new(TokenString *s)
@@ -2615,7 +2586,7 @@ maybe_newline: · 1559 unmodified lines
26152586 } else {
26162587 /* slower case */
26172588 cstr_reset(&tokcstr);
2618− cstr_cat(&tokcstr, p1, len);
2589+ cstr_cat(&tokcstr, (char *) p1, len);
26192590 p--;
26202591 PEEKC(c, p);
26212592 parse_ident_slow:
@@ -3732,7 +3703,7 @@ ST_FUNC int tcc_preprocess(TCCState *s1) · 1110 unmodified lines
37323703 /* Credits to Fabrice Bellard's initial revision to demonstrate its
37333704 capability to compile and run itself, provided all numbers are
37343705 given as decimals. tcc -E -P10 will do. */
3735− if (s1->Pflag == 1 + 10)
3706+ if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_P10)
37363707 parse_flags |= PARSE_FLAG_TOK_NUM, s1->Pflag = 1;
37373708
37383709 #ifdef PP_BENCH
x86_64-link.c+1−1
@@ -157,7 +157,7 @@ void relocate_init(Section *sr) · 156 unmodified lines
157157 qrel = (ElfW_Rel *) sr->data;
158158 }
159159
160−void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)
160+void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
161161 {
162162 int sym_index, esym_index;
163163

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