llvm-project/clang/lib/AST
Douglas Gregor 882211c1da Completely reimplement __builtin_offsetof, based on a patch by Roberto
Amadini.

This change introduces a new expression node type, OffsetOfExpr, that
describes __builtin_offsetof. Previously, __builtin_offsetof was
implemented using a unary operator whose subexpression involved
various synthesized array-subscript and member-reference expressions,
which was ugly and made it very hard to instantiate as a
template. OffsetOfExpr represents the AST more faithfully, with proper
type source information and a more compact representation.

OffsetOfExpr also has support for dependent __builtin_offsetof
expressions; it can be value-dependent, but will never be
type-dependent (like sizeof or alignof). This commit introduces
template instantiation for __builtin_offsetof as well.

There are two major caveats to this patch:

  1) CodeGen cannot handle the case where __builtin_offsetof is not a
  constant expression, so it produces an error. So, to avoid
  regressing in C, we retain the old UnaryOperator-based
  __builtin_offsetof implementation in C while using the shiny new
  OffsetOfExpr implementation in C++. The old implementation can go
  away once we have proper CodeGen support for this case, which we
  expect won't cause much trouble in C++.

  2) __builtin_offsetof doesn't work well with non-POD class types,
  particularly when the designated field is found within a base
  class. I will address this in a subsequent patch.

Fixes PR5880 and a bunch of assertions when building Boost.Python
tests. 

llvm-svn: 102542
2010-04-28 22:16:22 +00:00
..
APValue.cpp Fix -Wcast-qual warnings. 2010-04-19 16:39:44 +00:00
ASTConsumer.cpp Push DeclGroup much farther throughout the compiler. Now the various 2009-03-29 16:50:03 +00:00
ASTContext.cpp Revert "Fix for PR6953: per gcc, regparm and noreturn affect the compatibility of", it is breaking the builds of quite a few projects (emacs, dovecot, gnutar, bison). 2010-04-28 16:20:58 +00:00
ASTDiagnostic.cpp Make the InjectedClassNameType the canonical type of the current instantiation 2010-04-27 00:57:59 +00:00
ASTImporter.cpp Make the InjectedClassNameType the canonical type of the current instantiation 2010-04-27 00:57:59 +00:00
AttrImpl.cpp Add support for the weakref attribute. We still produce "alias weak" as llvm-gcc does, but are more strict on what uses of weakref we accept. 2010-02-23 22:00:30 +00:00
CMakeLists.txt Sort calls to add_clang_library() 2010-03-22 18:16:06 +00:00
CXXInheritance.cpp Implement computation of the final overriders for each virtual 2010-03-23 23:47:56 +00:00
Decl.cpp Reduce string trashing in getQualifiedNameAsString. 2010-04-28 14:33:51 +00:00
DeclBase.cpp Recommit my change to how C++ does elaborated type lookups, now with 2010-04-23 18:46:30 +00:00
DeclCXX.cpp Make the InjectedClassNameType the canonical type of the current instantiation 2010-04-27 00:57:59 +00:00
DeclFriend.cpp Implement basic support for friend types and functions in non-dependent 2010-03-12 01:19:31 +00:00
DeclGroup.cpp Add 'DeclStmt::DoDestroy()' which doesn't actually recurse over its child expressions (via StmtIterator), as those expressions are owned by the Decls and Types (which are destroyed elsewhere). This fixes a crasher reported in <rdar://problem/7487294>. 2009-12-23 08:56:00 +00:00
DeclObjC.cpp Add raw_ostream operators to NamedDecl for convenience. Switch over all users of getNameAsString on a stream. 2010-04-17 09:33:03 +00:00
DeclPrinter.cpp Add raw_ostream operators to NamedDecl for convenience. Switch over all users of getNameAsString on a stream. 2010-04-17 09:33:03 +00:00
DeclTemplate.cpp Make the InjectedClassNameType the canonical type of the current instantiation 2010-04-27 00:57:59 +00:00
DeclarationName.cpp Add printName to DeclarationName which prints the human-readable name on a 2010-04-17 09:56:45 +00:00
Expr.cpp Completely reimplement __builtin_offsetof, based on a patch by Roberto 2010-04-28 22:16:22 +00:00
ExprCXX.cpp When explicitly building a temporary object (CXXTemporaryObjectExpr), 2010-04-27 20:36:09 +00:00
ExprConstant.cpp Completely reimplement __builtin_offsetof, based on a patch by Roberto 2010-04-28 22:16:22 +00:00
FullExpr.cpp More work on the FullExpr class. 2009-12-16 06:10:22 +00:00
InheritViz.cpp Remove tabs, and whitespace cleanups. 2009-09-09 15:08:12 +00:00
Makefile Allow users to set CPPFLAGS and CXXFLAGS on the make command line. 2010-03-12 22:55:16 +00:00
NestedNameSpecifier.cpp When pretty-printing tag types, only print the tag if we're in C (and 2010-03-10 11:27:22 +00:00
ParentMap.cpp Remove tabs, and whitespace cleanups. 2009-09-09 15:08:12 +00:00
RecordLayout.cpp Replace the class offset vectors in RecordLayoutBuilder with maps instead so we'll have faster lookup and so we can detect duplicates. 2010-03-11 04:10:39 +00:00
RecordLayoutBuilder.cpp AST: Dump ASTRecordLayout objects when they are created with -fdump-record-layouts. 2010-04-19 20:44:53 +00:00
RecordLayoutBuilder.h More work on wide bit-fields, WIP. 2010-04-16 15:57:11 +00:00
Stmt.cpp Improve the AST representation of Objective-C @try/@catch/@finally 2010-04-23 22:50:49 +00:00
StmtDumper.cpp Make the static type of the exception variable in an Objective-C 2010-04-26 16:46:50 +00:00
StmtIterator.cpp Add StmtIterator support for iterating over both the condition 2009-12-23 23:38:34 +00:00
StmtPrinter.cpp Completely reimplement __builtin_offsetof, based on a patch by Roberto 2010-04-28 22:16:22 +00:00
StmtProfile.cpp Completely reimplement __builtin_offsetof, based on a patch by Roberto 2010-04-28 22:16:22 +00:00
StmtViz.cpp Adapt to the DOTGraphTraits changes in LLVM. 2009-11-30 14:16:05 +00:00
TemplateBase.cpp DeclaratorInfo -> TypeSourceInfo. Makes an effort to rename associated variables, 2009-12-07 02:54:59 +00:00
TemplateName.cpp Add raw_ostream operators to NamedDecl for convenience. Switch over all users of getNameAsString on a stream. 2010-04-17 09:33:03 +00:00
Type.cpp During template instantiation, set the naming class of 2010-04-27 18:19:34 +00:00
TypeLoc.cpp float, double, and long double do need extra data in the 2010-01-18 20:37:56 +00:00
TypePrinter.cpp Removed spaces at end of line. (Test commit.) 2010-04-27 21:08:25 +00:00