llvm-project/clang/lib/Sema
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
..
AnalysisBasedWarnings.cpp Don't perform AnalysisBasedWarnings in Sema or run the static analyzer when a 2010-04-30 21:49:25 +00:00
AnalysisBasedWarnings.h Remove micro-optimization for not issueing CFG-based warnings for 'static inline' functions 2010-04-08 18:51:44 +00:00
CMakeLists.txt Unbreak CMake build. 2010-05-05 05:41:05 +00:00
CXXFieldCollector.h ActOnTagDefinitionError is supposed to 'unwind' ActOnTagStartDefinition, not 2010-03-17 19:25:57 +00:00
CodeCompleteConsumer.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
IdentifierResolver.cpp Optimize the implementation of IdDeclInfo pooling in the IdentifierResolver. 2010-02-15 19:38:00 +00:00
IdentifierResolver.h Eliminate dead code. 2010-01-02 21:44:36 +00:00
JumpDiagnostics.cpp Improve the AST representation of Objective-C @try/@catch/@finally 2010-04-23 22:50:49 +00:00
Lookup.h Recommit r102215, this time being more careful to only set the "principal 2010-04-24 01:30:58 +00:00
Makefile Allow users to set CPPFLAGS and CXXFLAGS on the make command line. 2010-03-12 22:55:16 +00:00
ParseAST.cpp push some source location information down through the compiler, 2010-04-20 20:35:58 +00:00
Sema.cpp Add base paths to CK_UncheckedDerivedToBase and CK_DerivedToBaseMemberPointer. 2010-04-24 19:22:20 +00:00
Sema.h When computing the template arguments for the instantiation of a 2010-05-03 23:29:10 +00:00
SemaAccess.cpp An access is permitted if the current template instantiates to the appropriate 2010-05-04 05:11:27 +00:00
SemaAttr.cpp Rip out the last remaining implicit use of OverloadedFunctionDecl in Sema: 2009-12-02 08:25:40 +00:00
SemaCXXCast.cpp Add base paths for CK_BaseToDerived and CK_BaseToDerivedMemberPointer. 2010-04-24 19:36:51 +00:00
SemaCXXScopeSpec.cpp It turns out that basically every caller to RequireCompleteDeclContext 2010-05-01 00:40:08 +00:00
SemaChecking.cpp Add FunctionDecl::isVariadic() to match BlockDecl::isVariadic() and ObjCMethodDecl::isVariadic(). 2010-04-29 16:49:01 +00:00
SemaCodeComplete.cpp It turns out that basically every caller to RequireCompleteDeclContext 2010-05-01 00:40:08 +00:00
SemaDecl.cpp When instantiating a function that was declared via a typedef, e.g., 2010-05-04 18:18:31 +00:00
SemaDeclAttr.cpp Add calling convention related attributes to related declaration. Mark attributes invalid on type related checking so to add them to declarations only when everything is ok. 2010-04-30 13:10:51 +00:00
SemaDeclCXX.cpp Reimplement code generation for copying fields in the 2010-05-05 05:51:00 +00:00
SemaDeclObjC.cpp Diagnose unused exception parameters under a different warning group 2010-05-03 18:51:14 +00:00
SemaExceptionSpec.cpp Reinstate my CodeModificationHint -> FixItHint renaming patch, without 2010-03-31 17:46:05 +00:00
SemaExpr.cpp When instantiating a function that was declared via a typedef, e.g., 2010-05-04 18:18:31 +00:00
SemaExprCXX.cpp The array form of 'new' can never have initializers. 2010-05-03 15:45:23 +00:00
SemaExprObjC.cpp With -fno-constant-cfstrrings, class NSConstantString 2010-04-23 23:19:04 +00:00
SemaInit.cpp Complain when we try to initialize an object of Objective-C class type 2010-05-03 18:24:37 +00:00
SemaInit.h Whenever we complain about a failed initialization of a function or 2010-04-22 00:20:18 +00:00
SemaLookup.cpp It turns out that basically every caller to RequireCompleteDeclContext 2010-05-01 00:40:08 +00:00
SemaObjCProperty.cpp Do not issue warning on unimplemented property in the class, if it 2010-05-03 15:49:20 +00:00
SemaOverload.cpp When instantiating a function that was declared via a typedef, e.g., 2010-05-04 18:18:31 +00:00
SemaOverload.h Improve our handling of user-defined conversions as part of overload 2010-04-17 22:01:05 +00:00
SemaStmt.cpp Refactor Objective-C @catch parameter checking by detangling it from 2010-04-26 17:32:49 +00:00
SemaTemplate.cpp It turns out that basically every caller to RequireCompleteDeclContext 2010-05-01 00:40:08 +00:00
SemaTemplate.h After performing template argument deduction for a function template, 2010-03-28 02:42:43 +00:00
SemaTemplateDeduction.cpp When performing partial ordering of class template partial 2010-04-29 06:31:36 +00:00
SemaTemplateInstantiate.cpp When computing the template arguments for the instantiation of a 2010-05-03 23:29:10 +00:00
SemaTemplateInstantiateDecl.cpp When instantiating a function that was declared via a typedef, e.g., 2010-05-04 18:18:31 +00:00
SemaType.cpp Add calling convention related attributes to related declaration. Mark attributes invalid on type related checking so to add them to declarations only when everything is ok. 2010-04-30 13:10:51 +00:00
TargetAttributesSema.cpp Don't emit a warning about a dllimport attribute being used in a typedef 2010-02-21 05:12:56 +00:00
TargetAttributesSema.h Generalize target weirdness handling having proper layering in mind: 2010-01-10 12:58:08 +00:00
TreeTransform.h Change StmtNodes.def to StmtNodes.td in anticipation of a rewrite of attributes 2010-05-05 04:13:52 +00:00