Граф коммитов

664 Коммитов

Автор SHA1 Сообщение Дата
Douglas Gregor 60a8fbb424 When implicit definition of the copy-assignment operator fails,
provide a note that shows where the copy-assignment operator was
needed. We used to have this, but I broke it during refactoring. 

Finishes PR6999.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103127 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-05 22:38:15 +00:00
Douglas Gregor fb8cc25342 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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103079 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-05 05:51:00 +00:00
Douglas Gregor 6cdc161527 When creating a call to a base subobject's operator= in an
implicitly-defined copy assignment operator, suppress the protected
access check. This eliminates the remaining failure in the
Boost.SmartPtr library (that was a product of the copy-assignment
generation rewrite) and, presumably, the Boost.TR1 library as well.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103010 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-04 15:20:55 +00:00
John McCall 3d6c1782c4 When inheriting a default argument expression, inherit the full expression,
not just the inner expression.  This is important if the expression has any
temporaries.  Fixes PR 7028.

Basically a symptom of really tragic method names.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102998 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-04 01:53:42 +00:00
Douglas Gregor 324b54d3f6 Diagnose unused exception parameters under a different warning group
(-Wunused-exception-parameter) than normal variables, since it's more
common to name and then ignore an exception parameter. This warning is
neither enabled by default nor by -Wall. Fixes <rdar://problem/7931045>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102931 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-03 18:51:14 +00:00
Douglas Gregor 62b71f489e When creating the declaration reference for implicit copy-construction
of a base class, give it real source-location information. Fixes PR7017.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102916 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-03 15:43:53 +00:00
Douglas Gregor ae374759fc When declaring a namespace alias, ignore previous declarations that
aren't in scope. Fixes PR7014.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102915 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-03 15:37:31 +00:00
Benjamin Kramer d566381800 Replace a char*/size pair with stringref.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102902 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-03 13:08:54 +00:00
Anders Carlsson 72e96fd181 Add an enum to CXXConstructExpr so we can determine if the construction expression constructs a non-virtual or virtual base.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102879 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-02 22:54:08 +00:00
Douglas Gregor 06a9f3680d Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators. 

Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.

This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:

  - For a class subobject, call the appropriate copy-assignment
    operator, after overload resolution has determined what that is.
  - For an array of scalar types or an array of class types that have
    trivial copy assignment operators, construct a call to
    __builtin_memcpy.
  - For an array of class types with non-trivial copy assignment
    operators, synthesize a (possibly nested!) for loop whose inner
    statement calls the copy constructor.
  - For a scalar type, use built-in assignment.

This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.

Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102853 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-01 20:49:11 +00:00
Anders Carlsson 59b7f1538d When defining implicit copy constructors, use SetBaseOrMemberInitializers to initialize the bases.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102842 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-01 16:39:01 +00:00
Douglas Gregor 39957dce3d Added an RAII object that helps set up/tear down the Sema context
information required to implicitly define a C++ special member
function. Use it rather than explicitly setting CurContext on entry
and exit, which is fragile. 

