Skip to content

Commit 153d363

Browse files
committed
[Clang] Wide delimiters ('{{{') for expect strings
Prior to this commit, it was impossible to use the simple string matching directives to look for most content that contains `{{`, such as: ``` // expected-note {{my_struct{{1}, 2}}} ``` Which would parse like so: ``` "nested" brace v // expected-note {{my_struct{{1}, 2}}} closes the nested brace ^ | trailing } ``` And the frontend would complain 'cannot find end ('}}') of expected'. At this snapshot, VerifyDiagnosticConsumer's parser now counts the opening braces and looks for a matching length of closing sigils, allowing the above to be written as: ``` // expected-note {{{my_struct{{1}, 2}}}} opening brace |-| |-| closing brace is '}}}', found here ^ ```
1 parent db9118f commit 153d363

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def err_verify_no_such_marker : Error<
166166
def err_verify_missing_start : Error<
167167
"cannot find start ('{{') of expected %0">;
168168
def err_verify_missing_end : Error<
169-
"cannot find end ('}}') of expected %0">;
169+
"cannot find end ('%1') of expected %0">;
170170
def err_verify_invalid_content : Error<
171171
"invalid expected %0: %1">;
172172
def err_verify_missing_regex : Error<

clang/lib/Frontend/VerifyDiagnosticConsumer.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,12 +612,19 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
612612
diag::err_verify_missing_start) << KindStr;
613613
continue;
614614
}
615+
llvm::SmallString<8> CloseBrace("}}");
616+
const char *const DelimBegin = PH.C;
615617
PH.Advance();
618+
// Count the number of opening braces for `string` kinds
619+
for (; !D.RegexKind && PH.Next("{"); PH.Advance())
620+
CloseBrace += '}';
616621
const char* const ContentBegin = PH.C; // mark content begin
617-
// Search for token: }}
618-
if (!PH.SearchClosingBrace("{{", "}}")) {
619-
Diags.Report(Pos.getLocWithOffset(PH.C-PH.Begin),
620-
diag::err_verify_missing_end) << KindStr;
622+
// Search for closing brace
623+
StringRef OpenBrace(DelimBegin, ContentBegin - DelimBegin);
624+
if (!PH.SearchClosingBrace(OpenBrace, CloseBrace)) {
625+
Diags.Report(Pos.getLocWithOffset(PH.C - PH.Begin),
626+
diag::err_verify_missing_end)
627+
<< KindStr << CloseBrace;
621628
continue;
622629
}
623630
const char* const ContentEnd = PH.P; // mark content end

clang/test/SemaCXX/static-assert-diagnostics.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ struct _arr {
2020
}
2121
};
2222

23-
// output: '{{2, 3, 4}} == {0, 3, 4}' (the `{{` breaks VerifyDiagnosticConsumer::ParseDirective)
24-
// expected-note@+1 {{evaluates to}}
23+
// expected-note@+1 {{{evaluates to '{{2, 3, 4}} == {0, 3, 4}'}}}
2524
static_assert(_arr{2, 3, 4} == a0.b); // expected-error {{failed}}
2625

2726
struct B {
@@ -41,8 +40,7 @@ struct C: A, B {
4140

4241
constexpr auto cc = C{A{1, {2, 3, 4}, 5}, B{7, 6}, C::E1};
4342

44-
// actually '{{1, {2, 3, 4}, 5}, {7, 6}, 0} == {{0, {0, 3, 4}, 5}, {5, 0}, 1}' (the `{{` breaks VerifyDiagnosticConsumer::ParseDirective)
45-
// expected-note@+1 {{evaluates to}}
43+
// expected-note@+1 {{{evaluates to '{{1, {2, 3, 4}, 5}, {7, 6}, 0} == {{0, {0, 3, 4}, 5}, {5, 0}, 1}'}}}
4644
static_assert(cc == C{a0, {5}, C::E2}); // expected-error {{failed}}
4745

4846
// this little guy? oh, I wouldn't worry about this little guy
@@ -83,8 +81,7 @@ struct V {
8381
};
8482
static_assert(V{1, 2, 3, 4} == V{1, 2, 3, 4});
8583

86-
// '{{1, 2, 3, 4}} == {{1, 2, 0, 4}}'
87-
// expected-note@+1 {{evaluates to}}
84+
// expected-note@+1 {{{evaluates to '{{1, 2, 3, 4}} == {{1, 2, 0, 4}}'}}}
8885
static_assert(V{1, 2, 3, 4} == V{1, 2, 0, 4}); // expected-error {{failed}}
8986

9087
constexpr auto v = (v4si){1, 2, 3, 4};
@@ -105,6 +102,5 @@ struct BV {
105102
}
106103
};
107104

108-
// '{{false, true, false, false, false, false, false, false}} == {{true, false, false, false, false, false, false, false}}'
109-
// expected-note@+1 {{evaluates to}}
105+
// expected-note@+1 {{{evaluates to '{{false, true, false, false, false, false, false, false}} == {{true, false, false, false, false, false, false, false}}'}}}
110106
static_assert(BV{{0, 1}} == BV{{1, 0}}); // expected-error {{failed}}

0 commit comments

Comments
 (0)