Douglas Gregor [Sun, 23 May 2010 19:57:01 +0000 (19:57 +0000)]
It turns out that people love using VLAs in templates, too. Weaken our
VLA restrictions so that one can use VLAs in templates (even
accidentally), but not as part of a non-type template parameter (which
would be very bad).
Douglas Gregor [Sun, 23 May 2010 18:57:34 +0000 (18:57 +0000)]
Provide the overloaded functions for UnresolvedLookupExpr and
UnresolvedMemberExpr in their constructors, rather than adding them
after the fact. No functionality change.
Douglas Gregor [Sun, 23 May 2010 18:26:36 +0000 (18:26 +0000)]
Keep track of all of the class and function template's "common"
pointers in the ASTContext, so that the folding sets stored inside
them will be deallocated when the ASTContext is destroyed (under
-disable-free). <rdar://problem/7998824>.
John McCall [Sat, 22 May 2010 22:13:32 +0000 (22:13 +0000)]
Re-teach IR gen to perform GC moves on rvalues resulting from various ObjC
expressions. Essentially, GC breaks a certain form of the return-value
optimization.
Douglas Gregor [Sat, 22 May 2010 16:17:30 +0000 (16:17 +0000)]
Implement support for variable length arrays in C++. VLAs are limited
in several important ways:
- VLAs of non-POD types are not permitted.
- VLAs cannot be used in conjunction with C++ templates.
These restrictions are intended to keep VLAs out of the parts of the
C++ type system where they cause the most trouble. Fixes PR5678 and
<rdar://problem/8013618>.
Douglas Gregor [Sat, 22 May 2010 05:17:18 +0000 (05:17 +0000)]
Improve our handling of reference binding for subobjects of
temporaries. There are actually several interrelated fixes here:
- When converting an object to a base class, it's only an lvalue
cast when the original object was an lvalue and we aren't casting
pointer-to-derived to pointer-to-base. Previously, we were
misclassifying derived-to-base casts of class rvalues as lvalues,
causing various oddities (including problems with reference binding
not extending the lifetimes of some temporaries).
- Teach the code for emitting a reference binding how to look
through no-op casts and parentheses directly, since
Expr::IgnoreParenNoOpCasts is just plain wrong for this. Also, make
sure that we properly look through multiple levels of indirection
from the temporary object, but destroy the actual temporary object;
this fixes the reference-binding issue mentioned above.
- Teach Objective-C message sends to bind the result as a temporary
when needed. This is actually John's change, but it triggered the
reference-binding problem above, so it's included here. Now John
can actually test his return-slot improvements.
Chandler Carruth [Sat, 22 May 2010 02:21:53 +0000 (02:21 +0000)]
Daniel re-educated me about what Alias does and does not do. Turn that off for
'-fasm' and explicitly map from that flag to -fgnu-keywords in the driver. Turn
off the driver in the lexer test for this madness and add a test to the driver
that the translation actually works.
John McCall [Sat, 22 May 2010 01:48:05 +0000 (01:48 +0000)]
Push a return-value slot throughout ObjC message-send codegen. Will be
critical for ObjC++ correctness; hard to test independently of various
required Sema changes, though.
Daniel Dunbar [Sat, 22 May 2010 00:37:20 +0000 (00:37 +0000)]
Driver: When printing a "command was signalled" type of diagnostic, use the
short name of the tool in use, instead of the name of the action that created
the command. The practical impact is we now get:
clang: error: clang frontend command failed due to signal 6 (use -v to see invocation)
instead of:
clang: error: assembler command failed due to signal 6 (use -v to see invocation)
when clang crashes on a job that uses the integrated assembler.
Douglas Gregor [Fri, 21 May 2010 23:43:39 +0000 (23:43 +0000)]
Improve recovery when we see a dependent template name that is missing
the required "template" keyword, using the same heuristics we do for
dependent template names in member access expressions, e.g.,
test/SemaTemplate/dependent-template-recover.cpp:11:8: error: use 'template'
keyword to treat 'getAs' as a dependent template name
T::getAs<U>();
^
template
Douglas Gregor [Fri, 21 May 2010 23:18:07 +0000 (23:18 +0000)]
Improve parser recovery when we encounter a dependent template name
that is missing the 'template' keyword, e.g.,
t->getAs<T>()
where getAs is a member of an unknown specialization. C++ requires
that we treat "getAs" as a value, but that would fail to parse since T
is the name of a type. We would then fail at the '>', since a type
cannot be followed by a '>'.
This is a very common error for C++ programmers to make, especially
since GCC occasionally allows it when it shouldn't (as does Visual
C++). So, when we are in this case, we use tentative parsing to see if
the tokens starting at "<" can only be parsed as a template argument
list. If so, we produce a diagnostic with a fix-it that states that
the 'template' keyword is needed:
test/SemaTemplate/dependent-template-recover.cpp:5:8: error: 'template' keyword
is required to treat 'getAs' as a dependent template name
t->getAs<T>();
^
template
This is just a start of this patch; I'd like to apply the same
approach to everywhere that a template-id with dependent template name
can be parsed.
Nick Lewycky [Fri, 21 May 2010 23:14:51 +0000 (23:14 +0000)]
Outdent this file by 2 spaces per the coding standards, and also clean up
whitespace at the end of lines since I'm already touching the whole file
anyways.
Douglas Gregor [Fri, 21 May 2010 20:29:55 +0000 (20:29 +0000)]
Use CanQualType to enforce the use of a canonical type argument to
CXXBasePaths::isAmbiguous(), rather than just asserting that we have a
canonical type. Fixes PR7176.
Douglas Gregor [Fri, 21 May 2010 17:55:12 +0000 (17:55 +0000)]
When generating the call arguments in a thunk to call the thunkee, do
not make copies non-POD arguments or arguments passed by reference:
just copy the pointers directly. This eliminates another source of the
dreaded memcpy-of-non-PODs. Fixes PR7188.
Chandler Carruth [Fri, 21 May 2010 10:29:57 +0000 (10:29 +0000)]
Teach the RecursiveASTVisitor to enter parts of the AST previously missed.
Factor its implementation to ease the addition of these custom edges to
traverse. With this patch we get initializer expressions, block bodies, type
source info, and function argument, result, and exception types. There are
probably still some more missed edges.
While we're here, clean up and flesh out a bunch of comments.
Patch by Zhanyong Wan; I've done a cursory review, but further review
appreciated. This is fast becoming one of the most important public APIs to the
AST.
John McCall [Fri, 21 May 2010 04:11:14 +0000 (04:11 +0000)]
Allocate space in a block record for implicit references to the Objective C
'self' variable arising from uses of the 'super' keyword. Also reorganize
some code so that BlockInfo (now CGBlockInfo) can be opaque outside of
CGBlocks.cpp.
John McCall [Fri, 21 May 2010 01:18:57 +0000 (01:18 +0000)]
When emitting an lvalue for an anonymous struct or union member during
class initialization, drill down through an arbitrary number of anonymous
records.
Douglas Gregor [Fri, 21 May 2010 00:31:19 +0000 (00:31 +0000)]
When instantiating anonymous structs/unions within a function, make
sure that the anonymous struct/union record declaration gets
instantiated before the variable declaration, and that it and its
fields (recursively) get entries in the local instantiation map. Fixes
PR7088.
John McCall [Thu, 20 May 2010 23:23:51 +0000 (23:23 +0000)]
Be sure to apply initializers to members of anonymous structs and unions
recursively, e.g. so that members of anonymous unions inside anonymous structs
still get initialized. Also generate default constructor calls for anonymous
struct members when necessary.
Douglas Gregor [Thu, 20 May 2010 22:12:02 +0000 (22:12 +0000)]
Add a new failure kind, FK_Incomplete, to InitializationSequence, to
capture failures when we try to initialize an incomplete
type. Previously, we would (ab)use FK_ConversionFailed, then
occasionally dereference a null pointer when trying to diagnose the
failure. Fixes <rdar://problem/7959007>.
Douglas Gregor [Thu, 20 May 2010 20:58:56 +0000 (20:58 +0000)]
Reinstate r104117, Chandler Carruth's change that "[provides] a naming
class for UnresolvedLookupExprs, even when occuring on template
names" along with a fix for an Objective-C++ crasher it introduced.
Douglas Gregor [Thu, 20 May 2010 15:39:01 +0000 (15:39 +0000)]
Assert that we do not try to memcpy a non-POD class type in C++. This
particular issue was the cause of the Boost.Interprocess failures, and
in general will lead to horrendous, hard-to-diagnose miscompiles. The
assertion itself has survives self-host and a full Boost build, so we
are close to eradicating this problem in C++.
Note that the assertion is *not* turned on for Objective-C++, where we
still have problems with introducing memcpy's of non-POD class
types. That part of the assertion will go away as soon as we fix the
known issues in Objective-C++.
Douglas Gregor [Thu, 20 May 2010 08:36:28 +0000 (08:36 +0000)]
Rework our handling of binding a reference to a temporary
subobject. Previously, we could only properly bind to a base class
subobject while extending the lifetime of the complete object (of a
derived type); for non-static data member subobjects, we could memcpy
(!) the result and bind to that, which is rather broken.
Now, we pull apart the expression that we're binding to, to figure out
which subobject we're accessing, then construct the temporary object
(adding a destruction if needed) and, finally, dig out the subobject
we actually meant to access.
This fixes yet another instance where we were memcpy'ing rather than
doing the right thing. However, note the FIXME in references.cpp:
there's more work to be done for binding to subobjects, since the AST
is incorrectly modeling some member accesses in base classes as
lvalues when they are really rvalues.
Douglas Gregor [Thu, 20 May 2010 05:54:35 +0000 (05:54 +0000)]
When creating a this-adjustment thunk where the return value is of C++
class type (that uses a return slot), pass the return slot to the
callee directly rather than allocating new storage and trying to copy
the object. This appears to have been the cause of the remaining two
Boost.Interprocess failures.
Douglas Gregor [Thu, 20 May 2010 02:24:22 +0000 (02:24 +0000)]
Various small fixes for construction/destruction of Objective-C++
instance variables:
- Use isRecordType() rather than isa<RecordType>(), so that we see
through typedefs in ivar types.
- Mark the destructor as referenced
- Perform C++ access control on the destructor
Chris Lattner [Thu, 20 May 2010 00:25:36 +0000 (00:25 +0000)]
switch TemplateArgumentListBuilder to hold its flat argument list in a smallvector
instead of new[]'d. This greatly reduces the number of new[]'s, and guess what,
they were all leaked.
where test/SemaTemplate/variadic-class-template-2.cpp is accessing the vector
out of range and NumPackArgs is negative. I assume variadic template args are
completely hosed.
Chris Lattner [Thu, 20 May 2010 00:19:09 +0000 (00:19 +0000)]
fix the TemplateArgumentList copy constructor to not
be a copy constructor (since it isn't one semantically)
and fix the ownership bits it sets to be correct!
Douglas Gregor [Wed, 19 May 2010 23:40:50 +0000 (23:40 +0000)]
When a conditional operator is an rvalue of class type, we need to
create a temporary copy of both the "true" and "false" results. Fixes
the Boost.Interprocess failures.
Daniel did all the hard work of tracking down the issue, I get to type
up the trivial fix for this horrible miscompile.
Daniel Dunbar [Wed, 19 May 2010 21:07:14 +0000 (21:07 +0000)]
Revert r104117, "Provide a naming class for UnresolvedLookupExprs, even when
occuring on..." which breaks some Objective-C code. Working on getting a test
case...
Douglas Gregor [Wed, 19 May 2010 18:39:18 +0000 (18:39 +0000)]
Cache the linkage of a type within its canonical type, eliminating
some seriously non-linear performance with deeply nested template
instantiations, as shown in PR6998.