Skip to content

Commit

Permalink
Preprocessor: replace empty object macros with placemarker
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas authored and Vexu committed Dec 14, 2023
1 parent bbd836c commit 7c83431
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,10 @@ fn deinitMacroArguments(allocator: Allocator, args: *const MacroArguments) void
fn expandObjMacro(pp: *Preprocessor, simple_macro: *const Macro) Error!ExpandBuf {
var buf = ExpandBuf.init(pp.gpa);
errdefer buf.deinit();
if (simple_macro.tokens.len == 0) {
try buf.append(.{ .id = .placemarker, .loc = .{ .id = .generated } });
return buf;
}
try buf.ensureTotalCapacity(simple_macro.tokens.len);

// Add all of the simple_macros tokens to the new buffer handling any concats.
Expand Down Expand Up @@ -2298,6 +2302,10 @@ fn expandMacro(pp: *Preprocessor, tokenizer: *Tokenizer, raw: RawToken) MacroErr
Token.free(tok.expansion_locs, pp.gpa);
continue;
}
if (tok.id == .placemarker) {
Token.free(tok.expansion_locs, pp.gpa);
continue;
}
tok.id.simplifyMacroKeywordExtra(true);
pp.tokens.appendAssumeCapacity(tok.*);
}
Expand Down
8 changes: 8 additions & 0 deletions test/cases/empty macro block expansion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//aro-args -P -E
#define CONTINUE(k) DEFER(k##_HOOK)()
#define DEFER(op) op EMPTY
#define EMPTY
#define F_HOOK() F

CONTINUE( F)
CONTINUE(F)
2 changes: 2 additions & 0 deletions test/cases/expanded/empty macro block expansion.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
F_HOOK ()
F_HOOK ()

0 comments on commit 7c83431

Please sign in to comment.