Commit Graph

4351 Commits

Author SHA1 Message Date
Anders Carlsson bcc066b659 Add an enum to CXXConstructExpr so we can determine if the construction expression constructs a non-virtual or virtual base.
llvm-svn: 102879
2010-05-02 22:54:08 +00:00
Douglas Gregor b139cd5843 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.

llvm-svn: 102853
2010-05-01 20:49:11 +00:00
Anders Carlsson 7911150a3d When defining implicit copy constructors, use SetBaseOrMemberInitializers to initialize the bases.
llvm-svn: 102842
2010-05-01 16:39:01 +00:00
Douglas Gregor a57478e8f6 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.

llvm-svn: 102840
2010-05-01 15:04:51 +00:00
John McCall 0b66eb38c7 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.

llvm-svn: 102818
2010-05-01 00:40:08 +00:00
Ted Kremenek b802192a7e Don't perform AnalysisBasedWarnings in Sema or run the static analyzer when a
fatal error has occurred.

llvm-svn: 102778
2010-04-30 21:49:25 +00:00
Douglas Gregor fabf95d066 After substituting a template argument for a non-type template
parameter with pointer-to-member type, we may have to perform a
qualification conversion, since the pointee type of the parameter
might be more qualified than the pointee type of the argument we form
from the declaration. Fixes PR6986.

llvm-svn: 102777
2010-04-30 21:46:38 +00:00
Douglas Gregor 0be628ff64 Fix a thinko that caused us not to compute __builtin_offset as a
constant expression in C. 

llvm-svn: 102762
2010-04-30 20:35:01 +00:00
Douglas Gregor 14cf752486 Clean up our handling of local instantiation scopes, which keep track
of the mapping from local declarations to their instantiated
counterparts during template instantiation. Previously, we tried to do
some unholy merging of local instantiation scopes that involved
storing a single hash table along with an "undo" list on the
side... which was ugly, and never handled function parameters
properly.

Now, we just keep separate hash tables for each local instantiation
scope, and "combining" two scopes means that we'll look in each of the
combined hash tables. The combined scope stack is rarely deep, and
this makes it easy to avoid the "undo" issues we were hitting. Also,
I've simplified the logic for function parameters: if we're declaring
a function and we need the function parameters to live longer, we just
push them back into the local instantiation scope where we need them. 

Fixes PR6990.

llvm-svn: 102732
2010-04-30 18:55:50 +00:00
Abramo Bagnara 5009937f47 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.
llvm-svn: 102710
2010-04-30 13:10:51 +00:00
Abramo Bagnara b639ab9ffc Attribute noreturn is now put in declaration attributes. Fixed a double warning generation.
llvm-svn: 102705
2010-04-30 09:13:03 +00:00
John McCall 5af1aa6393 An edge from a call expression to the exit block is only an abnormal edge
if *none* of the successors of the call expression is the exit block.
This matters when a call of bool type is the condition of (say) a while
loop in a function with no statements after the loop.  This *can* happen
in C, but it's much more common in C++ because of overloaded operators.

Suppresses some substantial number of spurious -Wmissing-noreturn warnings.

llvm-svn: 102696
2010-04-30 07:10:06 +00:00
Douglas Gregor 8b895228d9 Fix ADL for types declared in transparent decls, from Alp Toker!
llvm-svn: 102695
2010-04-30 07:08:38 +00:00
Douglas Gregor 407e961645 Introduce a sequence number into class template partial
specializations, which keeps track of the order in which they were
originally declared. We use this number so that we can always walk the
list of partial specializations in a predictable order during matching
or template instantiation. This also fixes a failure in Boost.Proto,
where SourceManager::isBeforeInTranslationUnit was behaving
poorly in inconsistent ways.

llvm-svn: 102693
2010-04-30 05:56:50 +00:00
John McCall 99b2fe5f54 Rebuild the nested name specifiers in member-pointer declarator chunks when
entering the current instantiation.  Set up a little to preserve type location
information for typename types while we're in there.

Fixes a Boost failure.

llvm-svn: 102673
2010-04-29 23:50:39 +00:00
Douglas Gregor 980fb16f9a When determining a standard conversion sequence involves resolving the
address of an overloaded function (or function template), perform that
resolution prior to determining the implicit conversion
sequence. This resolution is not part of the implicit conversion
sequence itself.

Previously, we would always consider this resolution to be a
function pointer decay, which was a lie: there might be an explicit &
in the expression, in which case decay should not occur. This caused
the CodeGen assertion in PR6973 (where we created a 
pointer to a pointer to a function when we should have had a pointer
to a function), but it's likely that there are corner cases of
overload resolution where this would have failed.

Cleaned up the code involved in determining the type that will
produced afer resolving the overloaded function reference, and added
an assertion to make sure the result is correct. Fixes PR6973.

