aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
author lemon<lsof@mailbox.org>2025-10-23 16:43:45 +0200
committer lemon<lsof@mailbox.org>2025-10-23 16:43:45 +0200
commit542412a0d3b7a0a3abab00fed3bb4f209f0808f6 (patch)
tree5ffa1d4f0b5cd7a20dd2a7144c3a46aa647ce461
parent84b0c410b43decf53caa2ceb2595b14871a243b1 (diff)
lex: fix consecutive preprocessor concatenation
-rw-r--r--c/lex.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/c/lex.c b/c/lex.c
index ec0b4d2..4b41483 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -44,6 +44,7 @@ identkeyword(struct token *tk, const char *s, int len)
/* allow future keywords but only if they begin with _ */
tk->t = kwtab[i].t;
tk->s = kwtab[i].s;
+ tk->len = strlen(tk->s);
return kwtab[i].cstd <= ccopt.cstd;
} else break;
}
@@ -1082,7 +1083,8 @@ expandfnmacro(struct lexer *lx, struct span *span, struct macro *mac)
tk = mac->rlist.tk[i];
if (tk.t == TKPPCAT) {
if (i > 0 && i < mac->rlist.n-1) {
- const struct token *lhs = &mac->rlist.tk[i-1], *rhs = &mac->rlist.tk[i+1];
+ const struct token *lhs = rlist2.n ? &rlist2.p[rlist2.n-1] : &mac->rlist.tk[i-1],
+ *rhs = &mac->rlist.tk[i+1];
struct token new;
if (lhs->t != TKPPMACARG && rhs->t != TKPPMACARG) {
/* trivial case should have been handled when defining */
@@ -1115,13 +1117,14 @@ expandfnmacro(struct lexer *lx, struct span *span, struct macro *mac)
struct macrostack *l;
lhsargpaste = i < mac->rlist.n-1 && mac->rlist.tk[i+1].t == TKPPCAT;
if (arg->n == 0) {
- if (lhsargpaste) {
- lhsargforpaste.t = 0;
- lhsargforpaste.span = tk.span;
- }
if (rhsargpaste) {
rhsargpaste = 0;
- vpush(&rlist2, lhsargforpaste);
+ if (!lhsargpaste && lhsargforpaste.t) {
+ vpush(&rlist2, lhsargforpaste);
+ }
+ } else if (lhsargpaste) {
+ lhsargforpaste.t = 0;
+ lhsargforpaste.span = tk.span;
}
continue;
}
@@ -1197,7 +1200,7 @@ advancemacro(struct lexer *lx, struct token *tk)
struct rlist rl;
assert(lx->macstk);
rl = lx->macstk->rlist;
- if (lx->macstk->idx == rl.n) {
+ if (lx->macstk->idx >= rl.n) {
if (lx->macstk->stop) {
tk->t = TKEOF;
return 1;