Skip to content

Commit

Permalink
a nested macro expansion, additional case
Browse files Browse the repository at this point in the history
    fixed segfaul for the case
    #define A B;
    #define B A
    return A + B;

    But fix is not perfect. tcc and gcc outputs differs for
    #define A B + 1;
    #define B A
    return A + B;
  • Loading branch information
seyko2 committed Apr 29, 2016
1 parent bc60d94 commit ddeed8d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tccpp.c
Expand Up @@ -3702,11 +3702,17 @@ static void macro_subst(

/* if nested substitution, do nothing */
s2 = sym_find2(*nested_list, t);
if (s2 && s2->c) {
/* and mark it as TOK_NOSUBST, so it doesn't get subst'd again */
tok_str_add2(tok_str, TOK_NOSUBST, NULL);
goto no_subst;
if (s2) {
if (s2->c || s->asm_label) {
/* and mark it as TOK_NOSUBST, so it doesn't get subst'd again */
s->asm_label = 0;
tok_str_add2(tok_str, TOK_NOSUBST, NULL);
goto no_subst;
}
s->asm_label++;
}
else
s->asm_label = 0;

{
TokenString str;
Expand Down
14 changes: 14 additions & 0 deletions tests/pp/15.c
@@ -1,3 +1,17 @@
#define Y(x) Z(x)
#define X Y
X(X(1))

#define A B
#define B A
return A + B;

#if 0
#undef A
#undef B

#define A 1 + B
#define B A
return A + B;
// currently output of the gcc and tcc differs
#endif
1 change: 1 addition & 0 deletions tests/pp/15.expect
@@ -1 +1,2 @@
Z(Z(1))
return A + B;

0 comments on commit ddeed8d

Please sign in to comment.