Skip to content

Commit 9f169af

Browse files
author
Zachary Turner
committed
Make YAML quote forward slashes.
If you have the string /usr/bin, prior to this patch it would not be quoted by our YAML serializer. But a string like C:\src would be, due to the presence of a backslash. This makes the quoting rules of basically every single file path different depending on the path syntax (posix vs. Windows). While technically not required by the YAML specification to quote forward slashes, when the behavior of paths is inconsistent it makes it difficult to portably write FileCheck lines that will work with either kind of path. Differential Revision: https://reviews.llvm.org/D53169 llvm-svn: 344359
1 parent 9c54419 commit 9f169af

17 files changed

+48
-41
lines changed

clang/unittests/Tooling/DiagnosticsYamlTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,30 @@ TEST(DiagnosticsYamlTest, serializesDiagnostics) {
5858
YAML << TUD;
5959

6060
EXPECT_EQ("---\n"
61-
"MainSourceFile: path/to/source.cpp\n"
61+
"MainSourceFile: 'path/to/source.cpp'\n"
6262
"Diagnostics: \n"
6363
" - DiagnosticName: 'diagnostic#1\'\n"
6464
" Message: 'message #1'\n"
6565
" FileOffset: 55\n"
66-
" FilePath: path/to/source.cpp\n"
66+
" FilePath: 'path/to/source.cpp'\n"
6767
" Replacements: \n"
68-
" - FilePath: path/to/source.cpp\n"
68+
" - FilePath: 'path/to/source.cpp'\n"
6969
" Offset: 100\n"
7070
" Length: 12\n"
7171
" ReplacementText: 'replacement #1'\n"
7272
" - DiagnosticName: 'diagnostic#2'\n"
7373
" Message: 'message #2'\n"
7474
" FileOffset: 60\n"
75-
" FilePath: path/to/header.h\n"
75+
" FilePath: 'path/to/header.h'\n"
7676
" Replacements: \n"
77-
" - FilePath: path/to/header.h\n"
77+
" - FilePath: 'path/to/header.h'\n"
7878
" Offset: 62\n"
7979
" Length: 2\n"
8080
" ReplacementText: 'replacement #2'\n"
8181
" - DiagnosticName: 'diagnostic#3'\n"
8282
" Message: 'message #3'\n"
8383
" FileOffset: 72\n"
84-
" FilePath: path/to/source2.cpp\n"
84+
" FilePath: 'path/to/source2.cpp'\n"
8585
" Replacements: \n"
8686
"...\n",
8787
YamlContentStream.str());

clang/unittests/Tooling/ReplacementsYamlTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ TEST(ReplacementsYamlTest, serializesReplacements) {
3333

3434
// NOTE: If this test starts to fail for no obvious reason, check whitespace.
3535
ASSERT_STREQ("---\n"
36-
"MainSourceFile: /path/to/source.cpp\n"
36+
"MainSourceFile: '/path/to/source.cpp'\n"
3737
"Replacements: \n" // Extra whitespace here!
38-
" - FilePath: /path/to/file1.h\n"
38+
" - FilePath: '/path/to/file1.h'\n"
3939
" Offset: 232\n"
4040
" Length: 56\n"
4141
" ReplacementText: 'replacement #1'\n"
42-
" - FilePath: /path/to/file2.h\n"
42+
" - FilePath: '/path/to/file2.h'\n"
4343
" Offset: 301\n"
4444
" Length: 2\n"
4545
" ReplacementText: 'replacement #2'\n"

lld/test/mach-o/cstring-sections.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@ sections:
3636
# CHECK: content: [ 61, 62, 63, 00 ]
3737
# CHECK: merge: by-content
3838
# CHECK: section-choice: custom-required
39-
# CHECK: section-name: __TEXT/__objc_methname
39+
# CHECK: section-name: '__TEXT/__objc_methname'
4040
# CHECK: - scope: hidden
4141
# CHECK: type: c-string
4242
# CHECK: content: [ 64, 65, 66, 00 ]
4343
# CHECK: merge: by-content
4444
# CHECK: section-choice: custom-required
45-
# CHECK: section-name: __TEXT/__objc_methname
45+
# CHECK: section-name: '__TEXT/__objc_methname'
4646
# CHECK: - scope: hidden
4747
# CHECK: type: c-string
4848
# CHECK: content: [ 61, 62, 63, 00 ]
4949
# CHECK: merge: by-content
5050
# CHECK: section-choice: custom-required
51-
# CHECK: section-name: __TEXT/__objc_classname
51+
# CHECK: section-name: '__TEXT/__objc_classname'
5252
# CHECK: - scope: hidden
5353
# CHECK: type: c-string
5454
# CHECK: content: [ 67, 68, 69, 00 ]
5555
# CHECK: merge: by-content
5656
# CHECK: section-choice: custom-required
57-
# CHECK: section-name: __TEXT/__objc_classname
57+
# CHECK: section-name: '__TEXT/__objc_classname'
5858
# CHECK: - scope: hidden
5959
# CHECK: type: c-string
6060
# CHECK: content: [ 61, 62, 63, 00 ]

lld/test/mach-o/parse-data-relocs-x86_64.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,6 @@ page-size: 0x00000000
367367
# CHECK: type: unknown
368368
# CHECK: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
369369
# CHECK: section-choice: custom-required
370-
# CHECK: section-name: __DATA/__custom
370+
# CHECK: section-name: '__DATA/__custom'
371371
# CHECK: dead-strip: never
372372

lld/test/mach-o/parse-data.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,5 @@ global-symbols:
115115
# CHECK: type: unknown
116116
# CHECK: content: [ 01, 02, 03, 04, 05, 06, 07, 08 ]
117117
# CHECK: section-choice: custom-required
118-
# CHECK: section-name: __CUST/__custom
118+
# CHECK: section-name: '__CUST/__custom'
119119

lld/test/mach-o/sectcreate.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
# CHECK: type: sectcreate
99
# CHECK: content: [ 68, 65, 6C, 6C, 6F, 0A ]
1010
# CHECK: section-choice: custom-required
11-
# CHECK: section-name: __DATA/__data
11+
# CHECK: section-name: '__DATA/__data'
1212
# CHECK: dead-strip: never

llvm/include/llvm/Support/YAMLTraits.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ inline QuotingType needsQuotes(StringRef S) {
578578
// Safe scalar characters.
579579
case '_':
580580
case '-':
581-
case '/':
582581
case '^':
583582
case '.':
584583
case ',':
@@ -595,6 +594,12 @@ inline QuotingType needsQuotes(StringRef S) {
595594
// DEL (0x7F) are excluded from the allowed character range.
596595
case 0x7F:
597596
return QuotingType::Double;
597+
// Forward slash is allowed to be unquoted, but we quote it anyway. We have
598+
// many tests that use FileCheck against YAML output, and this output often
599+
// contains paths. If we quote backslashes but not forward slashes then
600+
// paths will come out either quoted or unquoted depending on which platform
601+
// the test is run on, making FileCheck comparisons difficult.
602+
case '/':
598603
default: {
599604
// C0 control block (0x0 - 0x1F) is excluded from the allowed character
600605
// range.

llvm/test/CodeGen/AArch64/arm64-spill-remarks.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
; YAML: --- !Missed
3939
; YAML: Pass: regalloc
4040
; YAML: Name: LoopSpillReload
41-
; YAML: DebugLoc: { File: /tmp/kk.c, Line: 3, Column: 20 }
41+
; YAML: DebugLoc: { File: '/tmp/kk.c', Line: 3, Column: 20 }
4242
; YAML: Function: fpr128
4343
; YAML: Hotness: 300
4444
; YAML: Args:
@@ -51,7 +51,7 @@
5151
; YAML: --- !Missed
5252
; YAML: Pass: regalloc
5353
; YAML: Name: LoopSpillReload
54-
; YAML: DebugLoc: { File: /tmp/kk.c, Line: 2, Column: 20 }
54+
; YAML: DebugLoc: { File: '/tmp/kk.c', Line: 2, Column: 20 }
5555
; YAML: Function: fpr128
5656
; YAML: Hotness: 30000
5757
; YAML: Args:
@@ -64,7 +64,7 @@
6464
; YAML: --- !Missed
6565
; YAML: Pass: regalloc
6666
; YAML: Name: LoopSpillReload
67-
; YAML: DebugLoc: { File: /tmp/kk.c, Line: 1, Column: 20 }
67+
; YAML: DebugLoc: { File: '/tmp/kk.c', Line: 1, Column: 20 }
6868
; YAML: Function: fpr128
6969
; YAML: Hotness: 300
7070
; YAML: Args:
@@ -79,7 +79,7 @@
7979
; THRESHOLD_YAML: --- !Missed
8080
; THRESHOLD_YAML: Pass: regalloc
8181
; THRESHOLD_YAML: Name: LoopSpillReload
82-
; THRESHOLD_YAML: DebugLoc: { File: /tmp/kk.c, Line: 2, Column: 20 }
82+
; THRESHOLD_YAML: DebugLoc: { File: '/tmp/kk.c', Line: 2, Column: 20 }
8383
; THRESHOLD_YAML: Function: fpr128
8484
; THRESHOLD_YAML: Hotness: 30000
8585
; THRESHOLD_YAML: Args:

llvm/test/ObjectYAML/MachO/DWARF-BigEndian.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ DWARF:
376376
#CHECK: DWARF:
377377
#CHECK: debug_str:
378378
#CHECK: - 'clang version 4.0.0 (trunk 290181) (llvm/trunk 290209)'
379-
#CHECK: - ../compiler-rt/lib/builtins/absvdi2.c
380-
#CHECK: - /Users/cbieneman/dev/open-source/llvm-build-rel
379+
#CHECK: - '../compiler-rt/lib/builtins/absvdi2.c'
380+
#CHECK: - '/Users/cbieneman/dev/open-source/llvm-build-rel'
381381
#CHECK: - int
382382
#CHECK: - di_int
383383
#CHECK: - long long int

llvm/test/ObjectYAML/MachO/DWARF-LittleEndian.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ DWARF:
365365
#CHECK: DWARF:
366366
#CHECK: debug_str:
367367
#CHECK: - 'clang version 4.0.0 (trunk 290181) (llvm/trunk 290209)'
368-
#CHECK: - ../compiler-rt/lib/builtins/absvdi2.c
369-
#CHECK: - /Users/cbieneman/dev/open-source/llvm-build-rel
368+
#CHECK: - '../compiler-rt/lib/builtins/absvdi2.c'
369+
#CHECK: - '/Users/cbieneman/dev/open-source/llvm-build-rel'
370370
#CHECK: - int
371371
#CHECK: - di_int
372372
#CHECK: - long long int

llvm/test/ObjectYAML/MachO/DWARF-debug_str.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ DWARF:
257257
#CHECK: - ''
258258
#CHECK: - 'clang version 4.0.0 (trunk 288677) (llvm/trunk 288676)'
259259
#CHECK: - hello_world.c
260-
#CHECK: - /Users/cbieneman/dev/open-source/llvm-build-rel
260+
#CHECK: - '/Users/cbieneman/dev/open-source/llvm-build-rel'
261261
#CHECK: - main
262262
#CHECK: - argc
263263
#CHECK: - argv

llvm/test/ObjectYAML/MachO/dylib_dylinker_command.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ LoadCommands:
4040
#CHECK: - cmd: LC_LOAD_DYLINKER
4141
#CHECK: cmdsize: 32
4242
#CHECK: name: 12
43-
#CHECK: PayloadString: /usr/lib/dyld
43+
#CHECK: PayloadString: '/usr/lib/dyld'
4444
#CHECK: ZeroPadBytes: 7
4545
#CHECK: - cmd: LC_LOAD_DYLIB
4646
#CHECK: cmdsize: 48
@@ -58,5 +58,5 @@ LoadCommands:
5858
#CHECK: timestamp: 2
5959
#CHECK: current_version: 80349697
6060
#CHECK: compatibility_version: 65536
61-
#CHECK: PayloadString: /usr/lib/libSystem.B.dylib
61+
#CHECK: PayloadString: '/usr/lib/libSystem.B.dylib'
6262
#CHECK: ZeroPadBytes: 6

llvm/test/Other/size-remarks.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
; CGSCC-NEXT: Name: IRSizeChange
3333
; CGSCC-NEXT: Function:
3434
; CGSCC-NEXT: Args:
35-
; CGSCC-NEXT: - Pass: Function Integration/Inlining
35+
; CGSCC-NEXT: - Pass: 'Function Integration/Inlining'
3636
; CGSCC-NEXT: - String: ': IR instruction count changed from '
3737
; CGSCC-NEXT: - IRInstrsBefore: '[[ORIG]]'
3838
; CGSCC-NEXT: - String: ' to '
@@ -44,7 +44,7 @@
4444
; CGSCC-NEXT: Name: FunctionIRSizeChange
4545
; CGSCC-NEXT: Function:
4646
; CGSCC-NEXT: Args:
47-
; CGSCC-NEXT: - Pass: Function Integration/Inlining
47+
; CGSCC-NEXT: - Pass: 'Function Integration/Inlining'
4848
; CGSCC-NEXT: - String: ': Function: '
4949
; CGSCC-NEXT: - Function: bar
5050
; CGSCC-NEXT: - String: ': IR instruction count changed from '

llvm/test/Transforms/GVN/opt-remarks.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@
4949
; YAML-NEXT: --- !Missed
5050
; YAML-NEXT: Pass: gvn
5151
; YAML-NEXT: Name: LoadClobbered
52-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 3, Column: 3 }
52+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 3, Column: 3 }
5353
; YAML-NEXT: Function: may_alias
5454
; YAML-NEXT: Args:
5555
; YAML-NEXT: - String: 'load of type '
5656
; YAML-NEXT: - Type: i32
5757
; YAML-NEXT: - String: ' not eliminated'
5858
; YAML-NEXT: - String: ' in favor of '
5959
; YAML-NEXT: - OtherAccess: load
60-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 1, Column: 13 }
60+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 1, Column: 13 }
6161
; YAML-NEXT: - String: ' because it is clobbered by '
6262
; YAML-NEXT: - ClobberedBy: store
63-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 2, Column: 10 }
63+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 2, Column: 10 }
6464
; YAML-NEXT: ...
6565

