the crash I reported and fixed earlier ( http://lists.cs.uiuc.edu/pipermail/cfe-dev/2007-December/000745.html ) happened because `Tok.getIdentifierInfo()` sometimes returns 0.
These conditions are not clearly documented in Token.h, and even if it was documented functions that may or may not return 0 are generally error prone. So I grepped clang for calls to `getIdentifierInfo()`. I found two places where this function was not handled correctly. Tests to reproduce the crashes and makeshift patches are attached (Someone familiar with the code needs to look at the FIXMEs in the patch. Problems where related to ObjC's @try/@catch and ObjC2 @interface prefixes).
(Why is it a good idea to treat stuff like @try as two tokens instead of one?)
Furthermore, I'd suggest to at least use an assert if you know that `getIdentifierInfo()` can't return 0 and rely on it. Doing an `assert(Tok.getIdentifierInfo() && "foo always has ident info")` serves as good documentation.
In the following places it was not immediately clear to me why the code is valid and `getIdentifierInfo` can't possibly return 0 (line numbers relative to rev 45360):
377 (one of the bugs, fixed with the patch
325 (but only because of strange identation because of tabs instead of spaces -- fixed in the attached patch as well)
1130 (one of the bugs, fixed with the patch)
1164 (one of the bugs, fixed with the patch)
Even better than adding asserts in these lines is to catch this problem with the compiler (for example, by putting `getIdentifierInfo()` in a subclass and never let it return 0. Then you _have_ to check for the right token type to call the method), but that's a bit of work
An unrelated crash that I found on the way is:
[a bla:0 6:7];
(crashes somewhere in sema, something like this should be put in test/Parse/objc-messaging-1.m)
And here's an inconsistency with gcc:
int @interface bla ; // ?? this is valid objc?
I have no idea what this code is supposed to do, but it doesn't warn with clang but doesn't even compile with gcc.
ps: I also converted a few tabs to spaces
crashes.patch (7.08 KB)