llvm-project/clang/lib/AST
Douglas Gregor 94f9a4820a Reimplement code generation for copying fields in the
implicitly-generated copy constructor. Previously, Sema would perform
some checking and instantiation to determine which copy constructors,
etc., would be called, then CodeGen would attempt to figure out which
copy constructor to call... but would get it wrong, or poke at an
uninstantiated default argument, or fail in other ways.

The new scheme is similar to what we now do for the implicit
copy-assignment operator, where Sema performs all of the semantic
analysis and builds specific ASTs that look similar to the ASTs we'd
get from explicitly writing the copy constructor, so that CodeGen need
only do a direct translation.

However, it's not quite that simple because one cannot explicit write
elementwise copy-construction of an array. So, I've extended
CXXBaseOrMemberInitializer to contain a list of indexing variables
used to copy-construct the elements. For example, if we have:

  struct A { A(const A&); };
  
  struct B {
    A array[2][3];
  };

then we generate an implicit copy assignment operator for B that looks
something like this:

  B::B(const B &other) : array[i0][i1](other.array[i0][i1]) { }

CodeGen will loop over the invented variables i0 and i1 to visit all
elements in the array, so that each element in the destination array
will be copy-constructed from the corresponding element in the source
array. Of course, if we're dealing with arrays of scalars or class
types with trivial copy-assignment operators, we just generate a
memcpy rather than a loop.

Fixes PR6928, PR5989, and PR6887. Boost.Regex now compiles and passes
all of its regression tests.

Conspicuously missing from this patch is handling for the exceptional
case, where we need to destruct those objects that we have
constructed. I'll address that case separately.

llvm-svn: 103079
2010-05-05 05:51:00 +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 When synthesizing Objective C records, give the synthetic fields public 2010-04-30 21:35:41 +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 Unbreak CMake build. 2010-05-05 05:41:05 +00:00
CXXInheritance.cpp Implement computation of the final overriders for each virtual 2010-03-23 23:47:56 +00:00
Decl.cpp When we start the definition of a class template, set the 2010-04-30 04:39:27 +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 Reimplement code generation for copying fields in the 2010-05-05 05:51:00 +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 Introduce a sequence number into class template partial 2010-04-30 05:56:50 +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 Change StmtNodes.def to StmtNodes.td in anticipation of a rewrite of attributes 2010-05-05 04:13:52 +00:00
ExprCXX.cpp Change CXXConstructExpr::Create to take a ConstructionKind. 2010-05-02 23:53:04 +00:00
ExprConstant.cpp A not equal for an unordered relation should return true as specified in IEEE-754, e.g., 2010-04-29 05:53:29 +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 Change StmtNodes.def to StmtNodes.td in anticipation of a rewrite of attributes 2010-05-05 04:13:52 +00:00
StmtDumper.cpp Let StmtDumper.cpp handle using declarations. 2010-05-04 10:20:17 +00:00
StmtIterator.cpp Add StmtIterator support for iterating over both the condition 2009-12-23 23:38:34 +00:00
StmtPrinter.cpp Change StmtNodes.def to StmtNodes.td in anticipation of a rewrite of attributes 2010-05-05 04:13:52 +00:00
StmtProfile.cpp Change StmtNodes.def to StmtNodes.td in anticipation of a rewrite of attributes 2010-05-05 04:13:52 +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