[Lex] Warn when defining or undefining any builtin macro
authorJohn Brawn <john.brawn@arm.com>
Mon, 23 Jan 2023 17:40:59 +0000 (17:40 +0000)
committerJohn Brawn <john.brawn@arm.com>
Wed, 17 May 2023 10:49:49 +0000 (11:49 +0100)
commit22e3f587fd1ff97185014cb1ba723579ed2150d3
tree77abae61a660e165f42ed9b498c38db9d573ebd9
parentcd87fe0c8be3c462f5c0bac745d740d0b5185562
[Lex] Warn when defining or undefining any builtin macro

Currently we warn when MI->isBuiltinMacro, but this is only true for
builtin macros that require processing when expanding. Checking
SourceMgr.isWrittenInBuiltinFile in addition to this will mean that
we catch all builtin macros, though we shouldn't warn on feature test
macros.

As part of doing this I've also moved the handling of undefining from
CheckMacroName to HandleUndefDirective, as it doesn't really make
sense to handle undefining in CheckMacroName but defining in
HandleDefineDirective. It would be nice to instead handle both in
CheckMacroName, but that isn't possible as the handling of defines
requires looking at what the name is being defined to.

Differential Revision: https://reviews.llvm.org/D144654
clang/docs/ReleaseNotes.rst
clang/lib/Lex/PPDirectives.cpp
clang/test/Lexer/builtin_redef.c
clang/test/Preprocessor/macro-reserved.c
clang/test/Preprocessor/macro-reserved.cpp