Description
We need to diagnose the macro in commands too. For example, the expected result of clang++ -Wreserved-identifier -D__WHY_NOT_ME__ -U__STDC__ tmp.cpp should be
<command line>:1:9: warning: macro name is a reserved identifier [-Wreserved-macro-identifier] #define __WHY_NOT_ME__ 1 ^ <command line>:2:8: warning: macro name is a reserved identifier [-Wreserved-macro-identifier] #undef __STDC__ ^
Currently, clang will not show any warning message when we define or undefine reserved macro in commands.
Fix
We use digital directives in the preprocessor, like
# 1 "<built-in>" 3 #define __llvm__ 1 #define __clang__ 1 ... # 1 "<command line>" 1 #define __WHY_NOT_ME__ 1 #undef __STDC__ #define __GCC_HAVE_DWARF2_CFI_ASM 1 # 1 "<built-in>" 2
I think we should use PresumedLoc to determine its <built-in> or <command line> section. In this case, the file name will be changed from <built-in> to <command line>. However, SourceMgr.getBufferName only returns the first name it matches.
Another issue is that clang will define __GCC_HAVE_DWARF2_CFI_ASM in the command line. But I don't know how to handle this macro. I only add this macro to the reserved macro list.
Make this CC1 only option NoDriverOption by moving it somewhere under let Flags = [CC1Option, NoDriverOption] in {
Don't add new Separate or JoinedOrSeparate options. They are legacy.