https://llvm.org/bugs/show_bug.cgi?id=31311
Bug ID: 31311 Summary: undef doesn't work well with pch files Product: clang Version: unspecified Hardware: PC OS: All Status: NEW Severity: normal Priority: P Component: Frontend Assignee: unassignedclangb...@nondot.org Reporter: nicolaswe...@gmx.de CC: llvm-bugs@lists.llvm.org Classification: Unclassified $ cat foo2.h #undef ARG $ cat foo2.c const int i = ARG; $ ./bin/clang -cc1 -DARG -include foo2.h foo2.c -emit-obj -o a.o foo2.c:1:15: error: use of undeclared identifier 'ARG' const int i = ARG; ^ 1 error generated. $ ./bin/clang -cc1 -emit-pch -o foo2.h.pch foo2.h $ ./bin/clang -cc1 -DARG -include-pch foo2.h.pch foo2.c -emit-obj -o a.o This should err when going through a pch as well. Similar but slightly more difficult to fix: The same with a builtin macro: $ cat foo2.h #undef __FILE__ $ cat foo2.c const char s[] = __FILE__; s$ bin/clang -cc1 -include foo2.h foo2.c -emit-obj -o a.o In file included from <built-in>:1: ./foo2.h:1:8: warning: undefining builtin macro #undef __FILE__ ^ foo2.c:1:18: error: use of undeclared identifier '__FILE__' const char s[] = __FILE__; ^ 1 warning and 1 error generated. $ ./bin/clang -cc1 -emit-pch -o foo2.h.pch foo2.h foo2.h:1:8: warning: undefining builtin macro #undef __FILE__ ^ 1 warning generated. $ ./bin/clang -cc1 -include-pch foo2.h.pch foo2.c -emit-obj -o a.o This too should error out but doesn't. Problems, partial list: 1. shouldIgnoreMacro() in ASTWriter.cpp stops at isBuiltinMacro(), but that's true for undefs of builtin macros as well. It probably should have `if (MD->getKind() != MacroDirective::MD_Define) return false;` as its first line. 2. ASTWriter only writes out identifiers with a ref (see AddIdentifierRef). ASTWriter::WritePreprocessor() only calls this for macros with a MacroInfo, and macros that are only #undef'd but never defined (at pch creation time) get dropped. 3. It seems that pch files get loaded before commandline -D flags are processed, and Preprocessor::HandleUndefDirective() ignores undefs for macros without a MacroInfo (which makes sense) (not really sure if the ordering here is like I say, but if it weren't then `#define FOO` in the .h and -DFOO on the command passing -include-pch would behave differently) (Spin-off from bug 29119) -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs