From afbf3127cbdebc7d3d8711c51b1d013afa57e849 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 29 Jul 2010 18:16:10 +0000 Subject: [PATCH] Implement PCH support for offsetof(base-specifier). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109785 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/PCHReaderStmt.cpp | 8 +++++--- lib/Frontend/PCHWriterStmt.cpp | 3 +-- test/PCH/cxx-offsetof-base.cpp | 2 ++ test/PCH/cxx-offsetof-base.h | 5 +++++ 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 test/PCH/cxx-offsetof-base.cpp create mode 100644 test/PCH/cxx-offsetof-base.h diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index 86dfd879ca..6a11529b02 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -502,11 +502,13 @@ void PCHStmtReader::VisitOffsetOfExpr(OffsetOfExpr *E) { E->setComponent(I, Node(Start, Reader.GetIdentifier(Record[Idx++]), End)); break; - case Node::Base: - // FIXME: Implement this! - llvm_unreachable("PCH for offsetof(base-specifier) not implemented"); + case Node::Base: { + CXXBaseSpecifier *Base = new (*Reader.getContext()) CXXBaseSpecifier(); + *Base = Reader.ReadCXXBaseSpecifier(DeclsCursor, Record, Idx); + E->setComponent(I, Node(Base)); break; } + } } for (unsigned I = 0, N = E->getNumExpressions(); I != N; ++I) diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp index e807ddff09..eee409b047 100644 --- a/lib/Frontend/PCHWriterStmt.cpp +++ b/lib/Frontend/PCHWriterStmt.cpp @@ -483,8 +483,7 @@ void PCHStmtWriter::VisitOffsetOfExpr(OffsetOfExpr *E) { break; case OffsetOfExpr::OffsetOfNode::Base: - // FIXME: Implement this! - llvm_unreachable("PCH for offsetof(base-specifier) not implemented"); + Writer.AddCXXBaseSpecifier(*ON.getBase(), Record); break; } } diff --git a/test/PCH/cxx-offsetof-base.cpp b/test/PCH/cxx-offsetof-base.cpp new file mode 100644 index 0000000000..18265deecc --- /dev/null +++ b/test/PCH/cxx-offsetof-base.cpp @@ -0,0 +1,2 @@ +// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx-offsetof-base.h +// RUN: %clang_cc1 -include-pch %t -fsyntax-only %s diff --git a/test/PCH/cxx-offsetof-base.h b/test/PCH/cxx-offsetof-base.h new file mode 100644 index 0000000000..7c7810185d --- /dev/null +++ b/test/PCH/cxx-offsetof-base.h @@ -0,0 +1,5 @@ +// Header for PCH test cxx-offsetof-base.cpp + +struct Base { int x; }; +struct Derived : Base { int y; }; +int o = __builtin_offsetof(Derived, x);