James Dennett [Thu, 11 Jul 2013 03:51:36 +0000 (03:51 +0000)]
Documentation cleanup for DeclCXX.h:
* Fixing up \brief summaries (adding some, making some briefer);
* Standardizing on \commands, not @commands;
* Update C++0x references to C++11;
* Fix typos and Doxygen warnings.
Richard Smith [Thu, 11 Jul 2013 02:27:57 +0000 (02:27 +0000)]
Add a __builtin_addressof that performs the same functionality as the built-in
& operator (ignoring any overloaded operator& for the type). The purpose of
this builtin is for use in std::addressof, to allow it to be made constexpr;
the existing implementation technique (reinterpret_cast to some reference type,
take address, reinterpert_cast back) does not permit this because
reinterpret_cast between reference types is not permitted in a constant
expression in C++11 onwards.
Richard Smith [Wed, 10 Jul 2013 22:04:13 +0000 (22:04 +0000)]
If we friend a declaration twice, that should not make it visible to name
lookup in the surrounding context. Slightly rework how we handle friend
declarations to inherit the visibility of the prior declaration, rather
than setting a friend declaration to be visible whenever there was a prior
declaration.
ObjC migrator: Improve on hueristics.
migrate to 'copy attribute if Object
class implements NSCopying otherwise
assume implied 'strong'. Remove
lifetime qualifier on property as it has
moved to property's attribute. Added TODO
comment for future work by poking into
setter implementation.
Jordan Rose [Wed, 10 Jul 2013 19:14:10 +0000 (19:14 +0000)]
[analyzer] Remove bogus assert: in C++11, 'new' can do list-initialization.
Previously, we asserted that whenever 'new' did not include a constructor
call, the type must be a non-record type. In C++11, however, uniform
initialization syntax (braces) allow 'new' to construct records with
list-initialization: "new Point{1, 2}".
Removing this assertion should be perfectly safe; the code here matches
what VisitDeclStmt does for regions allocated on the stack.
James Dennett [Wed, 10 Jul 2013 18:29:15 +0000 (18:29 +0000)]
Add a hook RecursiveASTVisitor::TraverseLambdaBody, to enable visitors to
use/maintain additional state from the LambdaExpr while visiting the body
of a LambdaExpr.
One use for this arises because Clang's AST currently holds lambda bodies
in a form prior to their adjustment to refer to captured copies of local
variables, and so some clients will need access to the lambda's closure
type in order to query how to map VarDecl*s to the FieldDecls of their
by-copy captures. This hook is sufficient for at least one such client;
to do this without such a hook would require the client to re-implement
the whole of TraverseLambdaExpr, which is non-trivial and would likely be
more brittle.
Daniel Jasper [Wed, 10 Jul 2013 14:02:49 +0000 (14:02 +0000)]
Add experimental flag for adaptive parameter bin-packing.
This is not activated for any style, might change or go away
completely.
For those that want to play around with it, set
ExperimentalAutoDetectBinPacking to true.
clang-format will then:
Look at whether function calls/declarations/definitions are currently
formatted with one parameter per line (on a case-by-case basis). If so,
clang-format will avoid bin-packing the parameters. If all parameters
are on one line (thus that line is "inconclusive"), clang-format will
make the choice dependent on whether there are other bin-packed
calls/declarations in the same file.
The reason for this change is that bin-packing in some situations can be
really bad and an author might opt to put one parameter on each line. If
the author does that, he might want clang-format not to mess with that.
If the author is unhappy with the one-per-line formatting, clang-format
can easily be convinced to bin-pack by putting any two parameters on the
same line.
Eli Friedman [Wed, 10 Jul 2013 00:30:46 +0000 (00:30 +0000)]
More local mangling fixes.
Compute mangling numbers for externally visible local variables and tags.
Change the mangler to consistently use discriminators where necessary.
Tweak the scheme we use to number decls which are not externally visible
to avoid unnecessary discriminators in common cases now that we request
them more consistently.
Objective-C: merge objc_requires_super attribute of
method declaration into its implementation to
prevent a bogus warning about mismatched attributes.
then make sure the warning about missing call to super comes out
of the method implementation. // rdar://14251387
ObjC migrator: Add -objcmt-migrate-property to do property
migration. Also, fixes an old bug where older migration
flags were not being checked for properly.
Richard Smith [Tue, 9 Jul 2013 00:57:56 +0000 (00:57 +0000)]
Generalize hack allowing 'const' in __has_attribute (etc) to allow any token
with identifier info. This covers most identifier-like entities (other than
the ISO646 keywords).
Attempt typo correction for function calls with the wrong number of arguments.
Combined with typo correction's new ability to apply global/absolute nested
name specifiers to possible corrections, cases such as in PR12287 where the
desired function is being shadowed by a lexically closer function with the
same name but a different number of parameters will now include a FixIt.
On a side note, since the test for this change caused
test/SemaCXX/typo-correction.cpp to exceed the typo correction limit for
a single file, I've included a test case for exceeding the limit and added
some comments to both the original and part two of typo-correction.cpp
warning future editors of the files about the limit.
Eli Friedman [Mon, 8 Jul 2013 20:20:06 +0000 (20:20 +0000)]
Fix Sema for compares with _Atomic vars.
Use UsualArithmeticConversions unconditionally in analysis of
comparisons and conditional operators: the method performs
the usual arithmetic conversions if both sides are arithmetic, and
usual unary conversions if they are not. This is just a cleanup
for conditional operators; for comparisons, it fixes the issue that
we would try to check isArithmetic() on an atomic type.
Also, fix GetExprRange() in SemaChecking.cpp so it deals with variables
of atomic type correctly.
Fixed testcase failing under MS by adding "-fno-delayed-template-parsing",
as suggested by Takumi. To this end, added a MatchVerifier::match()
overload accepting a vector of invocation arguments.
Daniel Jasper [Mon, 8 Jul 2013 14:25:23 +0000 (14:25 +0000)]
Prefer similar line breaks.
This adds a penalty for clang-format for each break that occurs in
a set of parentheses (including fake parenthesis that determine
the range of certain operator precendences) that have not yet been
broken. Thereby, clang-format prefers similar line breaks.
This fixes llvm.org/PR15506.
Before:
const int kTrackingOptions =
NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited |
NSTrackingActiveAlways;
After:
const int kTrackingOptions = NSTrackingMouseMoved |
NSTrackingMouseEnteredAndExited |
NSTrackingActiveAlways;
Also removed ParenState::ForFakeParenthesis which has become unused.
Fix for corner cases in code handling leading "* " decorations in block comments
Summary:
Fixes problems that lead to incorrect formatting of these and similar snippets:
/*
**
*/
/*
**/
/*
* */
/*
*test
*/
Clang-format used to think that all the cases above use "* " decoration, and
failed to calculate insertion position properly. It also used to remove leading
"* " in the last line.
clang/test/Index/comment-custom-block-command.cpp: This has not been failing since r175892 on valgrind.
That said, it fails with --vg-leak. Mark it as XFAIL: vg_leak instead.
David Majnemer [Sun, 7 Jul 2013 23:49:50 +0000 (23:49 +0000)]
Sema: Do not merge new decls with invalid, old decls
Sema::MergeFunctionDecl attempts merging two decls even if the old decl
is invalid. This can lead to interesting circumstances where we
successfully merge the decls but the result makes no sense.
Take the following for example:
template <typename T>
int main(void);
int main(void);
Sema will not consider these to be overloads of the same name because
main can't be overloaded, which means that this must be a redeclaration.
In this case the templated decl is compatible with the non-templated
decl allowing the Sema::CheckFunctionDeclaration machinery to move on
and do bizarre things like setting the previous decl of a non-templated
decl to a templated decl!
The way I see it, we should just bail from MergeFunctionDecl if the old
decl is invalid.
James Dennett [Sun, 7 Jul 2013 05:19:50 +0000 (05:19 +0000)]
Documentation cleanup for include/clang/AST/DeclCXX.h, no substantive changes.
* Fix up \brief documentation;
* Update C++0x references to C++11;
* Doxygen formatting: bulleted lists start with a single hyphen, not two;
* Fix a typo, "assosiate" -> "associate".
David Majnemer [Sat, 6 Jul 2013 02:13:46 +0000 (02:13 +0000)]
Sema: Fix a crash when main is redeclared as a function-template.
This boils down to us sending invalid function decls to
CheckFunctionDeclaration becauswe we did not consider that CheckMain
could cause the decl to be invalid. Instead, interogate the new decl's
main-validity and *then* send it over to get CheckFunctionDeclaration'd
if it was still valid after calling CheckMain.
Eli Friedman [Fri, 5 Jul 2013 20:27:40 +0000 (20:27 +0000)]
Don't use mangleCXXRTTIName in TBAA for C code.
This changes the TBAA code so it doesn't use mangleCXXRTTIName in C,
because it doesn't really make sense there. Also, as sort of a
defense-in-depth change, fix the mangler so it handles C RecordDecls
correctly.
No tests because I don't know the TBAA code well enough to write a test,
and I don't know how else to trigger mangling a local struct in C.
Fixes a crash with r185450 reported by Joerg Sonnenberger.
Eli Friedman [Fri, 5 Jul 2013 18:41:30 +0000 (18:41 +0000)]
Fix regression from r185450.
As it turns out, the NoFunction bit for local class mangling needed to be
propagated into more places. r185450 turned what used to be an incorrect
mangling into an assertion.
We should not be asking unique_file to prepend the system temporary directory
when creating the html report. Unfortunately I don't think we can test this
with the current infrastructure since unique_file ignores MakeAbsolute if the
directory is already absolute and the paths provided by lit are.
I will take a quick look at making this api a bit less error prone.