Based on the new information in the AST provided by r130628, write
3 lines of code and improve a bunch of information in the libclang view
of the code.
Updates the two tests that exercise this with the new data, checking
that each new source location actually points back to the declared
template parameter.
Have the array type traits build an expression with type 'size_t'
instead of 'int'.
The Embarcadero spec says 'unsigned int', not 'int'. That's what
'size_t' is on Windows, but for Clang using a 'size_t' that can be
larger than int seems more appropriate.
Remove more dead code for emitting diagnostics. The callers of these
functions already precluded dependent types from reaching them.
Also change one of the callers to not error when a trait is applied to
a dependent type. This is a perfectly reasonable pattern, and both Unary
and Binary type traits already support dependent types (by populating
the AST with a nonce value).
Remove the actual diagnostic, since these aren't errors.
Convert the expression trait evaluation to a static function and
a switch with any default case. This both warns when an enumerator is
missing and asserts if a value sneaks through despite the warning.
While in there fix a bunch of coding style issues with this code.
Remove the default case from the unary type trait evaluation function,
adding an unreachable annotation. Remarkably this one was already
enumarting every trait.
Remove the type traits UTT_IsLvalueExpr and UTT_IsRvalueExpr.
As might be surmised from their names, these aren't type traits, they're
expression traits. Amazingly enough, they're expression traits that we
have, and fully implement. These "type" traits are even parsed from the
same tokens as the expression traits. Luckily, the parser only tried the
expression trait parsing for these tokens, so this was all just a pile
of dead code.
More cleanup of the type traits implementation.
1) Moved the completeness checking routine above the evaluation routine
so the reader sees that we do in fact check for complete types when
necessary.
2) Remove the FIXME comment about not doing this.
3) Make the arguments to the evaluate function agree in order with those
to the completeness checking function.
4) Completely specify the enumerators for the completeness checking
function rather than relying on a default.
5) Remove a check for the Borland language to only require complete
types in a few places. Borland's own documentation doesn't agree with
this: some of the previously unspecified traits *do* require
a complete type, some don't.
6) Correctly split the traits which do not require complete types from
those that do, clarifying comments and citations to the standard or
other documentation where relevant.
Order the type traits according to the standard's listing of unary type
traits where possible. For the rest, group them and add some
documentation regarding their origins.
Switch the interface name for both TemplateTypeParmType and
SubstTemplateTypeParmType to be 'getIdentifier' instead of 'getName' as
it returns an identifier. This makes them more consistent with the
NamedDecl interface.
Also, switch back to using this interface to acquire the indentifier in
TypePrinter.cpp. I missed this in r130628.
Re-applies the patch first applied way back in r106099, with
accompanying fixes to make it work today.
The core of this patch is to provide a link from a TemplateTypeParmType
back to the TemplateTypeParmDecl node which declared it. This in turn
provides much more precise information about the type, where it came
from, and how it functions for AST consumers.
To make the patch work almost a year after its first attempt, it needed
serialization support, and it now retains the old getName() interface.
Finally, it requires us to not attempt to instantiate the type in an
unsupported friend decl -- specifically those coming from template
friend decls but which refer to a specific type through a dependent
name.
A cleaner representation of the last item would be to build
FriendTemplateDecl nodes for these, storing their template parameters
etc, and to perform proper instantation of them like any other template
declaration. They can still be flagged as unsupported for the purpose of
access checking, etc.
This passed an asserts-enabled bootstrap for me, and the reduced test
case mentioned in the original review thread no longer causes issues,
likely fixed at somewhere amidst the 24k revisions that have elapsed.
Douglas Gregor [Sat, 30 Apr 2011 17:07:52 +0000 (17:07 +0000)]
When comparing parameters of reference-to-qualified type during
partial ordering of function templates, use a simple superset
relationship rather than the convertibility-implying
isMoreQualifiedThan/compatibilyIncludes relationship. Fixes partial
ordering between references and address-space-qualified references.
Switch the type-trait like APIs on the AST to only check for incomplete
types after looking through arrays. Arrays with an unknown bound seem to
be specifically allowed in the library type traits in C++0x, and GCC's
builtin __is_trivial returns 'true' for the type 'int[]'. Now Clang
agrees with GCC about __is_trivial here.
Also hardens these methods against dependent types by just returning false.
Extract a function to impose the completeness requirement on unary type
trait arguments. Reflow the logic to use early exit instead of a complex
condition expression. Switch to a switch for acting on different type
traits and add a bunch of the recently implemented type traits here.
This fixes one of the regressions with the new __is_standard_layout
trait to again require a complete type. It also fixes some latent bugs
in other traits that never did impose this despite the standard
requiring it. However, all these bugs were hidden for non-borland
systems where the default is to require a complete type.
It's unclear to me what the best approach here is: providing an explicit
lists for the ones requiring complete types only w/ Borland and using
a default for the rest, or forcing this switch to enumerate the traits
and make it clear which way each one goes.
I'm still working on cleaning up the tests so that they actually catch
this, a much more comprehensive update to the tests will come once I've
worked through the bugs I'm finding via inspection.
Rename the last '[hH]asStandardLayout' entites to '[iI]sStandardLayout'
based on Doug's preferences when we discussed this in IRC. This brings
the wording more in line with the standard.
Hoist all of the type-specific trait logic for __is_standard_layout into
a Type method isStandardLayoutType, to keep our user API matching the
type trait builtins as closely as possible. Also, implement it in terms
of other Type APIs rather than in terms of other type traits. This
models the implementation on that of isLiteralType and isTrivialType.
There remain some common problems with these traits still, so this is
a bit of a WIP. However, we can now fix all of these traits at the same
time and in a consistent manner.
Completely re-implement the core logic behind the __is_standard_layout
type trait. The previous implementation suffered from several problems:
1) It implemented all of the logic in RecordType by walking over every
base and field in a CXXRecordDecl and validating the constraints of
the standard. This made for very straightforward code, but is
extremely inefficient. It also is conceptually wrong, the logic tied
to the C++ definition of standard-layout classes should be in
CXXRecordDecl, not RecordType.
2) To address the performance problems with #1, a cache bit was added to
CXXRecordDecl, and at the completion of every C++ class, the
RecordType was queried to determine if it was a standard layout
class, and that state was cached. Two things went very very wrong
with this. First, the caching version of the query *was never
called*. Even within the recursive steps of the walk over all fields
and bases the caching variant was not called, making each query
a full *recursive* walk. Second, despite the cache not being used, it
was computed for every class declared, even when the trait was never
used in the program. This probably significantly regressed compile
time performance for edge-case files.
3) An ASTContext was required merely to query the type trait because
querying it performed the actual computations.
4) The caching bit wasn't managed correctly (uninitialized).
The new implementation follows the system for all the other traits on
C++ classes by encoding all the state needed in the definition data and
building up the trait incrementally as each base and member are added to
the definition of the class.
The idiosyncracies of the specification of standard-layout classes
requires more state than I would like; currently 5 bits. I could
eliminate one of the bits easily at the expense of both clarity and
resilience of the code. I might be able to eliminate one of the other
bits by computing its state in terms of other state bits in the
definition. I've already done that in one place where there was a fairly
simple way to achieve it.
It's possible some of the bits could be moved out of the definition data
and into some other structure which isn't serialized if the serialized
bloat is a problem. That would preclude serialization of a partial class
declaration, but that's likely already precluded.
Daniel Dunbar [Sat, 30 Apr 2011 04:25:16 +0000 (04:25 +0000)]
Driver/Darwin: Don't link -lgcc_s.1 when compiling as iOS for the simulator,
that library has never been in the SDK. Fortunately, it shouldn't be necessary,
since that library was also removed in 10.6.
Daniel Dunbar [Sat, 30 Apr 2011 04:22:58 +0000 (04:22 +0000)]
Driver/Darwin: When using -mios-simulator-version-min, explicitly pass this on
to the linker.
- Only do this explicitly with the argument for now, the linker will need to
explicitly add support for this.
block variables on lhs need be ir-gen'ed after the
rhs when its 'forwarding' pointer may be modified
in rhs evaluation as result of call to Block_copy.
// rdar://9309454
Disable -Wnon-pod-memset for now while I try to reduce the false
positives still further.
The plan is to:
1) Create a more targeted warning for memset of memory pointing at
a type with virtual methods or bases where a vptr would be
overwritten.
2) Consider turning the above warning back on by default.
3) Evaluate whether any false positives in the existing warning can be
detected and white listed in the warning implementation.
4) If #3 lowers the noise floor enough, enable the full warning in -Wall
or -Wextra.
Comments or suggestions welcome. Even more welcome are specific test
cases which trigger the warning and shouldn't.
Charles Davis [Fri, 29 Apr 2011 15:50:52 +0000 (15:50 +0000)]
Remove comments about __int8 and friends from the mangler. Turns out we don't
actually have to implement them, since in modern versions of MSVC they're
aliases to the standard C types.
Relax the non-POD memset warning to use the less restrictive C++11
definition of POD. Specifically, this allows certain non-aggregate
types due to their data members being private.
The representation of C++11 POD testing is pretty gross. Any suggestions
for improvements there are welcome. Especially the name
'isCXX11PODType()' seems truly unfortunate.
Sebastian Redl [Fri, 29 Apr 2011 08:19:30 +0000 (08:19 +0000)]
Add a decl update when a static data member of a class template is instantiated in a different PCH than its containing class. Otherwise we get double definition errors. Fixes a Boost.MPL problem that affects Boost.Accumulators and probably a lot more of Boost.
Don't assume that the AST methods will only be invoked on C++ types.
Teaches isLiteralType and isTrivialType to behave plausibly and most
importantly not crash on normal RecordDecls.
Sadly I have no real way to test this. I stumbled onto it by
mis-implementing a warning.
Cut down unnecessary zero'ing when value-initializing arrays of C++ objects.
-C++ objects with user-declared constructor don't need zero'ing.
-We can zero-initialize arrays of C++ objects in "bulk" now, in which case don't zero-initialize each object again.
Use StringRef::substr() and unbounded StringRef::compare() instead of bounded version of StringRef::compare() because bounded version of StringRef::compare() is going to be removed.
Make the top-level driver ignore -fobjc-default-synthesize-properties while this feature undergoes more review and development. This is still available as a -cc1 option for testing.
Eliminates an assert in the strncpy/strncat checker caused by not validating a cast was successful. If the value of an argument was unknown, the cast would result in a NULL pointer which was later being dereferenced.
Douglas Gregor [Thu, 28 Apr 2011 17:56:11 +0000 (17:56 +0000)]
When determining whether two types are reference-compatible, check
non-CVR qualifiers as well as CVR qualifiers. For example, don't allow
a reference to an integer in address space 1 to bind to an integer in
address space 2.
Douglas Gregor [Thu, 28 Apr 2011 15:48:45 +0000 (15:48 +0000)]
libstdc++ 4.4 uses __is_signed as an identifier, while Clang treats it
as a keyword for the __is_signed type trait. Cope with this conflict
via some hackish recovery: if we see a declaration of the form
static const bool __is_signed
then we stop treating __is_signed as a keyword and instead treat it as
an identifier. It's ugly, but it's better than making the __is_signed
type trait conditional on some language flag. Fixes PR9804.
Silence more -Wnon-pod-memset given its current implementation. I may be
able to revert these based on a patch I'm working on, but no reason for
people to be spammed with warnings in the interim.