]> granicus.if.org Git - clang/commitdiff
Handle struct fields through the index-test tool.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 14 Jul 2009 03:18:40 +0000 (03:18 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 14 Jul 2009 03:18:40 +0000 (03:18 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75596 91177308-0d34-0410-b5e6-96231b3b80d8

test/Index/find-decls.c
test/Index/find-refs.c
test/Index/resolve-loc-input.c
test/Index/resolve-loc.c
test/Index/t1.c
tools/index-test/index-test.cpp

index eb3ff895e51051ab6c7d309665c85ab54a07f636..1fb1a65251e89bfd08b89b2914ac0986346217f1 100644 (file)
@@ -6,4 +6,10 @@
 // RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:5:47 -print-decls | count 1 &&
 // RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:5:47 -print-decls | grep 't1.c:5:12,' && 
 // RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:6:20 -print-decls | count 1 &&
-// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:6:20 -print-decls | grep 't1.c:3:19,'
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:6:20 -print-decls | grep 't1.c:3:19,' &&
+
+// field test
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:21:6 -print-decls | count 1 &&
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:21:6 -print-decls | grep 't1.c:12:7,' &&
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:22:21 -print-decls | count 1 &&
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:22:21 -print-decls | grep 't1.c:16:7,'
index 29bf6508057db19f0103d8d4491a98de2a351853..7f00bcf24e285d0c36f87985fb59e92a427291b1 100644 (file)
 // RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:5:30 -print-refs | count 3 &&
 // RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:5:30 -print-refs | grep 't1.c:5:27,' &&
 // RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:5:30 -print-refs | grep 't1.c:5:44,' &&
-// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:5:30 -print-refs | grep 't1.c:6:26,'
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:5:30 -print-refs | grep 't1.c:6:26,' &&
+
+// field test
+// FIXME: References point at the start of MemberExpr, make them point at the field instead.
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:12:7 -print-refs | count 1 &&
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:12:7 -print-refs | grep 't1.c:21:3,' &&
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:16:7 -print-refs | count 1 &&
+// RUN: index-test %t1.ast %t2.ast -point-at %S/t1.c:16:7 -print-refs | grep 't1.c:22:3,'
index c03dbb3951830cacc11c9455882c89daaf8de1d9..a36ae6726914b5c4d9814aeb5848daa6b814ac90 100644 (file)
@@ -8,3 +8,7 @@ void top_func_def(int param2) {
     int local_var2 = for_var + 1;
   }
 }
+
+struct S {
+  int field_var;
+};
index 1a6bf4a570da59ed611b22776599634f3ed12c30..7fd3ad5957da75df3254acf9bf0c4b61a942226b 100644 (file)
@@ -11,3 +11,6 @@
 // RUN: index-test %t.ast -point-at %S/resolve-loc-input.c:8:9 | grep local_var2 &&
 // RUN: index-test %t.ast -point-at %S/resolve-loc-input.c:8:30 | grep local_var2 &&
 // RUN: index-test %t.ast -point-at %S/resolve-loc-input.c:8:30 | grep 'for_var + 1' &&
+
+// fields test.
+// RUN: index-test %t.ast -point-at %S/resolve-loc-input.c:13:10 | grep field_var
index 1ff89ca34b6f2b4de18409d859f0ff6278eca5e6..17cdb7dc4ff68bfa68a06eafd5865f8b66a063c1 100644 (file)
@@ -7,3 +7,17 @@ void foo_func(int param1) {
   }
   bar_func();
 }
+
+struct S1 {
+  int x;
+};
+
+struct S2 {
+  int x;
+};
+
+void field_test(void) {
+  struct S1 s1;
+  s1.x = 0;
+  ((struct S2 *)0)->x = 0;
+}
index 815d0d0adf6d1798d904dd373f31c153533a5dd0..b7471a1c9d043054fdc0453cb526a23f6a93d5d2 100644 (file)
@@ -95,6 +95,8 @@ DisableFree("disable-free",
            llvm::cl::desc("Disable freeing of memory on exit"),
            llvm::cl::init(false));
 
+static bool HadErrors = false;
+
 static void ProcessDecl(Decl *D) {
   assert(D);
   llvm::raw_ostream &OS = llvm::outs();
@@ -155,10 +157,17 @@ static void ProcessASTLocation(ASTLocation ASTLoc, IndexProvider &IdxProvider) {
   if (ASTLoc.isStmt()) {
     if (DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(ASTLoc.getStmt()))
       D = RefExpr->getDecl();
+    else if (MemberExpr *ME = dyn_cast<MemberExpr>(ASTLoc.getStmt()))
+      D = ME->getMemberDecl();
   } else {
     D = ASTLoc.getDecl();
   }
-  assert(D);
+  
+  if (D == 0) {
+    llvm::errs() << "Error: Couldn't get a Decl out of the ASTLocation";
+    HadErrors = true;
+    return;
+  }
 
   Entity *Ent = Entity::get(D, IdxProvider.getProgram());
   // If there is no Entity associated with this Decl, it means that it's not
@@ -267,6 +276,9 @@ int main(int argc, char **argv) {
       ProcessASTLocation(ASTLoc, IdxProvider);
     }
   }
+  
+  if (HadErrors)
+    return 1;
 
   if (!DisableFree) {
     for (int i=0, e=TUnits.size(); i != e; ++i)