History

feat: treat unknown macros with arguments as undefined

Jonathan M. Wilbur committed 2 years ago

Commit c85efac1 parent 08a4c522 files · +27 −0Browse files

Unified · Split

2 files
  1. tccpp.c +14 −0
  2. tests/undef_func_macro.c +13 −0
tccpp.c+14−0
@@ -1506,6 +1506,20 @@ static int expr_preprocess(TCCState *s1) · 1505 unmodified lines
1506 tokc.i = c;1506 tokc.i = c;
1507 } else {1507 } else {
1508 /* if undefined macro, replace with zero */1508 /* if undefined macro, replace with zero */
1509 next_nomacro();
1510 // If the undefined macro is followed by parens, just skip them.
1511 if (tok == '(') {
1512 int bracket_depth = 1;
1513 while (bracket_depth > 0) {
1514 next();
1515 if (tok == '(')
1516 bracket_depth++;
1517 else if (tok == ')')
1518 bracket_depth--;
1519 }
1520 } else {
1521 unget_tok(tok); // Is this actually the function I want?
1522 }
1509 tok = TOK_CINT;1523 tok = TOK_CINT;
1510 tokc.i = 0;1524 tokc.i = 0;
1511 }1525 }
tests/undef_func_macro.c+13−0
@@ -0,0 +1,13 @@
1int main () {
2// This used to evaluate to 0 (0), which is invalid.
3// Now it should evaluate to 0.
4#if WUMBOED(WUMBO)
5#endif
6
7// Just trying a more complicated test case.
8#if WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY
9 return 0;
10#elif WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY
11 return 1;
12#endif
13}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t