summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2021-04-14 16:24:30 +0300
committerMartin Storsjö <martin@martin.st>2021-04-21 11:50:10 +0300
commit64bc44f5ddfb6da4b6a8b51ea9a03f8772b3ae95 (patch)
treeeb60984d8a593b3784e9c5a83f63533888de2d09
parentee34ca34c6675531c0d86709ebf99beef2ee7db1 (diff)
downloadllvm-64bc44f5ddfb6da4b6a8b51ea9a03f8772b3ae95.tar.gz
[llvm-rc] Run clang to preprocess input files
Allow opting out from preprocessing with a command line argument. Update tests to pass -no-preprocess to make it not try to use clang (which isn't a build level dependency of llvm-rc), but add a test that does preprocessing under clang/test/Preprocessor. Update a few options to allow them both joined (as -DFOO) and separate (-D BR), as rc.exe allows both forms of them. With the verbose flag set, this prints the preprocessing command used (which differs from what rc.exe does). Tests under llvm/test/tools/llvm-rc only test constructing the preprocessor commands, while tests under clang/test/Preprocessor test actually running the preprocessor. Differential Revision: https://reviews.llvm.org/D100755
-rw-r--r--clang/test/CMakeLists.txt1
-rw-r--r--clang/test/Preprocessor/Inputs/llvm-rc.h7
-rw-r--r--clang/test/Preprocessor/llvm-rc.rc8
-rw-r--r--clang/test/lit.cfg.py2
-rw-r--r--llvm/test/tools/llvm-rc/absolute.test4
-rw-r--r--llvm/test/tools/llvm-rc/codepage.test6
-rw-r--r--llvm/test/tools/llvm-rc/cpp-output.test2
-rw-r--r--llvm/test/tools/llvm-rc/flags.test4
-rw-r--r--llvm/test/tools/llvm-rc/helpmsg.test1
-rw-r--r--llvm/test/tools/llvm-rc/include-paths.test14
-rw-r--r--llvm/test/tools/llvm-rc/language.test4
-rw-r--r--llvm/test/tools/llvm-rc/memoryflags-stringtable.test2
-rw-r--r--llvm/test/tools/llvm-rc/memoryflags.test2
-rw-r--r--llvm/test/tools/llvm-rc/not-expr.test2
-rw-r--r--llvm/test/tools/llvm-rc/parser-expr.test16
-rw-r--r--llvm/test/tools/llvm-rc/parser.test64
-rw-r--r--llvm/test/tools/llvm-rc/preproc.test3
-rw-r--r--llvm/test/tools/llvm-rc/tag-accelerators.test28
-rw-r--r--llvm/test/tools/llvm-rc/tag-dialog.test26
-rw-r--r--llvm/test/tools/llvm-rc/tag-escape.test2
-rw-r--r--llvm/test/tools/llvm-rc/tag-html.test2
-rw-r--r--llvm/test/tools/llvm-rc/tag-icon-cursor.test6
-rw-r--r--llvm/test/tools/llvm-rc/tag-menu.test8
-rw-r--r--llvm/test/tools/llvm-rc/tag-stringtable.test6
-rw-r--r--llvm/test/tools/llvm-rc/tag-user.test2
-rw-r--r--llvm/test/tools/llvm-rc/tag-versioninfo.test6
-rw-r--r--llvm/test/tools/llvm-rc/tokenizer.test2
-rw-r--r--llvm/test/tools/llvm-rc/versioninfo-padding.test2
-rw-r--r--llvm/tools/llvm-rc/Opts.td15
-rw-r--r--llvm/tools/llvm-rc/llvm-rc.cpp117
30 files changed, 253 insertions, 111 deletions
diff --git a/clang/test/CMakeLists.txt b/clang/test/CMakeLists.txt
index 562a14826033..1325a0308d69 100644
--- a/clang/test/CMakeLists.txt
+++ b/clang/test/CMakeLists.txt
@@ -120,6 +120,7 @@ if( NOT CLANG_BUILT_STANDALONE )
llvm-objcopy
llvm-objdump
llvm-profdata
+ llvm-rc
llvm-readelf
llvm-readobj
llvm-strip
diff --git a/clang/test/Preprocessor/Inputs/llvm-rc.h b/clang/test/Preprocessor/Inputs/llvm-rc.h
new file mode 100644
index 000000000000..dcc91c20961c
--- /dev/null
+++ b/clang/test/Preprocessor/Inputs/llvm-rc.h
@@ -0,0 +1,7 @@
+#ifndef RC_INVOKED
+#error RC_INVOKED not defined
+#endif
+#ifndef _WIN32
+#error _WIN32 not defined
+#endif
+#define MY_ID 42
diff --git a/clang/test/Preprocessor/llvm-rc.rc b/clang/test/Preprocessor/llvm-rc.rc
new file mode 100644
index 000000000000..689fc87473f9
--- /dev/null
+++ b/clang/test/Preprocessor/llvm-rc.rc
@@ -0,0 +1,8 @@
+// RUN: llvm-rc -i%p/Inputs -Fo%t.res %s
+// RUN: llvm-readobj %t.res | FileCheck %s
+// CHECK: Resource type (int): RCDATA (ID 10)
+// CHECK: Resource name (int): 42
+#include "llvm-rc.h"
+MY_ID RCDATA {
+ "a long string of data"
+}
diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index 63ba8160c661..7411e8716943 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -26,7 +26,7 @@ config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
# suffixes: A list of file extensions to treat as test files.
config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu', '.hip',
- '.ll', '.cl', '.clcpp', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs']
+ '.ll', '.cl', '.clcpp', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs', '.rc']
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
# subdirectories contain auxiliary inputs for various tests in their parent
diff --git a/llvm/test/tools/llvm-rc/absolute.test b/llvm/test/tools/llvm-rc/absolute.test
index fd8b2d68d41e..fd054536b3bf 100644
--- a/llvm/test/tools/llvm-rc/absolute.test
+++ b/llvm/test/tools/llvm-rc/absolute.test
@@ -1,7 +1,7 @@
; RUN: touch %t.manifest
; RUN: echo "1 24 \"%t.manifest\"" > %t.rc
-; RUN: llvm-rc -- %t.rc
+; RUN: llvm-rc -no-preprocess -- %t.rc
;; On Windows, try stripping out the drive name from the absolute path,
;; and make sure the path still is found.
; RUN: cat %t.rc | sed 's/"[a-zA-Z]:/"/' > %t2.rc
-; RUN: llvm-rc -- %t2.rc
+; RUN: llvm-rc -no-preprocess -- %t2.rc
diff --git a/llvm/test/tools/llvm-rc/codepage.test b/llvm/test/tools/llvm-rc/codepage.test
index 5da7a5af8f2d..406ff00be53b 100644
--- a/llvm/test/tools/llvm-rc/codepage.test
+++ b/llvm/test/tools/llvm-rc/codepage.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /C 65001 /FO %t.utf8.res -- %p/Inputs/utf8.rc
+; RUN: llvm-rc -no-preprocess /C 65001 /FO %t.utf8.res -- %p/Inputs/utf8.rc
; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
; UTF8: Resource type (int): STRINGTABLE (ID 6)
@@ -18,11 +18,11 @@
; UTF8-NEXT: 0040: 00000000 |....|
; UTF8-NEXT: )
-; RUN: not llvm-rc /C 65001 /FO %t.utf8-escape-narrow.res -- %p/Inputs/utf8-escape-narrow.rc 2>&1 | FileCheck %s --check-prefix UTF8_ESCAPE
+; RUN: not llvm-rc -no-preprocess /C 65001 /FO %t.utf8-escape-narrow.res -- %p/Inputs/utf8-escape-narrow.rc 2>&1 | FileCheck %s --check-prefix UTF8_ESCAPE
; UTF8_ESCAPE: llvm-rc: Error in STRINGTABLE statement (ID 1):
; UTF8_ESCAPE-NEXT: Unable to interpret single byte (195) as UTF-8
-; RUN: llvm-rc /C 1252 /FO %t.cp1252.res -- %p/Inputs/cp1252.rc
+; RUN: llvm-rc -no-preprocess /C 1252 /FO %t.cp1252.res -- %p/Inputs/cp1252.rc
; RUN: llvm-readobj %t.cp1252.res | FileCheck %s --check-prefix=CP1252
; CP1252: Resource type (int): STRINGTABLE (ID 6)
diff --git a/llvm/test/tools/llvm-rc/cpp-output.test b/llvm/test/tools/llvm-rc/cpp-output.test
index 6814187d5f69..00acfff4e960 100644
--- a/llvm/test/tools/llvm-rc/cpp-output.test
+++ b/llvm/test/tools/llvm-rc/cpp-output.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/cpp-output.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/cpp-output.rc
; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): STRINGTABLE (ID 6)
diff --git a/llvm/test/tools/llvm-rc/flags.test b/llvm/test/tools/llvm-rc/flags.test
index 5b71481af2df..d1bda51bcfa7 100644
--- a/llvm/test/tools/llvm-rc/flags.test
+++ b/llvm/test/tools/llvm-rc/flags.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /dry-run /FO %t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
-; RUN: llvm-rc /dry-run /FO%t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
+; RUN: llvm-rc -no-preprocess /dry-run /FO %t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
+; RUN: llvm-rc -no-preprocess /dry-run /FO%t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
; FO-NOT: Exactly one input file should be provided.
diff --git a/llvm/test/tools/llvm-rc/helpmsg.test b/llvm/test/tools/llvm-rc/helpmsg.test
index b9a55f647268..60a99a472656 100644
--- a/llvm/test/tools/llvm-rc/helpmsg.test
+++ b/llvm/test/tools/llvm-rc/helpmsg.test
@@ -15,6 +15,7 @@
; CHECK-NEXT: /I <value> Add an include path.
; CHECK-NEXT: /LN <value> Set the default language name.
; CHECK-NEXT: /L <value> Set the default language identifier.
+; CHECK-NEXT: /no-preprocess Don't try to preprocess the input file.
; CHECK-NEXT: /N Null-terminate all strings in the string table.
; CHECK-NEXT: /U <value> Undefine a symbol for the C preprocessor.
; CHECK-NEXT: /V Be verbose.
diff --git a/llvm/test/tools/llvm-rc/include-paths.test b/llvm/test/tools/llvm-rc/include-paths.test
index 0097ae88e1db..932b2c288f0d 100644
--- a/llvm/test/tools/llvm-rc/include-paths.test
+++ b/llvm/test/tools/llvm-rc/include-paths.test
@@ -1,31 +1,31 @@
; Should find the bitmap if it is in the same folder as the rc file.
; RUN: rm -f %t.include.res
-; RUN: llvm-rc /FO %t.include.res -- %p/Inputs/include.rc
+; RUN: llvm-rc -no-preprocess /FO %t.include.res -- %p/Inputs/include.rc
; RUN: llvm-readobj %t.include.res | FileCheck --check-prefix=FOUND %s
; Try including files without quotes.
; RUN: rm -f %t.noquotes.res
-; RUN: llvm-rc /FO %t.noquotes.res -- %p/Inputs/include-noquotes.rc
+; RUN: llvm-rc -no-preprocess /FO %t.noquotes.res -- %p/Inputs/include-noquotes.rc
; RUN: llvm-readobj %t.noquotes.res | FileCheck --check-prefix=FOUND %s
; Should find the bitmap if the folder is explicitly specified.
; RUN: rm -f %t.nested-include.res
-; RUN: llvm-rc /FO %t.nested-include.res /I %p/Inputs/nested -- %p/Inputs/deep-include.rc
+; RUN: llvm-rc -no-preprocess /FO %t.nested-include.res /I %p/Inputs/nested -- %p/Inputs/deep-include.rc
; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
; The include dir can be specified via the INCLUDE env var too.
; RUN: rm -f %t.nested-include.res
-; RUN: env INCLUDE=%p/Inputs/nested llvm-rc /FO %t.nested-include.res -- %p/Inputs/deep-include.rc
+; RUN: env INCLUDE=%p/Inputs/nested llvm-rc -no-preprocess /FO %t.nested-include.res -- %p/Inputs/deep-include.rc
; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
; Specifying the /X option should make it ignore the INCLUDE variable.
; RUN: rm -f %t.nested-include.res
-; RUN: not env INCLUDE=%p/Inputs/nested llvm-rc /X /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
+; RUN: not env INCLUDE=%p/Inputs/nested llvm-rc -no-preprocess /X /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
; RUN: | FileCheck --check-prefix=MISSING %s
; Otherwise, it should not find the bitmap.
; RUN: rm -f %t.nested-include.res
-; RUN: not llvm-rc /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
+; RUN: not llvm-rc -no-preprocess /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
; RUN: | FileCheck --check-prefix=MISSING %s
; Should find the bitmap if the process's current working directory
@@ -34,7 +34,7 @@
; failure of other tests if run first.
; RUN: rm -f %t.nested-include.res
; RUN: cd %p/Inputs/nested
-; RUN: llvm-rc /FO %t.nested-include.res -- %p/Inputs/include.rc
+; RUN: llvm-rc -no-preprocess /FO %t.nested-include.res -- %p/Inputs/include.rc
; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
FOUND: Resource type (int): BITMAP (ID 2)
diff --git a/llvm/test/tools/llvm-rc/language.test b/llvm/test/tools/llvm-rc/language.test
index e764cde05e7b..7e70ae1630a3 100644
--- a/llvm/test/tools/llvm-rc/language.test
+++ b/llvm/test/tools/llvm-rc/language.test
@@ -1,6 +1,6 @@
-; RUN: llvm-rc /l 40A /FO %t.res -- %p/Inputs/language.rc
+; RUN: llvm-rc -no-preprocess /l 40A /FO %t.res -- %p/Inputs/language.rc
; RUN: llvm-readobj %t.res | FileCheck %s
-; RUN: llvm-rc /l40A /FO %t.res -- %p/Inputs/language.rc
+; RUN: llvm-rc -no-preprocess /l40A /FO %t.res -- %p/Inputs/language.rc
; RUN: llvm-readobj %t.res | FileCheck %s
; CHECK: Resource name (int): 1
diff --git a/llvm/test/tools/llvm-rc/memoryflags-stringtable.test b/llvm/test/tools/llvm-rc/memoryflags-stringtable.test
index 24f68cd09e7b..3236c500745f 100644
--- a/llvm/test/tools/llvm-rc/memoryflags-stringtable.test
+++ b/llvm/test/tools/llvm-rc/memoryflags-stringtable.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/memoryflags-stringtable.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/memoryflags-stringtable.rc
; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): STRINGTABLE (ID 6)
diff --git a/llvm/test/tools/llvm-rc/memoryflags.test b/llvm/test/tools/llvm-rc/memoryflags.test
index cd9e53c4ed59..3d1fe9a4e53c 100644
--- a/llvm/test/tools/llvm-rc/memoryflags.test
+++ b/llvm/test/tools/llvm-rc/memoryflags.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/memoryflags.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/memoryflags.rc
; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): CURSOR (ID 1)
diff --git a/llvm/test/tools/llvm-rc/not-expr.test b/llvm/test/tools/llvm-rc/not-expr.test
index f785ec78c069..db7fee42a248 100644
--- a/llvm/test/tools/llvm-rc/not-expr.test
+++ b/llvm/test/tools/llvm-rc/not-expr.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/not-expr.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/not-expr.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=NOTEXPR
; NOTEXPR: Resource type (int): DIALOG (ID 5)
diff --git a/llvm/test/tools/llvm-rc/parser-expr.test b/llvm/test/tools/llvm-rc/parser-expr.test
index e16d29de3cbc..ed6796529fdf 100644
--- a/llvm/test/tools/llvm-rc/parser-expr.test
+++ b/llvm/test/tools/llvm-rc/parser-expr.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /dry-run /V -- %p/Inputs/parser-expr.rc | FileCheck %s
+; RUN: llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr.rc | FileCheck %s
; CHECK: Language: 5, Sublanguage: 1
; CHECK-NEXT: Language: 3, Sublanguage: 2
@@ -17,36 +17,36 @@
; CHECK-NEXT: Language: 5, Sublanguage: 7
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-binary-1.rc 2>&1 | FileCheck %s --check-prefix BINARY1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-binary-1.rc 2>&1 | FileCheck %s --check-prefix BINARY1
; BINARY1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got &
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-binary-2.rc 2>&1 | FileCheck %s --check-prefix BINARY2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-binary-2.rc 2>&1 | FileCheck %s --check-prefix BINARY2
; BINARY2: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got |
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-binary-3.rc 2>&1 | FileCheck %s --check-prefix BINARY3
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-binary-3.rc 2>&1 | FileCheck %s --check-prefix BINARY3
; BINARY3: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got +
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-unary.rc 2>&1 | FileCheck %s --check-prefix UNARY
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-unary.rc 2>&1 | FileCheck %s --check-prefix UNARY
; UNARY: llvm-rc: Error parsing file: expected ',', got ~
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-unbalanced-1.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-unbalanced-1.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED1
; UNBALANCED1: llvm-rc: Error parsing file: expected ')', got ,
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-unbalanced-2.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-unbalanced-2.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED2
; UNBALANCED2: llvm-rc: Error parsing file: expected ',', got )
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-unbalanced-3.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED3
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-unbalanced-3.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED3
; UNBALANCED3: llvm-rc: Error parsing file: expected ',', got )
diff --git a/llvm/test/tools/llvm-rc/parser.test b/llvm/test/tools/llvm-rc/parser.test
index e9f8cb94c8c9..2e1d981418c3 100644
--- a/llvm/test/tools/llvm-rc/parser.test
+++ b/llvm/test/tools/llvm-rc/parser.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /dry-run /V -- %p/Inputs/parser-correct-everything.rc | FileCheck %s --check-prefix PGOOD
+; RUN: llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-correct-everything.rc | FileCheck %s --check-prefix PGOOD
; PGOOD: Icon (meh): "hello.bmp"
; PGOOD-NEXT: Icon (Icon): "Icon"
@@ -100,156 +100,156 @@
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-stringtable-no-string.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-stringtable-no-string.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE1
; PSTRINGTABLE1: llvm-rc: Error parsing file: expected string, got }
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-stringtable-weird-option.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-stringtable-weird-option.rc 2>&1 | FileCheck %s --check-prefix PSTRINGTABLE2
; PSTRINGTABLE2: llvm-rc: Error parsing file: expected optional statement type, BEGIN or '{', got NONSENSETYPE
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-eof.rc 2>&1 | FileCheck %s --check-prefix PEOF
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-eof.rc 2>&1 | FileCheck %s --check-prefix PEOF
; PEOF: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got <EOF>
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-no-characteristics-arg.rc 2>&1 | FileCheck %s --check-prefix PCHARACTERISTICS1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-no-characteristics-arg.rc 2>&1 | FileCheck %s --check-prefix PCHARACTERISTICS1
; PCHARACTERISTICS1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got BEGIN
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-nonsense-token.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-nonsense-token.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE1
; PNONSENSE1: llvm-rc: Error parsing file: expected int or identifier, got &
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-nonsense-type.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-nonsense-type.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE2
; PNONSENSE2: llvm-rc: Error parsing file: expected filename, '{' or BEGIN, got <EOF>
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-nonsense-type-eof.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE3
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-nonsense-type-eof.rc 2>&1 | FileCheck %s --check-prefix PNONSENSE3
; PNONSENSE3: llvm-rc: Error parsing file: expected int or identifier, got <EOF>
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-language-no-comma.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-language-no-comma.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE1
; PLANGUAGE1: llvm-rc: Error parsing file: expected ',', got 7
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-language-too-many-commas.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-language-too-many-commas.rc 2>&1 | FileCheck %s --check-prefix PLANGUAGE2
; PLANGUAGE2: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got ,
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-html-extra-comma.rc 2>&1 | FileCheck %s --check-prefix PHTML2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-html-extra-comma.rc 2>&1 | FileCheck %s --check-prefix PHTML2
; PHTML2: llvm-rc: Error parsing file: expected string, got ,
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-accelerators-bad-flag.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-accelerators-bad-flag.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS1
; PACCELERATORS1: llvm-rc: Error parsing file: expected ASCII/VIRTKEY/NOINVERT/ALT/SHIFT/CONTROL, got HELLO
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-accelerators-bad-int-or-string.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-accelerators-bad-int-or-string.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS2
; PACCELERATORS2: llvm-rc: Error parsing file: expected int or string, got NotIntOrString
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-accelerators-no-comma.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS3
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-accelerators-no-comma.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS3
; PACCELERATORS3: llvm-rc: Error parsing file: expected int or string, got CONTROL
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-accelerators-no-comma-2.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS4
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-accelerators-no-comma-2.rc 2>&1 | FileCheck %s --check-prefix PACCELERATORS4
; PACCELERATORS4: llvm-rc: Error parsing file: expected ',', got 10
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-menu-bad-id.rc 2>&1 | FileCheck %s --check-prefix PMENU1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-menu-bad-id.rc 2>&1 | FileCheck %s --check-prefix PMENU1
; PMENU1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got A
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-menu-bad-flag.rc 2>&1 | FileCheck %s --check-prefix PMENU2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-menu-bad-flag.rc 2>&1 | FileCheck %s --check-prefix PMENU2
; PMENU2: llvm-rc: Error parsing file: expected CHECKED/GRAYED/HELP/INACTIVE/MENUBARBREAK/MENUBREAK, got ERRONEOUS
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-menu-missing-block.rc 2>&1 | FileCheck %s --check-prefix PMENU3
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-menu-missing-block.rc 2>&1 | FileCheck %s --check-prefix PMENU3
; PMENU3: llvm-rc: Error parsing file: expected '{', got POPUP
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-menu-misspelled-separator.rc 2>&1 | FileCheck %s --check-prefix PMENU4
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-menu-misspelled-separator.rc 2>&1 | FileCheck %s --check-prefix PMENU4
; PMENU4: llvm-rc: Error parsing file: expected SEPARATOR or string, got NOTSEPARATOR
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-cant-give-helpid.rc 2>&1 | FileCheck %s --check-prefix PDIALOG1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-cant-give-helpid.rc 2>&1 | FileCheck %s --check-prefix PDIALOG1
; PDIALOG1: llvm-rc: Error parsing file: expected identifier, got ,
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-too-few-args.rc 2>&1 | FileCheck %s --check-prefix PDIALOG2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-too-few-args.rc 2>&1 | FileCheck %s --check-prefix PDIALOG2
; PDIALOG2: llvm-rc: Error parsing file: expected ',', got }
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-too-many-args.rc 2>&1 | FileCheck %s --check-prefix PDIALOG3
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-too-many-args.rc 2>&1 | FileCheck %s --check-prefix PDIALOG3
; PDIALOG3: llvm-rc: Error parsing file: expected identifier, got ,
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-unknown-type.rc 2>&1 | FileCheck %s --check-prefix PDIALOG4
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-unknown-type.rc 2>&1 | FileCheck %s --check-prefix PDIALOG4
; PDIALOG4: llvm-rc: Error parsing file: expected control type, END or '}', got UNKNOWN
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-unnecessary-string.rc 2>&1 | FileCheck %s --check-prefix PDIALOG5
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-unnecessary-string.rc 2>&1 | FileCheck %s --check-prefix PDIALOG5
; PDIALOG5: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got "This shouldn't be here"
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-dialog-simple-font.rc 2>&1 | FileCheck %s --check-prefix PDIALOG6
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-dialog-simple-font.rc 2>&1 | FileCheck %s --check-prefix PDIALOG6
; PDIALOG6: llvm-rc: Error parsing file: expected identifier, got ,
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-wrong-fixed.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-wrong-fixed.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO1
; PVERSIONINFO1: llvm-rc: Error parsing file: expected fixed VERSIONINFO statement type, got WEIRDFIXED
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-named-main-block.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO2
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-named-main-block.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO2
; PVERSIONINFO2: llvm-rc: Error parsing file: expected fixed VERSIONINFO statement type, got BLOCK
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-unnamed-inner-block.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO3
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-unnamed-inner-block.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO3
; PVERSIONINFO3: llvm-rc: Error parsing file: expected string, got {
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-unnamed-value.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO4
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-unnamed-value.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO4
; PVERSIONINFO4: llvm-rc: Error parsing file: expected string, got END
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-bad-type.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO5
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-bad-type.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO5
; PVERSIONINFO5: llvm-rc: Error parsing file: expected BLOCK or VALUE, got INCORRECT
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-versioninfo-repeated-fixed.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO6
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-versioninfo-repeated-fixed.rc 2>&1 | FileCheck %s --check-prefix PVERSIONINFO6
; PVERSIONINFO6: llvm-rc: Error parsing file: expected yet unread fixed VERSIONINFO statement type, got FILEVERSION
-; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-user-invalid-contents.rc 2>&1 | FileCheck %s --check-prefix PUSER1
+; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-user-invalid-contents.rc 2>&1 | FileCheck %s --check-prefix PUSER1
; PUSER1: llvm-rc: Error parsing file: expected int or string, got InvalidToken
diff --git a/llvm/test/tools/llvm-rc/preproc.test b/llvm/test/tools/llvm-rc/preproc.test
new file mode 100644
index 000000000000..f55e5434dce3
--- /dev/null
+++ b/llvm/test/tools/llvm-rc/preproc.test
@@ -0,0 +1,3 @@
+; RUN: llvm-rc -### -i%p "-DFOO1=\"foo bar\"" -UFOO2 -D FOO3 -- %p/Inputs/empty.rc | FileCheck %s
+
+; CHECK: {{^}} "clang" "--driver-mode=gcc" "-target" "{{.*}}-pc-windows-msvc-coff" "-E" "-xc" "-DRC_INVOKED" "{{.*}}empty.rc" "-o" "{{.*}}preproc-{{.*}}.rc" "-I" "{{.*}}" "-D" "FOO1=\"foo bar\"" "-U" "FOO2" "-D" "FOO3"{{$}}
diff --git a/llvm/test/tools/llvm-rc/tag-accelerators.test b/llvm/test/tools/llvm-rc/tag-accelerators.test
index 73ce6ae08378..336727f61768 100644
--- a/llvm/test/tools/llvm-rc/tag-accelerators.test
+++ b/llvm/test/tools/llvm-rc/tag-accelerators.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/tag-accelerators.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=ACCELERATORS
; ACCELERATORS: Resource type (int): ACCELERATOR (ID 9)
@@ -79,79 +79,79 @@
; ACCELERATORS-NEXT: )
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-bad-id.rc 2>&1 | FileCheck %s --check-prefix BADID
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-bad-id.rc 2>&1 | FileCheck %s --check-prefix BADID
; BADID: llvm-rc: Error in ACCELERATORS statement (ID 1):
; BADID-NEXT: ACCELERATORS entry ID (1234567) does not fit in 16 bits.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-ascii-virtkey.rc 2>&1 | FileCheck %s --check-prefix ASCII1
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-virtkey.rc 2>&1 | FileCheck %s --check-prefix ASCII1
; ASCII1: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII1-NEXT: Accelerator ID 15: Accelerator can't be both ASCII and VIRTKEY
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-ascii-control.rc 2>&1 | FileCheck %s --check-prefix ASCII2
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-control.rc 2>&1 | FileCheck %s --check-prefix ASCII2
; ASCII2: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII2-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-ascii-shift.rc 2>&1 | FileCheck %s --check-prefix ASCII3
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-shift.rc 2>&1 | FileCheck %s --check-prefix ASCII3
; ASCII3: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII3-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-ascii-alt.rc 2>&1 | FileCheck %s --check-prefix ASCII4
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-ascii-alt.rc 2>&1 | FileCheck %s --check-prefix ASCII4
; ASCII4: llvm-rc: Error in ACCELERATORS statement (ID 2):
; ASCII4-NEXT: Accelerator ID 15: Can only apply ALT, SHIFT or CONTROL to VIRTKEY accelerators
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-bad-key-id.rc 2>&1 | FileCheck %s --check-prefix BADKEYID
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-bad-key-id.rc 2>&1 | FileCheck %s --check-prefix BADKEYID
; BADKEYID: llvm-rc: Error in ACCELERATORS statement (ID 9):
; BADKEYID-NEXT: Numeric event key ID (1234567) does not fit in 16 bits.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-too-short.rc 2>&1 | FileCheck %s --check-prefix LENGTH1
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-too-short.rc 2>&1 | FileCheck %s --check-prefix LENGTH1
; LENGTH1: llvm-rc: Error in ACCELERATORS statement (ID 10):
; LENGTH1-NEXT: Accelerator ID 12: Accelerator string events should have length 1 or 2
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-too-long.rc 2>&1 | FileCheck %s --check-prefix LENGTH2
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-too-long.rc 2>&1 | FileCheck %s --check-prefix LENGTH2
; LENGTH2: llvm-rc: Error in ACCELERATORS statement (ID 12):
; LENGTH2-NEXT: Accelerator ID 5: Accelerator string events should have length 1 or 2
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-only-caret.rc 2>&1 | FileCheck %s --check-prefix CARET1
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-only-caret.rc 2>&1 | FileCheck %s --check-prefix CARET1
; CARET1: llvm-rc: Error in ACCELERATORS statement (ID 555):
; CARET1-NEXT: Accelerator ID 100: No character following '^' in accelerator event
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-no-caret.rc 2>&1 | FileCheck %s --check-prefix CARET2
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-no-caret.rc 2>&1 | FileCheck %s --check-prefix CARET2
; CARET2: llvm-rc: Error in ACCELERATORS statement (ID 50):
; CARET2-NEXT: Accelerator ID 1: Event string should be one-character, possibly preceded by '^'
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-long-virtkey.rc 2>&1 | FileCheck %s --check-prefix CARET3
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-long-virtkey.rc 2>&1 | FileCheck %s --check-prefix CARET3
; CARET3: llvm-rc: Error in ACCELERATORS statement (ID 100):
; CARET3-NEXT: Accelerator ID 10: VIRTKEY accelerator events can't be preceded by '^'
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-control-nonalpha.rc 2>&1 | FileCheck %s --check-prefix NONALPHA1
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-control-nonalpha.rc 2>&1 | FileCheck %s --check-prefix NONALPHA1
; NONALPHA1: llvm-rc: Error in ACCELERATORS statement (ID 100):
; NONALPHA1-NEXT: Accelerator ID 1: Control character accelerator event should be alphabetic
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-accelerators-virtual-nonalpha.rc 2>&1 | FileCheck %s --check-prefix NONALPHA2
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-accelerators-virtual-nonalpha.rc 2>&1 | FileCheck %s --check-prefix NONALPHA2
; NONALPHA2: llvm-rc: Error in ACCELERATORS statement (ID 42):
; NONALPHA2-NEXT: Accelerator ID 1: Non-alphanumeric characters cannot describe virtual keys
diff --git a/llvm/test/tools/llvm-rc/tag-dialog.test b/llvm/test/tools/llvm-rc/tag-dialog.test
index 023deeb27583..7e081c414fc4 100644
--- a/llvm/test/tools/llvm-rc/tag-dialog.test
+++ b/llvm/test/tools/llvm-rc/tag-dialog.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/tag-dialog.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=DIALOG
; DIALOG: Resource type (int): DIALOG (ID 5)
@@ -163,7 +163,7 @@
; DIALOG-NEXT: )
-; RUN: llvm-rc /FO %t -- %p/Inputs/tag-dialog-headers.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-headers.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=HEADERS
; HEADERS: Resource type (int): DIALOG (ID 5)
@@ -636,73 +636,73 @@
; HEADERS-NEXT: )
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-large-coord.rc 2>&1 | FileCheck %s --check-prefix COORD1
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-large-coord.rc 2>&1 | FileCheck %s --check-prefix COORD1
; COORD1: llvm-rc: Error in DIALOGEX statement (ID 1):
; COORD1-NEXT: Dialog x-coordinate (50000) does not fit in 16-bit signed integer type.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-large-coord-neg.rc 2>&1 | FileCheck %s --check-prefix COORD2
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-large-coord-neg.rc 2>&1 | FileCheck %s --check-prefix COORD2
; COORD2: llvm-rc: Error in DIALOG statement (ID 1):
; COORD2-NEXT: Dialog y-coordinate (-40000) does not fit in 16-bit signed integer type.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-large-size.rc 2>&1 | FileCheck %s --check-prefix COORD3
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-large-size.rc 2>&1 | FileCheck %s --check-prefix COORD3
; COORD3: llvm-rc: Error in DIALOGEX statement (ID 1):
; COORD3-NEXT: Dialog height (32768) does not fit in 16-bit signed integer type.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-negative-size.rc 2>&1 | FileCheck %s --check-prefix COORD4
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-negative-size.rc 2>&1 | FileCheck %s --check-prefix COORD4
; COORD4: llvm-rc: Error in DIALOGEX statement (ID 1):
; COORD4-NEXT: Dialog width (-50) cannot be negative.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-coord.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD1
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-coord.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD1
; CTL-COORD1: llvm-rc: Error in DIALOGEX statement (ID 1):
; CTL-COORD1-NEXT: Error in LTEXT control (ID 1):
; CTL-COORD1-NEXT: Dialog control x-coordinate (44444) does not fit in 16-bit signed integer type.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-coord-neg.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD2
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-coord-neg.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD2
; CTL-COORD2: llvm-rc: Error in DIALOG statement (ID 1):
; CTL-COORD2-NEXT: Error in LTEXT control (ID 1):
; CTL-COORD2-NEXT: Dialog control y-coordinate (-32769) does not fit in 16-bit signed integer type.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-size.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD3
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-size.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD3
; CTL-COORD3: llvm-rc: Error in DIALOGEX statement (ID 1):
; CTL-COORD3-NEXT: Error in LTEXT control (ID 1):
; CTL-COORD3-NEXT: Dialog control width (40000) does not fit in 16-bit signed integer type.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-negative-size.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD4
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-negative-size.rc 2>&1 | FileCheck %s --check-prefix CTL-COORD4
; CTL-COORD4: llvm-rc: Error in DIALOG statement (ID 1):
; CTL-COORD4-NEXT: Error in LTEXT control (ID 1):
; CTL-COORD4-NEXT: Dialog control height (-700) cannot be negative.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-id.rc 2>&1 | FileCheck %s --check-prefix CTL-ID
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-id.rc 2>&1 | FileCheck %s --check-prefix CTL-ID
; CTL-ID: llvm-rc: Error in DIALOG statement (ID 5):
; CTL-ID-NEXT: Error in RTEXT control (ID 100000):
; CTL-ID-NEXT: Control ID in simple DIALOG resource (100000) does not fit in 16 bits.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-ctl-large-ref-id.rc 2>&1 | FileCheck %s --check-prefix CTL-REF-ID
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-ctl-large-ref-id.rc 2>&1 | FileCheck %s --check-prefix CTL-REF-ID
; CTL-REF-ID: llvm-rc: Error in DIALOGEX statement (ID 1):
; CTL-REF-ID-NEXT: Error in CTEXT control (ID 42):
; CTL-REF-ID-NEXT: Control reference ID (65536) does not fit in 16 bits.
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-dialog-bad-style.rc 2>&1 | FileCheck %s --check-prefix STYLE
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-dialog-bad-style.rc 2>&1 | FileCheck %s --check-prefix STYLE
; STYLE: llvm-rc: Error in DIALOG statement (ID 1):
; STYLE-NEXT: 16 higher bits of DIALOG resource style cannot be equal to 0xFFFF
diff --git a/llvm/test/tools/llvm-rc/tag-escape.test b/llvm/test/tools/llvm-rc/tag-escape.test
index 667a7e6076ad..5c8beb680698 100644
--- a/llvm/test/tools/llvm-rc/tag-escape.test
+++ b/llvm/test/tools/llvm-rc/tag-escape.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/tag-escape.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-escape.rc
; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): MENU (ID 4)
diff --git a/llvm/test/tools/llvm-rc/tag-html.test b/llvm/test/tools/llvm-rc/tag-html.test
index 30e873e04790..3620fe954ba1 100644
--- a/llvm/test/tools/llvm-rc/tag-html.test
+++ b/llvm/test/tools/llvm-rc/tag-html.test
@@ -1,6 +1,6 @@
; RUN: rm -rf %t && mkdir %t && cd %t
; RUN: cp %p/Inputs/webpage*.html .
-; RUN: llvm-rc /FO %t/tag-html.res -- %p/Inputs/tag-html.rc
+; RUN: llvm-rc -no-preprocess /FO %t/tag-html.res -- %p/Inputs/tag-html.rc
; RUN: llvm-readobj %t/tag-html.res | FileCheck %s --check-prefix HTML
; HTML: Resource type (int): HTML (ID 23)
diff --git a/llvm/test/tools/llvm-rc/tag-icon-cursor.test b/llvm/test/tools/llvm-rc/tag-icon-cursor.test
index 1451c4a816ca..cfff79944bd8 100644
--- a/llvm/test/tools/llvm-rc/tag-icon-cursor.test
+++ b/llvm/test/tools/llvm-rc/tag-icon-cursor.test
@@ -1,7 +1,7 @@
; RUN: rm -rf %t
; RUN: mkdir %t
-; RUN: llvm-rc /FO %t/tag-icon-cursor.res -- %p/Inputs/tag-icon-cursor.rc
+; RUN: llvm-rc -no-preprocess /FO %t/tag-icon-cursor.res -- %p/Inputs/tag-icon-cursor.rc
; RUN: llvm-readobj %t/tag-icon-cursor.res | FileCheck %s
; CHECK: Resource type (int): CURSOR (ID 1)
@@ -320,12 +320,12 @@
; CHECK-NEXT: )
-; RUN: not llvm-rc /FO %t/1 -- %p/Inputs/tag-icon-cursor-nonexistent.rc 2>&1 | FileCheck %s --check-prefix NOFILE
+; RUN: not llvm-rc -no-preprocess /FO %t/1 -- %p/Inputs/tag-icon-cursor-nonexistent.rc 2>&1 | FileCheck %s --check-prefix NOFILE
; NOFILE: llvm-rc: Error in CURSOR statement (ID 500):
; NOFILE-NEXT: file not found : this-file-does-not-exist.cur
-; RUN: not llvm-rc /FO %t/1 -- %p/Inputs/tag-icon-cursor-nonsense.rc 2>&1 | FileCheck %s --check-prefix NONSENSE
+; RUN: not llvm-rc -no-preprocess /FO %t/1 -- %p/Inputs/tag-icon-cursor-nonsense.rc 2>&1 | FileCheck %s --check-prefix NONSENSE
; NONSENSE: llvm-rc: Error in ICON statement (ID 1):
; NONSENSE-NEXT: Incorrect icon/cursor Reserved field; should be 0.
diff --git a/llvm/test/tools/llvm-rc/tag-menu.test b/llvm/test/tools/llvm-rc/tag-menu.test
index 58c856b700f8..3a17b22f847b 100644
--- a/llvm/test/tools/llvm-rc/tag-menu.test
+++ b/llvm/test/tools/llvm-rc/tag-menu.test
@@ -1,9 +1,9 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/tag-menu.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-menu.rc
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=MENU
-; Test running llvm-rc without an explicit output file.
+; Test running llvm-rc -no-preprocess without an explicit output file.
; RUN: cp %p/Inputs/tag-menu.rc %t.implicit.rc
-; RUN: llvm-rc -- %t.implicit.rc
+; RUN: llvm-rc -no-preprocess -- %t.implicit.rc
; RUN: llvm-readobj %t.implicit.res | FileCheck --check-prefix=MENU %s
; MENU: Resource type (int): MENU (ID 4)
@@ -74,7 +74,7 @@
; MENU-NEXT: )
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-menu-bad-menuitem-id.rc 2>&1 | FileCheck %s --check-prefix BADID
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-menu-bad-menuitem-id.rc 2>&1 | FileCheck %s --check-prefix BADID
; BADID: llvm-rc: Error in MENU statement (ID 1):
; BADID-NEXT: MENUITEM action ID (100000) does not fit in 16 bits.
diff --git a/llvm/test/tools/llvm-rc/tag-stringtable.test b/llvm/test/tools/llvm-rc/tag-stringtable.test
index dd7946e326f5..f62215a6b013 100644
--- a/llvm/test/tools/llvm-rc/tag-stringtable.test
+++ b/llvm/test/tools/llvm-rc/tag-stringtable.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/tag-stringtable-basic.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-stringtable-basic.rc
; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): STRINGTABLE (ID 6)
@@ -81,7 +81,7 @@
; CHECK-NEXT: )
-; RUN: llvm-rc /N /FO %t0 -- %p/Inputs/tag-stringtable-basic.rc
+; RUN: llvm-rc -no-preprocess /N /FO %t0 -- %p/Inputs/tag-stringtable-basic.rc
; RUN: llvm-readobj %t0 | FileCheck %s --check-prefix=NULL
; NULL: Resource type (int): STRINGTABLE (ID 6)
@@ -166,5 +166,5 @@
; NULL-NEXT: )
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-stringtable-same-ids.rc 2>&1 | FileCheck %s --check-prefix SAMEIDS
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-stringtable-same-ids.rc 2>&1 | FileCheck %s --check-prefix SAMEIDS
; SAMEIDS: llvm-rc: Multiple STRINGTABLE strings located under ID 1
diff --git a/llvm/test/tools/llvm-rc/tag-user.test b/llvm/test/tools/llvm-rc/tag-user.test
index 44c8b758fd50..fb17d93ee92d 100644
--- a/llvm/test/tools/llvm-rc/tag-user.test
+++ b/llvm/test/tools/llvm-rc/tag-user.test
@@ -2,7 +2,7 @@
; RUN: mkdir %t
; RUN: cd %t
; RUN: cp %p/Inputs/bitmap.bmp .
-; RUN: llvm-rc /FO %t/tag-user.res -- %p/Inputs/tag-user.rc
+; RUN: llvm-rc -no-preprocess /FO %t/tag-user.res -- %p/Inputs/tag-user.rc
; RUN: llvm-readobj %t/tag-user.res | FileCheck %s
; CHECK: Resource type (int): ID 500
diff --git a/llvm/test/tools/llvm-rc/tag-versioninfo.test b/llvm/test/tools/llvm-rc/tag-versioninfo.test
index 3ce534b88096..472bc575463e 100644
--- a/llvm/test/tools/llvm-rc/tag-versioninfo.test
+++ b/llvm/test/tools/llvm-rc/tag-versioninfo.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/tag-versioninfo.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-versioninfo.rc
; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): VERSIONINFO (ID 16)
@@ -56,11 +56,11 @@
; CHECK-NEXT: )
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-versioninfo-mixed-ints-strings.rc 2>&1 | FileCheck %s --check-prefix STRINT
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-versioninfo-mixed-ints-strings.rc 2>&1 | FileCheck %s --check-prefix STRINT
; STRINT: llvm-rc: Error in VERSIONINFO statement (ID 1):
; STRINT-NEXT: VALUE "FileDescription" cannot contain both strings and integers
-; RUN: not llvm-rc /FO %t -- %p/Inputs/tag-versioninfo-word-too-large.rc 2>&1 | FileCheck %s --check-prefix WORD
+; RUN: not llvm-rc -no-preprocess /FO %t -- %p/Inputs/tag-versioninfo-word-too-large.rc 2>&1 | FileCheck %s --check-prefix WORD
; WORD: llvm-rc: Error in VERSIONINFO statement (ID 1):
; WORD-NEXT: VERSIONINFO integer value (65536) does not fit in 16 bits.
diff --git a/llvm/test/tools/llvm-rc/tokenizer.test b/llvm/test/tools/llvm-rc/tokenizer.test
index 59164677bac8..eb2233c89d72 100644
--- a/llvm/test/tools/llvm-rc/tokenizer.test
+++ b/llvm/test/tools/llvm-rc/tokenizer.test
@@ -1,4 +1,4 @@
-; RUN: not llvm-rc /V /FO %t.res -- %p/Inputs/tokens.rc | FileCheck %s
+; RUN: not llvm-rc -no-preprocess /V /FO %t.res -- %p/Inputs/tokens.rc | FileCheck %s
; llvm-rc fails now on this sample because it is an invalid resource file
; script. We silence the error message and just analyze the output.
diff --git a/llvm/test/tools/llvm-rc/versioninfo-padding.test b/llvm/test/tools/llvm-rc/versioninfo-padding.test
index 41f5df8bdc31..bd230f408648 100644
--- a/llvm/test/tools/llvm-rc/versioninfo-padding.test
+++ b/llvm/test/tools/llvm-rc/versioninfo-padding.test
@@ -1,4 +1,4 @@
-; RUN: llvm-rc /FO %t -- %p/Inputs/versioninfo-padding.rc
+; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/versioninfo-padding.rc
; RUN: llvm-readobj %t | FileCheck %s
; CHECK: Resource type (int): VERSIONINFO (ID 16)
diff --git a/llvm/tools/llvm-rc/Opts.td b/llvm/tools/llvm-rc/Opts.td
index 7a39a71f5aa8..6d9c0e2601a4 100644
--- a/llvm/tools/llvm-rc/Opts.td
+++ b/llvm/tools/llvm-rc/Opts.td
@@ -17,13 +17,13 @@ class S_nodoc<string name> : Separate<["/", "-"], name>;
def fileout : JS<"FO", "Change the output file location.">;
-def define : S<"D", "Define a symbol for the C preprocessor.">;
-def undef : S<"U", "Undefine a symbol for the C preprocessor.">;
+def define : JS<"D", "Define a symbol for the C preprocessor.">;
+def undef : JS<"U", "Undefine a symbol for the C preprocessor.">;
def lang_id : JS<"L", "Set the default language identifier.">;
def lang_name : S<"LN", "Set the default language name.">;
-def includepath : S<"I", "Add an include path.">;
+def includepath : JS<"I", "Add an include path.">;
def noinclude : F<"X", "Ignore 'include' variable.">;
def add_null : F<"N", "Null-terminate all strings in the string table.">;
@@ -34,9 +34,16 @@ def verbose : F<"V", "Be verbose.">;
def help : F<"?", "Display this help and exit.">;
def h : F<"H", "Display this help and exit.">, Alias<help>;
+def codepage : JS<"C", "Set the codepage used for input strings.">;
+
+// llvm-rc specific options:
+
def dry_run : F<"dry-run", "Don't compile the input; only try to parse it.">;
-def codepage : JS<"C", "Set the codepage used for input strings.">;
+def no_preprocess : F<"no-preprocess", "Don't try to preprocess the input file.">;
+
+// Print (but do not run) the commands to run for preprocessing
+def _HASH_HASH_HASH : F_nodoc<"###">;
// Unused switches (at least for now). These will stay unimplemented
// in an early stage of development and can be ignored. However, we need to
diff --git a/llvm/tools/llvm-rc/llvm-rc.cpp b/llvm/tools/llvm-rc/llvm-rc.cpp
index 2007ef903c7d..ab5ecb8fa3fd 100644
--- a/llvm/tools/llvm-rc/llvm-rc.cpp
+++ b/llvm/tools/llvm-rc/llvm-rc.cpp
@@ -17,17 +17,22 @@
#include "ResourceScriptStmt.h"
#include "ResourceScriptToken.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/Host.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
@@ -71,12 +76,114 @@ public:
};
static ExitOnError ExitOnErr;
+static FileRemover TempPreprocFile;
LLVM_ATTRIBUTE_NORETURN static void fatalError(const Twine &Message) {
errs() << Message << "\n";
exit(1);
}
+std::string createTempFile(const Twine &Prefix, StringRef Suffix) {
+ std::error_code EC;
+ SmallString<128> FileName;
+ if ((EC = sys::fs::createTemporaryFile(Prefix, Suffix, FileName)))
+ fatalError("Unable to create temp file: " + EC.message());
+ return static_cast<std::string>(FileName);
+}
+
+ErrorOr<std::string> findClang(const char *Argv0) {
+ StringRef Parent = llvm::sys::path::parent_path(Argv0);
+ ErrorOr<std::string> Path = std::error_code();
+ if (!Parent.empty()) {
+ // First look for the tool with all potential names in the specific
+ // directory of Argv0, if known
+ for (const auto *Name : {"clang", "clang-cl"}) {
+ Path = sys::findProgramByName(Name, Parent);
+ if (Path)
+ return Path;
+ }
+ }
+ // If no parent directory known, or not found there, look everywhere in PATH
+ for (const auto *Name : {"clang", "clang-cl"}) {
+ Path = sys::findProgramByName(Name);
+ if (Path)
+ return Path;
+ }
+ return Path;
+}
+
+std::string getClangClTriple() {
+ Triple T(sys::getDefaultTargetTriple());
+ T.setOS(llvm::Triple::Win32);
+ T.setVendor(llvm::Triple::PC);
+ T.setEnvironment(llvm::Triple::MSVC);
+ T.setObjectFormat(llvm::Triple::COFF);
+ return T.str();
+}
+
+bool preprocess(StringRef Src, StringRef Dst, opt::InputArgList &InputArgs,
+ const char *Argv0) {
+ std::string Clang;
+ if (InputArgs.hasArg(OPT__HASH_HASH_HASH)) {
+ Clang = "clang";
+ } else {
+ ErrorOr<std::string> ClangOrErr = findClang(Argv0);
+ if (ClangOrErr) {
+ Clang = *ClangOrErr;
+ } else {
+ errs() << "llvm-rc: Unable to find clang, skipping preprocessing."
+ << "\n";
+ errs() << "Pass -no-cpp to disable preprocessing. This will be an error "
+ "in the future."
+ << "\n";
+ return false;
+ }
+ }
+ std::string PreprocTriple = getClangClTriple();
+
+ SmallVector<StringRef, 8> Args = {
+ Clang, "--driver-mode=gcc", "-target", PreprocTriple, "-E",
+ "-xc", "-DRC_INVOKED", Src, "-o", Dst};
+ if (InputArgs.hasArg(OPT_noinclude)) {
+#ifdef _WIN32
+ ::_putenv("INCLUDE=");
+#else
+ ::unsetenv("INCLUDE");
+#endif
+ }
+ for (const auto *Arg :
+ InputArgs.filtered(OPT_includepath, OPT_define, OPT_undef)) {
+ switch (Arg->getOption().getID()) {
+ case OPT_includepath:
+ Args.push_back("-I");
+ break;
+ case OPT_define:
+ Args.push_back("-D");
+ break;
+ case OPT_undef:
+ Args.push_back("-U");
+ break;
+ }
+ Args.push_back(Arg->getValue());
+ }
+ if (InputArgs.hasArg(OPT__HASH_HASH_HASH) || InputArgs.hasArg(OPT_verbose)) {
+ for (const auto &A : Args) {
+ outs() << " ";
+ sys::printArg(outs(), A, InputArgs.hasArg(OPT__HASH_HASH_HASH));
+ }
+ outs() << "\n";
+ if (InputArgs.hasArg(OPT__HASH_HASH_HASH))
+ exit(0);
+ }
+ // The llvm Support classes don't handle reading from stdout of a child
+ // process; otherwise we could avoid using a temp file.
+ int Res = sys::ExecuteAndWait(Clang, Args);
+ if (Res) {
+ fatalError("llvm-rc: Preprocessing failed.");
+ }
+ return true;
+}
+
} // anonymous namespace
int main(int Argc, const char **Argv) {
@@ -106,9 +213,17 @@ int main(int Argc, const char **Argv) {
fatalError("Exactly one input file should be provided.");
}
+ std::string PreprocessedFile = InArgsInfo[0];
+ if (!InputArgs.hasArg(OPT_no_preprocess)) {
+ std::string OutFile = createTempFile("preproc", "rc");
+ TempPreprocFile.setFile(OutFile);
+ if (preprocess(InArgsInfo[0], OutFile, InputArgs, Argv[0]))
+ PreprocessedFile = OutFile;
+ }
+
// Read and tokenize the input file.
ErrorOr<std::unique_ptr<MemoryBuffer>> File =
- MemoryBuffer::getFile(InArgsInfo[0]);
+ MemoryBuffer::getFile(PreprocessedFile);
if (!File) {
fatalError("Error opening file '" + Twine(InArgsInfo[0]) +
"': " + File.getError().message());