Skip to content

Commit 64bc44f

Browse files
committed
[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
1 parent ee34ca3 commit 64bc44f

30 files changed

+253
-111
lines changed

clang/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ if( NOT CLANG_BUILT_STANDALONE )
120120
llvm-objcopy
121121
llvm-objdump
122122
llvm-profdata
123+
llvm-rc
123124
llvm-readelf
124125
llvm-readobj
125126
llvm-strip
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef RC_INVOKED
2+
#error RC_INVOKED not defined
3+
#endif
4+
#ifndef _WIN32
5+
#error _WIN32 not defined
6+
#endif
7+
#define MY_ID 42

clang/test/Preprocessor/llvm-rc.rc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: llvm-rc -i%p/Inputs -Fo%t.res %s
2+
// RUN: llvm-readobj %t.res | FileCheck %s
3+
// CHECK: Resource type (int): RCDATA (ID 10)
4+
// CHECK: Resource name (int): 42
5+
#include "llvm-rc.h"
6+
MY_ID RCDATA {
7+
"a long string of data"
8+
}

clang/test/lit.cfg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
# suffixes: A list of file extensions to treat as test files.
2828
config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu', '.hip',
29-
'.ll', '.cl', '.clcpp', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs']
29+
'.ll', '.cl', '.clcpp', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs', '.rc']
3030

3131
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
3232
# subdirectories contain auxiliary inputs for various tests in their parent

llvm/test/tools/llvm-rc/absolute.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; RUN: touch %t.manifest
22
; RUN: echo "1 24 \"%t.manifest\"" > %t.rc
3-
; RUN: llvm-rc -- %t.rc
3+
; RUN: llvm-rc -no-preprocess -- %t.rc
44
;; On Windows, try stripping out the drive name from the absolute path,
55
;; and make sure the path still is found.
66
; RUN: cat %t.rc | sed 's/"[a-zA-Z]:/"/' > %t2.rc
7-
; RUN: llvm-rc -- %t2.rc
7+
; RUN: llvm-rc -no-preprocess -- %t2.rc

llvm/test/tools/llvm-rc/codepage.test

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llvm-rc /C 65001 /FO %t.utf8.res -- %p/Inputs/utf8.rc
1+
; RUN: llvm-rc -no-preprocess /C 65001 /FO %t.utf8.res -- %p/Inputs/utf8.rc
22
; RUN: llvm-readobj %t.utf8.res | FileCheck %s --check-prefix=UTF8
33

44
; UTF8: Resource type (int): STRINGTABLE (ID 6)
@@ -18,11 +18,11 @@
1818
; UTF8-NEXT: 0040: 00000000 |....|
1919
; UTF8-NEXT: )
2020

21-
; 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
21+
; 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
2222
; UTF8_ESCAPE: llvm-rc: Error in STRINGTABLE statement (ID 1):
2323
; UTF8_ESCAPE-NEXT: Unable to interpret single byte (195) as UTF-8
2424

25-
; RUN: llvm-rc /C 1252 /FO %t.cp1252.res -- %p/Inputs/cp1252.rc
25+
; RUN: llvm-rc -no-preprocess /C 1252 /FO %t.cp1252.res -- %p/Inputs/cp1252.rc
2626
; RUN: llvm-readobj %t.cp1252.res | FileCheck %s --check-prefix=CP1252
2727

2828
; CP1252: Resource type (int): STRINGTABLE (ID 6)

llvm/test/tools/llvm-rc/cpp-output.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llvm-rc /FO %t -- %p/Inputs/cpp-output.rc
1+
; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/cpp-output.rc
22
; RUN: llvm-readobj %t | FileCheck %s
33

44
; CHECK: Resource type (int): STRINGTABLE (ID 6)

llvm/test/tools/llvm-rc/flags.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llvm-rc /dry-run /FO %t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
2-
; RUN: llvm-rc /dry-run /FO%t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
1+
; RUN: llvm-rc -no-preprocess /dry-run /FO %t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
2+
; RUN: llvm-rc -no-preprocess /dry-run /FO%t -- %p/Inputs/empty.rc 2>&1 | FileCheck %s --allow-empty --check-prefix=FO
33