llvm-svn: 102650
2010-04-29 18:24:40 +00:00
Fariborz Jahanian 9e1a3af030 Properties cannot be synthesized by-dafult in
categories. Issue usual warnings instead of
confusing error message. Radar 7920807

llvm-svn: 102645
2010-04-29 17:52:18 +00:00
Ted Kremenek 186a074346 Add FunctionDecl::isVariadic() to match BlockDecl::isVariadic() and ObjCMethodDecl::isVariadic().
Do some minor refactoring along the way.

llvm-svn: 102635
2010-04-29 16:49:01 +00:00
Ted Kremenek 8af4f40f4a Rename BlockDecl::IsVariadic() to BlockDecl::isVariadic() to match the casing
for similar methods.  No functionality change.

llvm-svn: 102634
2010-04-29 16:48:58 +00:00
Douglas Gregor 9225b02096 When performing partial ordering of class template partial
specializations, substitute the deduced template arguments and check
the resulting substitution before concluding that template argument
deduction succeeds. This marvelous little fix makes a bunch of
Boost.Spirit tests start working.

llvm-svn: 102601
2010-04-29 06:31:36 +00:00
Douglas Gregor 684268daab For template argument deduction from class template partial
specializations, separate out the deduction part from the checking and
substitution of the deduced arguments.

llvm-svn: 102600
2010-04-29 06:21:43 +00:00
Douglas Gregor 33dcc2e34d It turns out that we *can* end up having to display template argument
bindings when the template argument is still an expression; it happens
while checking the template arguments of a class template partial
specializations. Fixes PR6964.

llvm-svn: 102595
2010-04-29 04:55:13 +00:00
John McCall e23b871c4b Access-check during template argument deduction from the context of the
template decl itself, not its context.  Testcase to follow;  fixes selfhost.

llvm-svn: 102578
2010-04-29 01:18:58 +00:00
John McCall 80e58cd3e9 Properly switch into the declaring scope of a template when performing
template argument deduction or (more importantly) the final substitution
required by such deduction.  Makes access control magically work in these
cases.

Fixes PR6967.

llvm-svn: 102572
2010-04-29 00:35:03 +00:00
Douglas Gregor d170206761 Teach __builtin_offsetof to compute the offsets of members of base
classes, since we only warn (not error) on offsetof() for non-POD
types. We store the base path within the OffsetOfExpr itself, then
evaluate the offsets within the constant evaluator.

llvm-svn: 102571
2010-04-29 00:18:15 +00:00
Alexis Hunt c46382e4b3 Ensure that cv-qualifiers are correctly removed for post-inc/decrements
as well as pre- and post-inc/decrements in C (not that I think it
matters for any C code).

llvm-svn: 102552
2010-04-28 23:02:27 +00:00
Douglas Gregor ea679ec125 Fix template instantiation for __builtin_offfsetof expressions that refer to members of anonymous structs/unions
llvm-svn: 102551
2010-04-28 22:43:14 +00:00
Douglas Gregor 10982ea3f9 Diagnose __builtin_offsetof expressions that refer to bit-fields
llvm-svn: 102548
2010-04-28 22:36:06 +00:00
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
Fariborz Jahanian c83726e64e More of Sema to implement initialization of
ivar of c++ object types.

llvm-svn: 102500
2010-04-28 16:11:27 +00:00
Abramo Bagnara 41160fed4c Written storage class for declarations inside linkage specifications without braces is none.
llvm-svn: 102496
2010-04-28 13:11:54 +00:00
Douglas Gregor a02bb34155 When the qualifier of a id-expression is non-dependent but not
complete, return an error rather than falling back to building a
dependent declaration reference, since we might not be in a dependent
context. Fixes a fiendish crash-on-invalid in Boost.FunctionTypes that
I wasn't able to reduce to anything useful.

llvm-svn: 102491
2010-04-28 07:04:26 +00:00
Douglas Gregor 1614237822 When instantiating a function template specialization following
template argument deduction, use the lexical declaration context as
the owner for friend function templates. Fixes 2 failures in
Boost.Graph.

llvm-svn: 102489
2010-04-28 04:52:24 +00:00
Douglas Gregor 1524333004 It's okay to refer to non-type template parameters anywhere they are
visible. Fixes the remaining two failures in Boost.ScopeExit.

llvm-svn: 102466
2010-04-27 21:10:04 +00:00
Douglas Gregor 199db36b79 When explicitly building a temporary object (CXXTemporaryObjectExpr),
keep track of whether we need to zero-initialize storage prior to
calling its constructor. Previously, we were only tracking this when
implicitly constructing the object (a CXXConstructExpr).

Fixes Boost's value-initialization tests, which means that the
Boost.Config library now passes all of its tests.

llvm-svn: 102461
2010-04-27 20:36:09 +00:00
Douglas Gregor 7d8072e038 Diagnose the use of abstract types as array element types. Previously,
we were relying on checking for abstract class types when an array
type was actually used to declare a variable, parameter, etc. However,
we need to check when the construct the array for, e.g., SFINAE
purposes (see DR337). Fixes problems with Boost's is_abstract type
trait. 

