return y;
}
+struct Y {
+ struct X array[3];
+};
+
+enum { StartIndex = 1 };
+
+void test_members(int aval, int bval) {
+ struct Y y0 = { .array[StartIndex].b = bval, .array[StartIndex].a = aval };
+ __builtin_offsetof(struct Y, array[StartIndex].b);
+}
+
// RUN: c-index-test -test-load-source all %s -fblocks | FileCheck %s
// CHECK: load-exprs.c:1:13: TypedefDecl=T:1:13 (Definition) Extent=[1:13 - 1:14]
// CHECK: load-exprs.c:16:10: DeclRefExpr=z:13:17 Extent=[16:10 - 16:11]
// CHECK: load-exprs.c:17:10: DeclRefExpr= Extent=[17:10 - 17:11]
// CHECK: load-exprs.c:20:10: DeclRefExpr=y:11:15 Extent=[20:10 - 20:11]
+// CHECK: load-exprs.c:29:6: FunctionDecl=test_members:29:6 (Definition)
+// CHECK: load-exprs.c:31:29: TypeRef=struct Y:23:8 Extent=[31:29 - 31:30]
+// CHECK: load-exprs.c:31:32: MemberRef=array:24:12 Extent=[31:32 - 31:37]
+// CHECK: load-exprs.c:31:38: DeclRefExpr=StartIndex:27:8 Extent=[31:38 - 31:48]
+// CHECK: load-exprs.c:31:50: MemberRef=b:2:19 Extent=[31:50 - 31:51]
}
bool CursorVisitor::VisitOffsetOfExpr(OffsetOfExpr *E) {
- // FIXME: Visit fields as well?
+ // Visit the type into which we're computing an offset.
if (Visit(E->getTypeSourceInfo()->getTypeLoc()))
return true;
+
+ // Visit the components of the offsetof expression.
+ for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
+ typedef OffsetOfExpr::OffsetOfNode OffsetOfNode;
+ const OffsetOfNode &Node = E->getComponent(I);
+ switch (Node.getKind()) {
+ case OffsetOfNode::Array:
+ if (Visit(MakeCXCursor(E->getIndexExpr(Node.getArrayExprIndex()),
+ StmtParent, TU)))
+ return true;
+ break;
+
+ case OffsetOfNode::Field:
+ if (Visit(MakeCursorMemberRef(Node.getField(), Node.getRange().getEnd(),
+ TU)))
+ return true;
+ break;
+
+ case OffsetOfNode::Identifier:
+ case OffsetOfNode::Base:
+ continue;
+ }
+ }
- return VisitExpr(E);
+ return false;
}
bool CursorVisitor::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {