[cfe-commits] r113556 - in /cfe/trunk: test/Index/load-exprs.c tools/libclang/CIndex.cpp
Douglas Gregor
dgregor at apple.com
Thu Sep 9 16:10:46 PDT 2010
Author: dgregor
Date: Thu Sep 9 18:10:46 2010
New Revision: 113556
URL: http://llvm.org/viewvc/llvm-project?rev=113556&view=rev
Log:
Add libclang visitation for __builtin_offsetof's components (fields
and array references).
Modified:
cfe/trunk/test/Index/load-exprs.c
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/test/Index/load-exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-exprs.c?rev=113556&r1=113555&r2=113556&view=diff
==============================================================================
--- cfe/trunk/test/Index/load-exprs.c (original)
+++ cfe/trunk/test/Index/load-exprs.c Thu Sep 9 18:10:46 2010
@@ -20,6 +20,17 @@
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]
@@ -52,4 +63,9 @@
// 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]
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=113556&r1=113555&r2=113556&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Sep 9 18:10:46 2010
@@ -1555,11 +1555,34 @@
}
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) {
More information about the cfe-commits
mailing list