llvm-svn: 102452
2010-04-27 19:38:14 +00:00
Douglas Gregor 9262f4775d During template instantiation, set the naming class of
UnresolvedLookupExpr and UnresolvedMemberExpr by substituting the
naming class we computed when building the expression in the
template...

... which we didn't always do correctly. Teach
UnresolvedMemberExpr::getNamingClass() all about the new 
representation of injected-class-names in templates, so	that it	can
return a naming	class that is the current instantiation.

Also, when decomposing a template-id into its template name and its
arguments, be sure to set the naming class on the LookupResult
structure. 

Fixes PR6947 the right way.

llvm-svn: 102448
2010-04-27 18:19:34 +00:00
Fariborz Jahanian 38b77a9d8e Move CollectIvarsToConstructOrDestruct to Sema
from AST, consider ivar array of objects
(per Doug's comment).

llvm-svn: 102446
2010-04-27 17:18:58 +00:00
Douglas Gregor 4423926e66 When checking the redeclaration context of a typedef that refers to a
tag of the same name, compare the lookup contexts rather than the
actual contexts. Fixes PR6923.

llvm-svn: 102437
2010-04-27 16:26:47 +00:00
Douglas Gregor 19defcd6f5 Don't look into incomplete types when trying to warn about unused
variables. Fixes PR6948.

llvm-svn: 102436
2010-04-27 16:20:13 +00:00
Douglas Gregor da7be08a0c When instantiating UnresolvedLookupExpr and UnresolvedMemberExpr
expressions, be sure to set the naming class of the LookupResult
structure. Fixes PR6947.

llvm-svn: 102434
2010-04-27 16:10:10 +00:00
John McCall 1e67dd6b2f Improve the diagnostic you get when making a qualified member access
with a qualifier referencing a different type.

llvm-svn: 102409
2010-04-27 01:43:38 +00:00
John McCall 2408e32096 Make the InjectedClassNameType the canonical type of the current instantiation
of a class template or class template partial specialization.  That is to
say, in
  template <class T> class A { ... };
or
  template <class T> class B<const T*> { ... };
make 'A<T>' and 'B<const T*>' sugar for the corresponding InjectedClassNameType
when written inside the appropriate context.  This allows us to track the
current instantiation appropriately even inside AST routines.  It also allows
us to compute a DeclContext for a type much more efficiently, at some extra
cost every time we write a template specialization (which can be optimized,
but I've left it simple in this patch).

llvm-svn: 102407
2010-04-27 00:57:59 +00:00
Douglas Gregor 9da641912d Improve source-location information in a C++ typeid (type) expression
by using TypeSourceInfo, cleaning up the representation
somewhat. Teach getTypeOperand() to strip references and
cv-qualifiers, providing the semantic view of the type without
requiring any extra storage (the unmodified type remains within the
TypeSourceInfo). This fixes a bug found by Boost's call_traits test.

Finally, clean up semantic analysis, by splitting the ActOnCXXTypeid
routine into ActOnCXXTypeId (the parser action) and two BuildCXXTypeId
functions, which perform the semantic analysis for typeid(type) and
typeid(expression), respectively. We now perform less work at template
instantiation time (we don't look for std::type_info again) and can
give better diagnostics.

llvm-svn: 102393
2010-04-26 22:37:10 +00:00
Fariborz Jahanian 0103d67f98 Diagnose declaration of reference typed ivars.
llvm-svn: 102390
2010-04-26 22:07:03 +00:00
Douglas Gregor 8385a06929 Introduce Type::isStructureOrClassType(), which does the obvious
thing. Audit all uses of Type::isStructure(), changing those calls to
isStructureOrClassType() as needed (which is alsmost
everywhere). Fixes the remaining failure in Boost.Utility/Swap.

llvm-svn: 102386
2010-04-26 21:31:17 +00:00
Douglas Gregor b7e20eb883 Implement template instantiation for implicit property references in
Objective-C++. This is the last bit of (non-blocks-related) template
instantiation logic for Objective-C++. Yay! 

llvm-svn: 102382
2010-04-26 21:04:54 +00:00
Douglas Gregor 9faee21f67 Implement template instantiation for ObjCPropertyRefExpr.
llvm-svn: 102379
2010-04-26 20:47:02 +00:00
Douglas Gregor d51d90dd04 Implement template instantiation for value-dependent Objective-C ivar
references and isa expressions. Also, test template instantiation of
unresolved member references to Objective-C ivar references and isa
expressions.

llvm-svn: 102374
2010-04-26 20:11:03 +00:00
Douglas Gregor f4e837f66c Implement template instantiation for Objective-C @catch
statements. This is the last of the Objective-C statements.

llvm-svn: 102356
2010-04-26 17:57:08 +00:00