Skip to content

Commit

Permalink
tccpp: tcc_warning("extra tokens after directive")
Browse files Browse the repository at this point in the history
with stuff like
    #endif int x;
Also fix
    /* */ #else
Also:
- search_cached_include(): search for file->true_filename
- tccasm.c: avoid crash with .file
  • Loading branch information
grischka committed Jun 11, 2024
1 parent 6b78e56 commit 08a4c52
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 67 deletions.
6 changes: 4 additions & 2 deletions tcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ typedef union CValue {
float f;
uint64_t i;
struct {
const void *data;
char *data;
int size;
} str;
int tab[LDOUBLE_SIZE/4];
Expand Down Expand Up @@ -1390,13 +1390,15 @@ ST_FUNC void define_undef(Sym *s);
ST_INLN Sym *define_find(int v);
ST_FUNC void free_defines(Sym *b);
ST_FUNC void parse_define(void);
ST_FUNC void skip_to_eol(int warn);
ST_FUNC void preprocess(int is_bof);
ST_FUNC void next(void);
ST_INLN void unget_tok(int last_tok);
ST_FUNC void preprocess_start(TCCState *s1, int filetype);
ST_FUNC void preprocess_end(TCCState *s1);
ST_FUNC void tccpp_new(TCCState *s);
ST_FUNC void tccpp_delete(TCCState *s);
ST_FUNC void tccpp_putfile(const char *filename);
ST_FUNC int tcc_preprocess(TCCState *s1);
ST_FUNC void skip(int c);
ST_FUNC NORETURN void expect(const char *msg);
Expand Down Expand Up @@ -1822,7 +1824,7 @@ ST_FUNC void tcc_debug_start(TCCState *s1);
ST_FUNC void tcc_debug_end(TCCState *s1);
ST_FUNC void tcc_debug_bincl(TCCState *s1);
ST_FUNC void tcc_debug_eincl(TCCState *s1);
ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename);
ST_FUNC void tcc_debug_newfile(TCCState *s1);

ST_FUNC void tcc_debug_line(TCCState *s1);
ST_FUNC void tcc_add_debug_info(TCCState *s1, int param, Sym *s, Sym *e);
Expand Down
30 changes: 18 additions & 12 deletions tccasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ static void asm_parse_directive(TCCState *s1, int global)
case TOK_ASMDIR_ascii:
case TOK_ASMDIR_asciz:
{
const uint8_t *p;
const char *p;
int i, size, t;

t = tok;
Expand Down Expand Up @@ -772,15 +772,21 @@ static void asm_parse_directive(TCCState *s1, int global)
break;
case TOK_ASMDIR_file:
{
char filename[512];

filename[0] = '\0';
const char *p;
parse_flags &= ~PARSE_FLAG_TOK_STR;
next();
if (tok == TOK_STR)
pstrcat(filename, sizeof(filename), tokc.str.data);
else
pstrcat(filename, sizeof(filename), get_tok_str(tok, NULL));
tcc_warning_c(warn_unsupported)("ignoring .file %s", filename);
if (tok == TOK_PPNUM)
next();
if (tok == TOK_PPSTR && tokc.str.data[0] == '"') {
tokc.str.data[tokc.str.size - 2] = 0;
p = tokc.str.data + 1;
} else if (tok >= TOK_IDENT) {
p = get_tok_str(tok, &tokc);
} else {
skip_to_eol(0);
break;
}
tccpp_putfile(p);
next();
}
break;
Expand Down Expand Up @@ -968,6 +974,7 @@ static int tcc_assemble_internal(TCCState *s1, int do_preprocess, int global)
next();
if (tok == TOK_EOF)
break;
tcc_debug_line(s1);
parse_flags |= PARSE_FLAG_LINEFEED; /* XXX: suppress that hack */
redo:
if (tok == '#') {
Expand Down Expand Up @@ -1033,9 +1040,8 @@ ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess)
/* GCC inline asm support */

/* assemble the string 'str' in the current C compilation unit without
C preprocessing. NOTE: str is modified by modifying the '\0' at the
end */
static void tcc_assemble_inline(TCCState *s1, char *str, int len, int global)
C preprocessing. */
static void tcc_assemble_inline(TCCState *s1, const char *str, int len, int global)
{
const int *saved_macro_ptr = macro_ptr;
int dotid = set_idnum('.', IS_ID);
Expand Down
5 changes: 1 addition & 4 deletions tccdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,8 @@ static BufferedFile* put_new_file(TCCState *s1)
}

/* put alternative filename */
ST_FUNC void tcc_debug_putfile(TCCState *s1, const char *filename)
ST_FUNC void tcc_debug_newfile(TCCState *s1)
{
if (0 == strcmp(file->filename, filename))
return;
pstrcpy(file->filename, sizeof(file->filename), filename);
if (!s1->do_debug)
return;
if (s1->dwarf)
Expand Down
2 changes: 1 addition & 1 deletion tccgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -8387,7 +8387,7 @@ static void gen_inline_functions(TCCState *s)
/* the function was used or forced (and then not internal):
generate its code and convert it to a normal function */
fn->sym = NULL;
tcc_debug_putfile(s, fn->filename);
tccpp_putfile(fn->filename);
begin_macro(fn->func_str, 1);
next();
cur_text_section = text_section;
Expand Down
Loading

0 comments on commit 08a4c52

Please sign in to comment.