Use this RAII object for the implicitly-defined default constructor,
copy constructor, copy assignment operator, and destructor.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102840 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-01 15:04:51 +00:00
John McCall 77bb1aa78b It turns out that basically every caller to RequireCompleteDeclContext
already knows what context it's looking in.  Just pass that context in
instead of (questionably) recalculating it.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102818 91177308-0d34-0410-b5e6-96231b3b80d8
2010-05-01 00:40:08 +00:00
Fariborz Jahanian e4498c6d66 More of Sema to implement initialization of
ivar of c++ object types.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102500 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-28 16:11:27 +00:00
John McCall 110acc1ae8 Improve the diagnostic you get when making a qualified member access
with a qualifier referencing a different type.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102409 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-27 01:43:38 +00:00
Anders Carlsson 8e142ccf11 Revert enough of my patches to fix self-host again :(
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102289 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-25 00:52:09 +00:00
Anders Carlsson 8f2abbc791 Add an explicit UsuallyTinyPtrVector that takes a single element.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102283 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-24 22:54:32 +00:00
Anders Carlsson e127abe8bb DefineImplicitCopyConstructor now uses SetBaseOrMemberInitializers to create implicit base initializers. (Member initializers are still handled by CodeGenFunction::SynthesizeCXXCopyConstructor for now).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102279 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-24 22:25:18 +00:00
Anders Carlsson c795750b29 When building implicit base initializers, add a derived-to-base cast that points to the exact base specifier.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102277 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-24 22:02:54 +00:00
Anders Carlsson 5cf86ba6b5 Actually produce base paths for CastExprs of kind CK_DerivedToBase.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102259 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-24 19:06:50 +00:00
Anders Carlsson e25a96c062 Pass the base specifiers through to CheckDerivedToBaseConversion. No functionality change yet.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102250 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-24 17:11:09 +00:00
Douglas Gregor 107de90451 Keep track of when DependentNameTypes have no associated keyword
(e.g., no typename, enum, class, etc.), e.g., because the context is
one that is known to refer to a type. Patch from Enea Zaffanella!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102243 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-24 15:35:55 +00:00
Anders Carlsson 63010a7f0f Cleanup.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102179 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-23 16:24:12 +00:00
Anders Carlsson f6513edbb7 Handle copy initialization in BuildImplicitMemberInitializer. Not used yet.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102178 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-23 16:04:08 +00:00
Anders Carlsson e5ef740266 Add an ImplicitInitializerKind enum and pass it to BuildImplicitBaseInitializer and BuildImplicitMemberInitializer.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102166 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-23 03:10:23 +00:00
Anders Carlsson 114a297ef0 Fix a think-o that broke self-host.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102165 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-23 03:07:47 +00:00
Anders Carlsson ddfb75f22d Factor code to initialize an implicit member out into a separate function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102162 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-23 02:15:47 +00:00
Anders Carlsson defefd28a9 Remove calls to isDependentContext, since we handle that case earlier in the code. Make BuildImplicitBaseInitializer return a boolean instead.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102159 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-23 02:00:02 +00:00
Anders Carlsson 3b8c53b619 Re-land the patch that merges two diagnostics into one now that it passes self-host :)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102050 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-22 05:40:53 +00:00
Anders Carlsson 128317e6a0 Remove an unused declaration.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102037 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 23:55:31 +00:00
Anders Carlsson 711f34adb8 Keep tack of whether a base in an InitializedEntity is an inherited virtual base or not. Use this in CheckConstructorAccess.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102020 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-21 19:52:01 +00:00
Anders Carlsson 84688f2a21 Factor some common code out into a separate function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101952 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-20 23:11:20 +00:00
Douglas Gregor 16573fa970 Keep track of the actual storage specifier written on a variable or
function declaration, since it may end up being changed (e.g.,
"extern" can become "static" if a prior declaration was static). Patch
by Enea Zaffanella and Paolo Bolzoni.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101826 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-19 22:54:31 +00:00
Anders Carlsson 046c294a43 Vtable -> VTable renames across the board.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101666 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-17 20:15:18 +00:00
Douglas Gregor d6e44a3c41 Collapse the three separate initialization paths in
TryStaticImplicitCast (for references, class types, and everything
else, respectively) into a single invocation of
InitializationSequence.

One of the paths (for class types) was the only client of
Sema::TryInitializationByConstructor, which I have eliminated. This
also simplified the interface for much of the cast-checking logic,
eliminating yet more code.

I've kept the representation of C++ functional casts with <> 1
arguments the same, despite the fact that I hate it. That fix will
come soon. To satisfy my paranoia, I've bootstrapped + tested Clang
with these changes.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101549 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-16 22:09:46 +00:00
Benjamin Kramer 1deea66124 Silence warning.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101495 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-16 17:43:15 +00:00
Douglas Gregor c0b39640de Audit uses of Sema::LookupSingleName for those lookups that are
intended for redeclarations, fixing those that need it. Fixes PR6831.

