[clang] [C] Diagnose use of C++ keywords in C (PR #137234)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 25 04:28:53 PDT 2025


AaronBallman wrote:

Alas, I think this PR may be a non-starter due to performance: https://llvm-compile-time-tracker.com/?config=Overview&stat=wall-time&remote=AaronBallman:
```
C 		56a3f3cd28 	8.04s (+2.96%) 	8.23s (+3.32%) 	11.87s (+1.92%) 	2.83s (+10.21%) 	8.50s (+2.99%) 	3.22s (+7.82%) 	7.12s (+1.63%) 	2.43s (+5.91%) 	580.64s (+0.44%)
```
+10% compile time overhead is painful. I believe the issue is with needing to look at token *names* (doing a string compare in a loop across a pile of tokens on every identifier declares). But the token kind we have is `identifier` and not one of the keywords, so we can't do the more trivial integer comparisons. Even if we could, I suspect this would have a performance hit just due to the number of identifiers.

I'm going to try checking whether the diagnostic is enabled before doing the comparisons to see if that improves things. The diagnostic is off by default and only enabled under `-Wc++-compat`, so some amount of performance hit is reasonable given the need to avoid C++ keywords in C code.

https://github.com/llvm/llvm-project/pull/137234


More information about the cfe-commits mailing list