[llvm-bugs] [Bug 31311] New: undef doesn't work well with pch files
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Dec 7 13:36:27 PST 2016
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: unassignedclangbugs at nondot.org
Reporter: nicolasweber at gmx.de
CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161207/1887d212/attachment.html>
More information about the llvm-bugs
mailing list