[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 06:53:12 PDT 2025


AaronBallman wrote:

> > > But the token kind we have is `identifier` and not one of the keywords, so we can't do the more trivial integer comparisons.
> > 
> > 
> > Can we precompute a list/map/whatever of all identifiers that are keywords in C++ but not in C and then do pointer comparisons on the `IdentifierInfo*` maybe? At least then we wouldn’t have to do actual string comparisons; that said, I’m not sure that’s going to be that much better...
> 
> That's a pretty good idea, let me try that. I'll back out the changes that disable checking when the diagnostic isn't enabled so we get a better comparison.

That idea clawed back most of the performance:
```
Initial slow-down: 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%)
New approach: C 		07e44e05f8 	7.80s (-2.85%) 	8.03s (-2.86%) 	11.63s (-1.57%) 	2.57s (-8.93%) 	8.25s (-2.60%) 	2.97s (-7.09%) 	7.06s (-1.02%) 	2.33s (-3.10%) 	580.01s (+0.01%)
```

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


More information about the cfe-commits mailing list