This uncovered an issue where the C++ type-specifier-seq parsing logic
would try to perform name lookup on an identifier after it already had
a type-specifier, which could also lead to spurious ambiguity errors
(as in PR6831, but with a different test case).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101419 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-15 23:40:53 +00:00
Douglas Gregor c83c6874e3 Feed proper source-location information into Sema::LookupSingleResult,
in case it ends up doing something that might trigger diagnostics
(template instantiation, ambiguity reporting, access
reporting). Noticed while working on PR6831.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101412 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-15 22:33:43 +00:00
Douglas Gregor 325e593a83 Warn about non-aggregate classes with no user-declared constructors
that have reference or const scalar members, since those members can
never be initializer or modified. Fixes <rdar://problem/7804350>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101316 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-15 00:00:53 +00:00
Douglas Gregor aaf87162c5 Teach typo correction about various language keywords. We can't
generally recover from typos in keywords (since we would effectively
have to mangle the token stream). However, there are still benefits to
typo-correcting with keywords:
  - We don't make stupid suggestions when the user typed something
  that is similar to a keyword. 
  - We can suggest the keyword in a diagnostic (did you mean
  "static_cast"?), even if we can't recover and therefore don't have
  a fix-it.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101274 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-14 20:04:41 +00:00
Douglas Gregor abe183dd2f Refactor and simplify the computation of implicit conversion sequences
for reference binding. The code attempted to handle both the
computation of the ICS and the actual conversion, but the latter is an
anachronism: we now use InitializationSequence for that. 

Sema::CheckReferenceInit is now a static function TryReferenceInit
that's only use within overload resolution, and has been simplified
slightly. It still needs to be updated per C++ [over.ics.ref], by
eliminating more of the lvalue/rvalue checks.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101136 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-13 16:31:36 +00:00
Douglas Gregor d1fed3e859 During referencing binding, only consider conversion functions for
direct reference binding when the source and target types are not
reference-related. Fixes PR6066.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101132 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-13 15:07:45 +00:00
John McCall 3d04336baf Allow classes to befriend implicitly-declared members. Fixes PR6207 for
members of non-templated classes.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101122 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-13 07:45:41 +00:00
John McCall a3f8137d9f Diagnose declarations of conversion functions with declarators other than '()'.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101098 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-13 00:04:31 +00:00
Douglas Gregor 6275e0cac3 When creating the implicitly-declared special member functions, be
sure to introduce them into the current Scope (when we have one) in
addition to the DeclContext for the class, so that they can be found
by name lookup for inline members of the class. Fixes PR6570.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101047 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-12 17:09:20 +00:00
Anders Carlsson 80638c5e63 Have the CXXBaseOrMemberInitializer keep track of whether an initializer initializes a virtual base or not.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101004 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-12 00:51:03 +00:00
John McCall 3c3ccdbe73 Diagnose more cases of initializing distinct members of an anonymous union
member.  Use a better diagnostic for this case.  Also fix a bug with nested
anonymous structs/unions for -Wreorder;  this last was PR6575.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100923 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-10 09:28:51 +00:00
John McCall d6ca8da0f5 Diagnose misordered initializers in constructor templates immediately instead of
when they're instantiated.  Merge the note into the -Wreorder warning;  it
doesn't really contribute much, and it was splitting a thought across diagnostics
anyway.  Don't crash in the parser when a constructor's initializers end in a
comma and there's no body;  the recovery here is still terrible, but anything's
better than a crash.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100922 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-10 07:37:23 +00:00
John McCall fd2254405d Suppress access control diagnostics when looking up a base or member name
fails to find a type.  There are no cases where it's valid for this to produce
an error.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100878 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-09 19:01:14 +00:00
Jeffrey Yasskin 9ab1454171 Make CXXScopeSpec invalid when incomplete, and propagate that into any
Declarator that depends on it.  This fixes several redundant errors and bad
recoveries.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100779 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-08 16:38:48 +00:00