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
15061506 tokc.i = c;
15071507 } else {
15081508 /* 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+ }
15091523 tok = TOK_CINT;
15101524 tokc.i = 0;
15111525 }
tests/undef_func_macro.c+13−0
@@ -0,0 +1,13 @@
1+int 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