r317599 - [refactor] rename field references in __builtin_offsetof

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 7 10:30:23 PST 2017


Author: arphaman
Date: Tue Nov  7 10:30:23 2017
New Revision: 317599

URL: http://llvm.org/viewvc/llvm-project?rev=317599&view=rev
Log:
[refactor] rename field references in __builtin_offsetof

rdar://33875453

Added:
    cfe/trunk/test/Refactor/LocalRename/BuiltinOffsetof.cpp
Modified:
    cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h

Modified: cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h?rev=317599&r1=317598&r2=317599&view=diff
==============================================================================
--- cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h (original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h Tue Nov  7 10:30:23 2017
@@ -70,6 +70,18 @@ public:
     return visit(Expr->getFoundDecl().getDecl(), Expr->getMemberLoc());
   }
 
+  bool VisitOffsetOfExpr(const OffsetOfExpr *S) {
+    for (unsigned I = 0, E = S->getNumComponents(); I != E; ++I) {
+      const OffsetOfNode &Component = S->getComponent(I);
+      if (Component.getKind() == OffsetOfNode::Field) {
+        if (!visit(Component.getField(), Component.getLocEnd()))
+          return false;
+      }
+      // FIXME: Try to resolve dependent field references.
+    }
+    return true;
+  }
+
   // Other visitors:
 
   bool VisitTypeLoc(const TypeLoc Loc) {

Added: cfe/trunk/test/Refactor/LocalRename/BuiltinOffsetof.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Refactor/LocalRename/BuiltinOffsetof.cpp?rev=317599&view=auto
==============================================================================
--- cfe/trunk/test/Refactor/LocalRename/BuiltinOffsetof.cpp (added)
+++ cfe/trunk/test/Refactor/LocalRename/BuiltinOffsetof.cpp Tue Nov  7 10:30:23 2017
@@ -0,0 +1,32 @@
+// RUN: clang-refactor local-rename -selection=test:%s -new-name=bar %s -- | grep -v CHECK | FileCheck %s
+
+struct Struct {
+  int /*range f=*/field;
+};
+
+struct Struct2 {
+  Struct /*range array=*/array[4][2];
+};
+
+void foo() {
+  (void)__builtin_offsetof(Struct, /*range f=*/field);
+  (void)__builtin_offsetof(Struct2, /*range array=*/array[1][0]./*range f=*/field);
+}
+
+#define OFFSET_OF_(X, Y) __builtin_offsetof(X, Y)
+
+class SubclassOffsetof : public Struct {
+  void foo() {
+    (void)OFFSET_OF_(SubclassOffsetof, field);
+  }
+};
+
+// CHECK: 2 'array' results:
+// CHECK: Struct /*range array=*/bar[4][2];
+// CHECK: __builtin_offsetof(Struct2, /*range array=*/bar[1][0]./*range f=*/field);
+
+// CHECK: 3 'f' results:
+// CHECK: int /*range f=*/bar;
+// CHECK: __builtin_offsetof(Struct, /*range f=*/bar);
+// CHECK-NEXT: __builtin_offsetof(Struct2, /*range array=*/array[1][0]./*range f=*/bar);
+// CHECK: OFFSET_OF_(SubclassOffsetof, bar);




More information about the cfe-commits mailing list