]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6291588> assertion failure: SourceManager.h line 489.
authorSteve Naroff <snaroff@apple.com>
Wed, 19 Nov 2008 21:15:47 +0000 (21:15 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 19 Nov 2008 21:15:47 +0000 (21:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59664 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteObjC.cpp
test/Rewriter/crash.m

index 804a891f6b6c45383954a459fb45adb7fcde66e6..a3ce8a8c569d48080f8075ce6dc2b49b2be21835 100644 (file)
@@ -1572,9 +1572,21 @@ bool RewriteObjC::needToScanForQualifiers(QualType T) {
 void RewriteObjC::RewriteObjCQualifiedInterfaceTypes(Expr *E) {
   QualType Type = E->getType();
   if (needToScanForQualifiers(Type)) {
-    SourceLocation Loc = E->getLocStart();
+    SourceLocation Loc, EndLoc;
+    
+    if (const CStyleCastExpr *ECE = dyn_cast<CStyleCastExpr>(E)) {
+      Loc = ECE->getLParenLoc();
+      EndLoc = ECE->getRParenLoc();
+    } else {
+      Loc = E->getLocStart();
+      EndLoc = E->getLocEnd();
+    }
+    // This will defend against trying to rewrite synthesized expressions.
+    if (Loc.isInvalid() || EndLoc.isInvalid())
+      return;
+
     const char *startBuf = SM->getCharacterData(Loc);
-    const char *endBuf = SM->getCharacterData(E->getLocEnd());
+    const char *endBuf = SM->getCharacterData(EndLoc);
     const char *startRef = 0, *endRef = 0;
     if (scanForProtocolRefs(startBuf, endBuf, startRef, endRef)) {
       // Get the locations of the startRef, endRef.
index 59f18f37c2c9e11843087bc001f6a5afb1c2ca63..2e34850e9684c2dd37798322d653cf3323b10722 100644 (file)
@@ -12,3 +12,14 @@ int main() {
     return 0;
 }
 
+// rdar://6291588
+@protocol A
+@end
+
+@interface Foo
+@end
+
+void func() {
+  id <A> obj = (id <A>)[Foo bar];
+}
+