OSDN Git Service

[llvm-rc] Handle C preprocessor output
authorMartin Storsjo <martin@martin.st>
Wed, 9 May 2018 18:21:03 +0000 (18:21 +0000)
committerMartin Storsjo <martin@martin.st>
Wed, 9 May 2018 18:21:03 +0000 (18:21 +0000)
commitd5e933640f83acfb16554ee4a5d5739e1c202f64
treec255fed035bd952c544594b59a8a6f6df5522b58
parent0aa38c8f714f3e6969242d8507db7da7fbd0a87e
[llvm-rc] Handle C preprocessor output

When preprocessing resource scripts (which can easily be done outside
of llvm-rc), included headers can leave behind C declarations (despite
preprocessing with -DRC_INVOKED), that can't be parsed by a resource
compiler.

This is handled in all of rc.exe, by parsing the preprocessor output
line markers and ignoring content from files named *.h and *.c,
documented at [1].

In addition to this filtering, strip out any other preprocessor directive
that is left behind (like pragmas) which also can't be handled by the
tokenizer.

The added test uses both standard #line markers (supported by rc.exe) and
GNU style extended line markers, thus this test doesn't pass with rc.exe,
but passes with GNU windres. (Windres on the other hand doesn't filter
out files named *.c, only *.h.)

Differential Revision: https://reviews.llvm.org/D46579

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa381033(v=vs.85).aspx

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331903 91177308-0d34-0410-b5e6-96231b3b80d8
test/tools/llvm-rc/Inputs/cpp-output.rc [new file with mode: 0644]
test/tools/llvm-rc/cpp-output.test [new file with mode: 0644]
tools/llvm-rc/CMakeLists.txt
tools/llvm-rc/ResourceScriptCppFilter.cpp [new file with mode: 0644]
tools/llvm-rc/ResourceScriptCppFilter.h [new file with mode: 0644]
tools/llvm-rc/llvm-rc.cpp