6666
define i32 @arg(i32* %p, i32 %i) {

llvm/test/Transforms/Inline/optimization-remarks-passed-yaml.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
; YAML: --- !Passed
2323
; YAML-NEXT: Pass: inline
2424
; YAML-NEXT: Name: Inlined
25-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 4, Column: 10 }
25+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 4, Column: 10 }
2626
; YAML-NEXT: Function: bar
2727
; YAML-NEXT: Hotness: 30
2828
; YAML-NEXT: Args:
2929
; YAML-NEXT: - Callee: foo
30-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 1, Column: 0 }
30+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 1, Column: 0 }
3131
; YAML-NEXT: - String: ' inlined into '
3232
; YAML-NEXT: - Caller: bar
33-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 3, Column: 0 }
33+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 3, Column: 0 }
3434
; YAML-NEXT: - String: ' with '
3535
; YAML-NEXT: - String: '(cost='
3636
; YAML-NEXT: - Cost: '{{[0-9\-]+}}'

llvm/test/Transforms/Inline/optimization-remarks-yaml.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@
5252
; YAML: --- !Missed
5353
; YAML-NEXT: Pass: inline
5454
; YAML-NEXT: Name: NoDefinition
55-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 5, Column: 10 }
55+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 5, Column: 10 }
5656
; YAML-NEXT: Function: baz
5757
; YAML-NEXT: Hotness: 30
5858
; YAML-NEXT: Args:
5959
; YAML-NEXT: - Callee: foo
6060
; YAML-NEXT: - String: ' will not be inlined into '
6161
; YAML-NEXT: - Caller: baz
62-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 4, Column: 0 }
62+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 4, Column: 0 }
6363
; YAML-NEXT: - String: ' because its definition is unavailable'
6464
; YAML-NEXT: ...
6565
; YAML-NEXT: --- !Missed
6666
; YAML-NEXT: Pass: inline
6767
; YAML-NEXT: Name: NoDefinition
68-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 5, Column: 18 }
68+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 5, Column: 18 }
6969
; YAML-NEXT: Function: baz
7070
; YAML-NEXT: Hotness: 30
7171
; YAML-NEXT: Args:
7272
; YAML-NEXT: - Callee: bar
7373
; YAML-NEXT: - String: ' will not be inlined into '
7474
; YAML-NEXT: - Caller: baz
75-
; YAML-NEXT: DebugLoc: { File: /tmp/s.c, Line: 4, Column: 0 }
75+
; YAML-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 4, Column: 0 }
7676
; YAML-NEXT: - String: ' because its definition is unavailable'
7777
; YAML-NEXT: ...
7878

llvm/unittests/Support/YAMLIOTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,9 @@ TEST(YAMLIO, TestEscaped) {
25432543
// Single quote
25442544
TestEscaped("@abc@", "'@abc@'");
25452545
// No quote
2546-
TestEscaped("abc/", "abc/");
2546+
TestEscaped("abc", "abc");
2547+
// Forward slash quoted
2548+
TestEscaped("abc/", "'abc/'");
25472549
// Double quote non-printable
25482550
TestEscaped("\01@abc@", "\"\\x01@abc@\"");
25492551
// Double quote inside single quote

0 commit comments

Comments
 (0)