Author: akirtzidis
Date: Mon Oct 8 18:08:41 2012
New Revision: 165456
URL: http://llvm.org/viewvc/llvm-project?rev=165456&view=rev
Log:
In VarDecl::getSourceRange() make sure to check that the source location
of the initializer is valid before using it.
Fixes rdar://12455002&12449015 where local variables of objc objects in ARC mode
were not annotated because of the ImplicitValueInitExpr initializer having
invalid
source range, resulting in the SourceRange of the VarDecl having invalid end
location.
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/Index/arc-annotate.m
Modified: cfe/trunk/lib/AST/Decl.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=165456&r1=165455&r2=165456&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Oct 8 18:08:41 2012
@@ -1204,8 +1204,11 @@
}
SourceRange VarDecl::getSourceRange() const {
- if (getInit())
- return SourceRange(getOuterLocStart(), getInit()->getLocEnd());
+ if (const Expr *Init = getInit()) {
+ SourceLocation InitEnd = Init->getLocEnd();
+ if (InitEnd.isValid())
+ return SourceRange(getOuterLocStart(), InitEnd);
+ }
return DeclaratorDecl::getSourceRange();
}
Modified: cfe/trunk/test/Index/arc-annotate.m
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/arc-annotate.m?rev=165456&r1=165455&r2=165456&view=diff
==============================================================================
--- cfe/trunk/test/Index/arc-annotate.m (original)
+++ cfe/trunk/test/Index/arc-annotate.m Mon Oct 8 18:08:41 2012
@@ -4,7 +4,12 @@
@property (unsafe_unretained, nonatomic) id third_property;
@end
-// RUN: c-index-test -test-annotate-tokens=%s:1:1:5:1 %s -fobjc-arc
-fobjc-nonfragile-abi | FileCheck %s
+void foo() {
+ A *avar;
+ avar = 0;
+}
+
+// RUN: c-index-test -test-annotate-tokens=%s:1:1:11:1 %s -fobjc-arc
-fobjc-nonfragile-abi | FileCheck %s
// CHECK: Punctuation: "@" [1:1 - 1:2] ObjCInterfaceDecl=A:1:12
// CHECK: Keyword: "interface" [1:2 - 1:11] ObjCInterfaceDecl=A:1:12
// CHECK: Identifier: "A" [1:12 - 1:13] ObjCInterfaceDecl=A:1:12
@@ -36,3 +41,17 @@
// CHECK: Punctuation: ")" [4:40 - 4:41] ObjCPropertyDecl=third_property:4:45
// CHECK: Identifier: "id" [4:42 - 4:44] TypeRef=id:0:0
// CHECK: Identifier: "third_property" [4:45 - 4:59]
ObjCPropertyDecl=third_property:4:45
+
+// CHECK: Identifier: "A" [8:3 - 8:4] ObjCClassRef=A:1:12
+// CHECK: Punctuation: "*" [8:5 - 8:6] VarDecl=avar:8:6 (Definition)
+// CHECK: Identifier: "avar" [8:6 - 8:10] VarDecl=avar:8:6 (Definition)
+// CHECK: Punctuation: ";" [8:10 - 8:11] DeclStmt=
+// CHECK: Identifier: "avar" [9:3 - 9:7] DeclRefExpr=avar:8:6
+// CHECK: Punctuation: "=" [9:8 - 9:9] BinaryOperator=
+// CHECK: Literal: "0" [9:10 - 9:11] IntegerLiteral=
+// CHECK: Punctuation: ";" [9:11 - 9:12] CompoundStmt=
+
+// RUN: c-index-test -file-refs-at=%s:8:8 %s -fobjc-arc -fobjc-nonfragile-abi
| FileCheck %s -check-prefix=CHECK-REFS
+// CHECK-REFS: VarDecl=avar:8:6 (Definition)
+// CHECK-REFS: VarDecl=avar:8:6 (Definition) =[8:6 - 8:10]
+// CHECK-REFS: DeclRefExpr=avar:8:6 =[9:3 - 9:7]
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits