aboutsummaryrefslogtreecommitdiff
path: root/tccpp.c
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2016-10-31 03:59:31 +0100
committerMichael Matz <matz@suse.de>2016-12-15 17:49:56 +0100
commit3e77bfb6e9b286bbb53377fb5d7343e58ba34127 (patch)
treef8798307b10322c629c01217dafb36b3ab013a84 /tccpp.c
parent3db037387c16c7e582f76167d32d5c29ac32fb15 (diff)
downloadtinycc-3e77bfb6e9b286bbb53377fb5d7343e58ba34127.tar.gz
tinycc-3e77bfb6e9b286bbb53377fb5d7343e58ba34127.tar.bz2
tccpp: Fix token pasting
See testcase. We must always paste tokens (at least if not currently substing a normal argument, which is a speed optimization only now) but at the same time must not regard a ## token coming from argument expansion as the token-paste operator, nor if we constructed a ## token due to pasting itself (that was already checked by pp/01.c).
Diffstat (limited to 'tccpp.c')
-rw-r--r--tccpp.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/tccpp.c b/tccpp.c
index 04d5722..6659812 100644
--- a/tccpp.c
+++ b/tccpp.c
@@ -1508,6 +1508,7 @@ ST_FUNC void parse_define(void)
if (1 == spc)
--tokstr_buf.len;
spc = 3;
+ tok = TOK_PPJOIN;
} else if ('#' == tok) {
spc = 4;
} else if (check_space(tok, &spc)) {
@@ -2958,10 +2959,10 @@ static int *macro_arg_subst(Sym **nested_list, const int *macro_str, Sym *args)
int l0 = str.len;
st = s->d;
/* if '##' is present before or after, no arg substitution */
- if (*macro_str == TOK_TWOSHARPS || t1 == TOK_TWOSHARPS) {
+ if (*macro_str == TOK_PPJOIN || t1 == TOK_PPJOIN) {
/* special case for var arg macros : ## eats the ','
if empty VA_ARGS variable. */
- if (t1 == TOK_TWOSHARPS && t0 == ',' && gnu_ext && s->type.t) {
+ if (t1 == TOK_PPJOIN && t0 == ',' && gnu_ext && s->type.t) {
if (*st == 0) {
/* suppress ',' '##' */
str.len -= 2;
@@ -3277,7 +3278,7 @@ static inline int *macro_twosharps(const int *ptr0)
/* we search the first '##' */
for (ptr = ptr0;;) {
TOK_GET(&t, &ptr, &cval);
- if (t == TOK_TWOSHARPS)
+ if (t == TOK_PPJOIN)
break;
if (t == 0)
return NULL;
@@ -3290,9 +3291,9 @@ static inline int *macro_twosharps(const int *ptr0)
TOK_GET(&t, &ptr, &cval);
if (t == 0)
break;
- if (t == TOK_TWOSHARPS)
+ if (t == TOK_PPJOIN)
continue;
- while (*ptr == TOK_TWOSHARPS) {
+ while (*ptr == TOK_PPJOIN) {
int t1; CValue cv1;
/* given 'a##b', remove nosubsts preceding 'a' */
if (start_of_nosubsts >= 0)
@@ -3300,7 +3301,7 @@ static inline int *macro_twosharps(const int *ptr0)
/* given 'a##b', remove nosubsts preceding 'b' */
while ((t1 = *++ptr) == TOK_NOSUBST)
;
- if (t1 && t1 != TOK_TWOSHARPS) {
+ if (t1 && t1 != TOK_PPJOIN) {
TOK_GET(&t1, &ptr, &cv1);
if (t != TOK_PLCHLDR || t1 != TOK_PLCHLDR) {
if (paste_tokens(t, &cval, t1, &cv1)) {
@@ -3346,7 +3347,7 @@ static void macro_subst(
spc = nosubst = 0;
/* first scan for '##' operator handling */
- if (can_read_stream & 1) {
+ if (can_read_stream) {
macro_str1 = macro_twosharps(ptr);
if (macro_str1)
ptr = macro_str1;