r317593 - [index] index field references in __builtin_offset

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 7 09:29:11 PST 2017


Author: arphaman
Date: Tue Nov  7 09:29:11 2017
New Revision: 317593

URL: http://llvm.org/viewvc/llvm-project?rev=317593&view=rev
Log:
[index] index field references in __builtin_offset

rdar://35109556

Modified:
    cfe/trunk/lib/Index/IndexBody.cpp
    cfe/trunk/test/Index/Core/index-source.cpp

Modified: cfe/trunk/lib/Index/IndexBody.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexBody.cpp?rev=317593&r1=317592&r2=317593&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexBody.cpp (original)
+++ cfe/trunk/lib/Index/IndexBody.cpp Tue Nov  7 09:29:11 2017
@@ -427,6 +427,17 @@ public:
 
     return true;
   }
+
+  bool VisitOffsetOfExpr(OffsetOfExpr *S) {
+    for (unsigned I = 0, E = S->getNumComponents(); I != E; ++I) {
+      const OffsetOfNode &Component = S->getComponent(I);
+      if (Component.getKind() == OffsetOfNode::Field)
+        IndexCtx.handleReference(Component.getField(), Component.getLocStart(),
+                                 Parent, ParentDC, SymbolRoleSet(), {});
+      // FIXME: Try to resolve dependent field references.
+    }
+    return true;
+  }
 };
 
 } // anonymous namespace

Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=317593&r1=317592&r2=317593&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Tue Nov  7 09:29:11 2017
@@ -525,3 +525,36 @@ struct rd33122110::Outer::Nested<int>;
 // CHECK-NEXT: RelCont | Nested | c:@N at rd33122110@S at Outer@S at Nested>#I
 // CHECK: [[@LINE-3]]:20 | struct/C++ | Outer | c:@N at rd33122110@S at Outer | <no-cgname> | Ref,RelCont | rel: 1
 // CHECK-NEXT: RelCont | Nested | c:@N at rd33122110@S at Outer@S at Nested>#I
+
+namespace index_offsetof {
+
+struct Struct {
+  int field;
+};
+
+struct Struct2 {
+  Struct array[4][2];
+};
+
+void foo() {
+  __builtin_offsetof(Struct, field);
+// CHECK: [[@LINE-1]]:30 | field/C | field | c:@N at index_offsetof@S at Struct@FI at field | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | foo | c:@N at index_offsetof@F at foo#
+  __builtin_offsetof(Struct2, array[1][0].field);
+// CHECK: [[@LINE-1]]:31 | field/C | array | c:@N at index_offsetof@S at Struct2@FI at array | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | foo | c:@N at index_offsetof@F at foo#
+// CHECK: [[@LINE-3]]:42 | field/C | field | c:@N at index_offsetof@S at Struct@FI at field | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | foo | c:@N at index_offsetof@F at foo#
+}
+
+#define OFFSET_OF_(X, Y) __builtin_offsetof(X, Y)
+
+class SubclassOffsetof : public Struct {
+  void foo() {
+    OFFSET_OF_(SubclassOffsetof, field);
+// CHECK: [[@LINE-1]]:34 | field/C | field | c:@N at index_offsetof@S at Struct@FI at field | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | foo | c:@N at index_offsetof@S at SubclassOffsetof@F at foo#
+  }
+};
+
+}




More information about the cfe-commits mailing list