From 25a31eba007161bcf751df7da503ab91ba8a1a78 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 14 Apr 2025 17:14:31 +0200 Subject: [PATCH] macro: Fixed macro expansion bug It was not possible for macros to expand defines correctly when a comment was preceeding the expansion. This was caused by the comment_seen flag that instructs the preprocessor to skip tokens in commnets. This flag is now unset when a new line (\n) is encountered. --- .clang-tidy | 3 ++- src/ulas.c | 6 ++++++ tests/t0.s | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 42c3dd0..ecc59c3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -29,7 +29,8 @@ Checks: "*, -readability-uppercase-literal-suffix, -hicpp-function-size, -readability-function-size, - -cert-env33-c + -cert-env33-c, + -cppcoreguidelines-macro-to-enum " WarningsAsErrors: '' HeaderFilterRegex: '' diff --git a/src/ulas.c b/src/ulas.c index 1f8d8a7..3e7d92e 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -878,6 +878,12 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line, // only expand macros if they match toks[0] though! // otherwise memcpy the read bytes 1:1 into the new string while ((read = ulas_tok(&pp->tok, &praw_line, *n))) { + // remove comment seen if raw line + // starts a new line + // this fixes expnasion in macros containing comments + if (*praw_line == '\n') { + comment_seen = 0; + } struct ulas_ppdef *def = ulas_preprocgetdef(pp, pp->tok.buf, pp->tok.maxlen); diff --git a/tests/t0.s b/tests/t0.s index 89c6143..04c14b8 100644 --- a/tests/t0.s +++ b/tests/t0.s @@ -204,9 +204,11 @@ test_scoped: .def int arg_p = 2 -#macro defarg2 +#macro defarg2 + ; test .db $1 + 1, $2 .db $1 #endmacro defarg2 DEFARG * arg_p, arg_p + -- 2.30.2