Skip to content

Commit

Permalink
Preprocessor: error instead of assert if include directive has no tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas authored and Vexu committed Apr 19, 2024
1 parent 0d3a51d commit 94c3ee9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,14 @@ fn stringify(pp: *Preprocessor, tokens: []const TokenWithExpansionLocs) !void {
}

fn reconstructIncludeString(pp: *Preprocessor, param_toks: []const TokenWithExpansionLocs, embed_args: ?*[]const TokenWithExpansionLocs, first: TokenWithExpansionLocs) !?[]const u8 {
assert(param_toks.len != 0);
if (param_toks.len == 0) {
try pp.comp.addDiagnostic(.{
.tag = .expected_filename,
.loc = first.loc,
}, first.expansionSlice());
return null;
}

const char_top = pp.char_buf.items.len;
defer pp.char_buf.items.len = char_top;

Expand Down
4 changes: 4 additions & 0 deletions test/cases/include pragma.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include _Pragma("once")

#define EXPECTED_ERRORS "include pragma.c:1:10: error: expected \"FILENAME\" or <FILENAME>" \

0 comments on commit 94c3ee9

Please sign in to comment.