[cfe-commits] r59925 - in /cfe/trunk: Driver/DiagChecker.cpp test/Analysis/CheckNSError.m test/Sema/decl-invalid.c test/Sema/vla.c test/SemaObjC/string.m
Chris Lattner
sabre at nondot.org
Sun Nov 23 17:28:18 PST 2008
Author: lattner
Date: Sun Nov 23 19:28:17 2008
New Revision: 59925
URL: http://llvm.org/viewvc/llvm-project?rev=59925&view=rev
Log:
Rewrite FindDiagnostics to be more strict about the formatting of the
expected-foo strings. Now the only allowed characters between
expected-error and {{ is whitespace.
Modified:
cfe/trunk/Driver/DiagChecker.cpp
cfe/trunk/test/Analysis/CheckNSError.m
cfe/trunk/test/Sema/decl-invalid.c
cfe/trunk/test/Sema/vla.c
cfe/trunk/test/SemaObjC/string.m
Modified: cfe/trunk/Driver/DiagChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/DiagChecker.cpp?rev=59925&r1=59924&r2=59925&view=diff
==============================================================================
--- cfe/trunk/Driver/DiagChecker.cpp (original)
+++ cfe/trunk/Driver/DiagChecker.cpp Sun Nov 23 19:28:17 2008
@@ -47,43 +47,65 @@
/// FindDiagnostics - Go through the comment and see if it indicates expected
/// diagnostics. If so, then put them in a diagnostic list.
///
-static void FindDiagnostics(const std::string &Comment,
+static void FindDiagnostics(const char *CommentStart, unsigned CommentLen,
DiagList &ExpectedDiags,
- Preprocessor &PP,
- SourceLocation Pos,
- const char * const ExpectedStr) {
- SourceManager &SourceMgr = PP.getSourceManager();
+ Preprocessor &PP, SourceLocation Pos,
+ const char *ExpectedStr) {
+ const char *CommentEnd = CommentStart+CommentLen;
+ unsigned ExpectedStrLen = strlen(ExpectedStr);
- // Find all expected diagnostics.
- typedef std::string::size_type size_type;
- size_type ColNo = 0;
-
- for (;;) {
- ColNo = Comment.find(ExpectedStr, ColNo);
- if (ColNo == std::string::npos) break;
-
- size_type OpenDiag = Comment.find("{{", ColNo);
-
- if (OpenDiag == std::string::npos) {
- EmitError(PP, Pos,
- "cannot find start ('{{') of expected diagnostic string");
- return;
+ // Find all expected-foo diagnostics in the string and add them to
+ // ExpectedDiags.
+ while (CommentStart != CommentEnd) {
+ CommentStart = std::find(CommentStart, CommentEnd, 'e');
+ if (unsigned(CommentEnd-CommentStart) < ExpectedStrLen) return;
+
+ // If this isn't expected-foo, ignore it.
+ if (memcmp(CommentStart, ExpectedStr, ExpectedStrLen)) {
+ ++CommentStart;
+ continue;
}
+
+ CommentStart += ExpectedStrLen;
+
+ // Skip whitespace.
+ while (CommentStart != CommentEnd &&
+ isspace(CommentStart[0]))
+ ++CommentStart;
+
+ // We should have a {{ now.
+ if (CommentEnd-CommentStart < 2 ||
+ CommentStart[0] != '{' || CommentStart[1] != '{') {
+ if (std::find(CommentStart, CommentEnd, '{') != CommentEnd)
+ EmitError(PP, Pos, "bogus characters before '{{' in expected string");
+ else
+ EmitError(PP, Pos, "cannot find start ('{{') of expected string");
+ return;
+ }
+ CommentStart += 2;
- OpenDiag += 2;
- size_type CloseDiag = Comment.find("}}", OpenDiag);
+ // Find the }}.
+ const char *ExpectedEnd = CommentStart;
+ while (1) {
+ ExpectedEnd = std::find(ExpectedEnd, CommentEnd, '}');
+ if (CommentEnd-ExpectedEnd < 2) {
+ EmitError(PP, Pos, "cannot find end ('}}') of expected string");
+ return;
+ }
+
+ if (ExpectedEnd[1] == '}')
+ break;
- if (CloseDiag == std::string::npos) {
- EmitError(PP, Pos,"cannot find end ('}}') of expected diagnostic string");
- return;
+ ++ExpectedEnd; // Skip over singular }'s
}
- std::string Msg(Comment.substr(OpenDiag, CloseDiag - OpenDiag));
- size_type FindPos;
+ std::string Msg(CommentStart, ExpectedEnd);
+ std::string::size_type FindPos;
while ((FindPos = Msg.find("\\n")) != std::string::npos)
Msg.replace(FindPos, 2, "\n");
ExpectedDiags.push_back(std::make_pair(Pos, Msg));
- ColNo = CloseDiag + 2;
+
+ CommentStart = ExpectedEnd;
}
}
@@ -113,17 +135,19 @@
if (!Tok.is(tok::comment)) continue;
std::string Comment = PP.getSpelling(Tok);
+ if (Comment.empty()) continue;
+
// Find all expected errors.
- FindDiagnostics(Comment, ExpectedErrors, PP,
+ FindDiagnostics(&Comment[0], Comment.size(), ExpectedErrors, PP,
Tok.getLocation(), "expected-error");
// Find all expected warnings.
- FindDiagnostics(Comment, ExpectedWarnings, PP,
+ FindDiagnostics(&Comment[0], Comment.size(), ExpectedWarnings, PP,
Tok.getLocation(), "expected-warning");
// Find all expected notes.
- FindDiagnostics(Comment, ExpectedNotes, PP,
+ FindDiagnostics(&Comment[0], Comment.size(), ExpectedNotes, PP,
Tok.getLocation(), "expected-note");
};
}
Modified: cfe/trunk/test/Analysis/CheckNSError.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/CheckNSError.m?rev=59925&r1=59924&r2=59925&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/CheckNSError.m (original)
+++ cfe/trunk/test/Analysis/CheckNSError.m Sun Nov 23 19:28:17 2008
@@ -20,8 +20,8 @@
@end
@implementation A
-- (void)myMethodWhichMayFail:(NSError **)error { // expected-warning: {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occured.}}
- *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning: {{Potential null dereference.}}
+- (void)myMethodWhichMayFail:(NSError **)error { // expected-warning {{Method accepting NSError** should have a non-void return value to indicate whether or not an error occured.}}
+ *error = [NSError errorWithDomain:@"domain" code:1 userInfo:0]; // expected-warning {{Potential null dereference.}}
}
- (BOOL)myMethodWhichMayFail2:(NSError **)error { // no-warning
@@ -33,8 +33,8 @@
struct __CFError {};
typedef struct __CFError* CFErrorRef;
-void foo(CFErrorRef* error) { // expected-warning{{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occured.}}
- *error = 0; // expected-warning{{Potential null dereference.}}
+void foo(CFErrorRef* error) { // expected-warning {{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occured.}}
+ *error = 0; // expected-warning {{Potential null dereference.}}
}
int bar(CFErrorRef* error) {
Modified: cfe/trunk/test/Sema/decl-invalid.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/decl-invalid.c?rev=59925&r1=59924&r2=59925&view=diff
==============================================================================
--- cfe/trunk/test/Sema/decl-invalid.c (original)
+++ cfe/trunk/test/Sema/decl-invalid.c Sun Nov 23 19:28:17 2008
@@ -1,11 +1,11 @@
// RUN: clang %s -fsyntax-only -verify
-typedef union <anonymous> __mbstate_t; // expected-error: {{declaration of anonymous union must be a definition}}
+typedef union <anonymous> __mbstate_t; // expected-error {{declaration of anonymous union must be a definition}}
// PR2017
void x();
int a() {
- int r[x()]; // expected-error: {{size of array has non-integer type 'void'}}
+ int r[x()]; // expected-error {{size of array has non-integer type 'void'}}
}
Modified: cfe/trunk/test/Sema/vla.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vla.c?rev=59925&r1=59924&r2=59925&view=diff
==============================================================================
--- cfe/trunk/test/Sema/vla.c (original)
+++ cfe/trunk/test/Sema/vla.c Sun Nov 23 19:28:17 2008
@@ -14,5 +14,5 @@
}
// PR3048
-int x = sizeof(struct{char qq[x];}); // expected-error {{fields must have a constant size}
+int x = sizeof(struct{char qq[x];}); // expected-error {{fields must have a constant size}}
Modified: cfe/trunk/test/SemaObjC/string.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/string.m?rev=59925&r1=59924&r2=59925&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/string.m (original)
+++ cfe/trunk/test/SemaObjC/string.m Sun Nov 23 19:28:17 2008
@@ -11,5 +11,5 @@
id s = @"123"; // simple
id t = @"123" @"456"; // concat
-id u = @"123" @ blah; // expected-error: {{unexpected token}}
+id u = @"123" @ blah; // expected-error {{unexpected token}}
More information about the cfe-commits
mailing list