Skip to content

Commit 4e8144a

Browse files
committed
[verify] Add support for location markers in directives.
A marker (matching /#[A-Za-z0-9_-]/) is specified by attaching a comment containing the marker to the line at which the diagnostic is expected, and then can be referenced from an expected-* directive after an @: foo // #1 // expected-error@#1 {{undeclared identifier 'foo'}} The intent is for markers to be used in situations where relative line numbers are currently used, to avoid the need to renumber when the test case is rearranged. llvm-svn: 358326
1 parent e03301a commit 4e8144a

File tree

5 files changed

+334
-145
lines changed

5 files changed

+334
-145
lines changed

clang/include/clang/Basic/DiagnosticFrontendKinds.td

+6
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ def err_verify_missing_file : Error<
121121
"file '%0' could not be located in expected %1">;
122122
def err_verify_invalid_range : Error<
123123
"invalid range following '-' in expected %0">;
124+
def err_verify_ambiguous_marker : Error<
125+
"reference to marker '%0' is ambiguous">;
126+
def note_verify_ambiguous_marker : Note<
127+
"ambiguous marker '%0' is defined here">;
128+
def err_verify_no_such_marker : Error<
129+
"use of undefined marker '%0'">;
124130
def err_verify_missing_start : Error<
125131
"cannot find start ('{{') of expected %0">;
126132
def err_verify_missing_end : Error<

clang/include/clang/Frontend/VerifyDiagnosticConsumer.h

+16
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ class TextDiagnosticBuffer;
8181
/// the included file is, for example, a system header where the actual line
8282
/// number may change and is not critical).
8383
///
84+
/// As an alternative to specifying a fixed line number, the location of a
85+
/// diagnostic can instead be indicated by a marker of the form "#<marker>".
86+
/// Markers are specified by including them in a comment, and then referenced
87+
/// by appending the marker to the diagnostic with "@#<marker>":
88+
///
89+
/// \code
90+
/// #warning some text // #1
91+
/// // expected-warning@#1 {{some text}}
92+
/// \endcode
93+
///
94+
/// The name of a marker used in a directive must be unique within the
95+
/// compilation.
96+
///
8497
/// The simple syntax above allows each specification to match exactly one
8598
/// error. You can use the extended syntax to customize this. The extended
8699
/// syntax is "expected-<type> <n> {{diag text}}", where \<type> is one of
@@ -212,11 +225,14 @@ class VerifyDiagnosticConsumer: public DiagnosticConsumer,
212225
HasOtherExpectedDirectives
213226
};
214227

228+
class MarkerTracker;
229+
215230
private:
216231
DiagnosticsEngine &Diags;
217232
DiagnosticConsumer *PrimaryClient;
218233
std::unique_ptr<DiagnosticConsumer> PrimaryClientOwner;
219234
std::unique_ptr<TextDiagnosticBuffer> Buffer;
235+
std::unique_ptr<MarkerTracker> Markers;
220236
const Preprocessor *CurrentPreprocessor = nullptr;
221237
const LangOptions *LangOpts = nullptr;
222238
SourceManager *SrcManager = nullptr;

0 commit comments

Comments
 (0)