44
; FO-NOT: Exactly one input file should be provided.

llvm/test/tools/llvm-rc/helpmsg.test

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
; CHECK-NEXT: /I <value> Add an include path.
1616
; CHECK-NEXT: /LN <value> Set the default language name.
1717
; CHECK-NEXT: /L <value> Set the default language identifier.
18+
; CHECK-NEXT: /no-preprocess Don't try to preprocess the input file.
1819
; CHECK-NEXT: /N Null-terminate all strings in the string table.
1920
; CHECK-NEXT: /U <value> Undefine a symbol for the C preprocessor.
2021
; CHECK-NEXT: /V Be verbose.

llvm/test/tools/llvm-rc/include-paths.test

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
; Should find the bitmap if it is in the same folder as the rc file.
22
; RUN: rm -f %t.include.res
3-
; RUN: llvm-rc /FO %t.include.res -- %p/Inputs/include.rc
3+
; RUN: llvm-rc -no-preprocess /FO %t.include.res -- %p/Inputs/include.rc
44
; RUN: llvm-readobj %t.include.res | FileCheck --check-prefix=FOUND %s
55

66
; Try including files without quotes.
77
; RUN: rm -f %t.noquotes.res
8-
; RUN: llvm-rc /FO %t.noquotes.res -- %p/Inputs/include-noquotes.rc
8+
; RUN: llvm-rc -no-preprocess /FO %t.noquotes.res -- %p/Inputs/include-noquotes.rc
99
; RUN: llvm-readobj %t.noquotes.res | FileCheck --check-prefix=FOUND %s
1010

1111
; Should find the bitmap if the folder is explicitly specified.
1212
; RUN: rm -f %t.nested-include.res
13-
; RUN: llvm-rc /FO %t.nested-include.res /I %p/Inputs/nested -- %p/Inputs/deep-include.rc
13+
; RUN: llvm-rc -no-preprocess /FO %t.nested-include.res /I %p/Inputs/nested -- %p/Inputs/deep-include.rc
1414
; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
1515

1616
; The include dir can be specified via the INCLUDE env var too.
1717
; RUN: rm -f %t.nested-include.res
18-
; RUN: env INCLUDE=%p/Inputs/nested llvm-rc /FO %t.nested-include.res -- %p/Inputs/deep-include.rc
18+
; RUN: env INCLUDE=%p/Inputs/nested llvm-rc -no-preprocess /FO %t.nested-include.res -- %p/Inputs/deep-include.rc
1919
; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
2020

2121
; Specifying the /X option should make it ignore the INCLUDE variable.
2222
; RUN: rm -f %t.nested-include.res
23-
; RUN: not env INCLUDE=%p/Inputs/nested llvm-rc /X /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
23+
; RUN: not env INCLUDE=%p/Inputs/nested llvm-rc -no-preprocess /X /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
2424
; RUN: | FileCheck --check-prefix=MISSING %s
2525

2626
; Otherwise, it should not find the bitmap.
2727
; RUN: rm -f %t.nested-include.res
28-
; RUN: not llvm-rc /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
28+
; RUN: not llvm-rc -no-preprocess /FO %t.nested-include.res -- %p/Inputs/deep-include.rc 2>&1 \
2929
; RUN: | FileCheck --check-prefix=MISSING %s
3030

3131
; Should find the bitmap if the process's current working directory
@@ -34,7 +34,7 @@
3434
; failure of other tests if run first.
3535
; RUN: rm -f %t.nested-include.res
3636
; RUN: cd %p/Inputs/nested
37-
; RUN: llvm-rc /FO %t.nested-include.res -- %p/Inputs/include.rc
37+
; RUN: llvm-rc -no-preprocess /FO %t.nested-include.res -- %p/Inputs/include.rc
3838
; RUN: llvm-readobj %t.nested-include.res | FileCheck --check-prefix=FOUND %s
3939

4040
FOUND: Resource type (int): BITMAP (ID 2)

llvm/test/tools/llvm-rc/language.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
; RUN: llvm-rc /l 40A /FO %t.res -- %p/Inputs/language.rc
1+
; RUN: llvm-rc -no-preprocess /l 40A /FO %t.res -- %p/Inputs/language.rc
22
; RUN: llvm-readobj %t.res | FileCheck %s
3-
; RUN: llvm-rc /l40A /FO %t.res -- %p/Inputs/language.rc
3+
; RUN: llvm-rc -no-preprocess /l40A /FO %t.res -- %p/Inputs/language.rc
44
; RUN: llvm-readobj %t.res | FileCheck %s
55

66
; CHECK: Resource name (int): 1

llvm/test/tools/llvm-rc/memoryflags-stringtable.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llvm-rc /FO %t -- %p/Inputs/memoryflags-stringtable.rc
1+
; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/memoryflags-stringtable.rc
22
; RUN: llvm-readobj %t | FileCheck %s
33

44
; CHECK: Resource type (int): STRINGTABLE (ID 6)

llvm/test/tools/llvm-rc/memoryflags.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llvm-rc /FO %t -- %p/Inputs/memoryflags.rc
1+
; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/memoryflags.rc
22
; RUN: llvm-readobj %t | FileCheck %s
33

44
; CHECK: Resource type (int): CURSOR (ID 1)

llvm/test/tools/llvm-rc/not-expr.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llvm-rc /FO %t -- %p/Inputs/not-expr.rc
1+
; RUN: llvm-rc -no-preprocess /FO %t -- %p/Inputs/not-expr.rc
22
; RUN: llvm-readobj %t | FileCheck %s --check-prefix=NOTEXPR
33

44
; NOTEXPR: Resource type (int): DIALOG (ID 5)

llvm/test/tools/llvm-rc/parser-expr.test

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llvm-rc /dry-run /V -- %p/Inputs/parser-expr.rc | FileCheck %s
1+
; RUN: llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr.rc | FileCheck %s
22

33
; CHECK: Language: 5, Sublanguage: 1
44
; CHECK-NEXT: Language: 3, Sublanguage: 2
@@ -17,36 +17,36 @@
1717
; CHECK-NEXT: Language: 5, Sublanguage: 7
1818

1919

20-
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-binary-1.rc 2>&1 | FileCheck %s --check-prefix BINARY1
20+
; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-binary-1.rc 2>&1 | FileCheck %s --check-prefix BINARY1
2121

2222
; BINARY1: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got &
2323

2424

25-
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-binary-2.rc 2>&1 | FileCheck %s --check-prefix BINARY2
25+
; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-binary-2.rc 2>&1 | FileCheck %s --check-prefix BINARY2
2626

2727
; BINARY2: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got |
2828

2929

30-
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-binary-3.rc 2>&1 | FileCheck %s --check-prefix BINARY3
30+
; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-binary-3.rc 2>&1 | FileCheck %s --check-prefix BINARY3
3131

3232
; BINARY3: llvm-rc: Error parsing file: expected '-', '~', integer or '(', got +
3333

3434

35-
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-bad-unary.rc 2>&1 | FileCheck %s --check-prefix UNARY
35+
; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-bad-unary.rc 2>&1 | FileCheck %s --check-prefix UNARY
3636

3737
; UNARY: llvm-rc: Error parsing file: expected ',', got ~
3838

3939

40-
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-unbalanced-1.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED1
40+
; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-unbalanced-1.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED1
4141

4242
; UNBALANCED1: llvm-rc: Error parsing file: expected ')', got ,
4343

4444

45-
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-unbalanced-2.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED2
45+
; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-unbalanced-2.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED2
4646

4747
; UNBALANCED2: llvm-rc: Error parsing file: expected ',', got )
4848

4949

50-
; RUN: not llvm-rc /dry-run /V -- %p/Inputs/parser-expr-unbalanced-3.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED3
50+
; RUN: not llvm-rc -no-preprocess /dry-run /V -- %p/Inputs/parser-expr-unbalanced-3.rc 2>&1 | FileCheck %s --check-prefix UNBALANCED3
5151

5252
; UNBALANCED3: llvm-rc: Error parsing file: expected ',', got )

0 commit comments

Comments
 (0)