Manuel Klimek [Tue, 31 May 2011 23:49:32 +0000 (23:49 +0000)]
This patch implements an AST matching framework that allows to write
tools that match on the C++ ASTs. The main interface is in ASTMatchers.h,
an example implementation of a tool that removes redundant .c_str() calls
is in the example RemoveCStrCalls.cpp.
Various contributions:
Zhanyong Wan, Chandler Carruth, Marcin Kowalczyk, Wei Xu, James Dennett.
Francois Pichet [Tue, 31 May 2011 11:44:00 +0000 (11:44 +0000)]
For compatibility with MSVC, a friend declaration also act as a forward declaration if the tag name is not already declared. The tag name is declared in the next outermost non record scope.
Example:
Chandler Carruth [Sun, 29 May 2011 07:32:14 +0000 (07:32 +0000)]
Fix a regression in the source locations for unary trait expressions.
I tried to use an assert to prove that I could remove each of the
arguments I did, but ended up writing my assert with inverted logic.
Doh! Reported by Xi Wang on cfe-dev. I have manually verified the source
locations and ranges for these using -ast-dump. I tried writing a test
case that would catch these, but these expressions aren't exposed in the
c-index-test's token annotation utility.
Add a couple of helper methods in the SourceManager API, isAtStartOfMacroInstantiation/isAtEndOfMacroInstantiation
useful only for source locations that point at a macro token.
Eli Friedman [Fri, 27 May 2011 22:13:20 +0000 (22:13 +0000)]
Match llvm-gcc's string literals alignment by forcing alignment on string literals to 1. This can significantly impact the size of the string data, and as far as I know, the alignment doesn't help performance. rdar://9078969 .
Douglas Gregor [Fri, 27 May 2011 21:28:00 +0000 (21:28 +0000)]
Clean up my changes to jump-diagnostic handling for local variables of
class type (or array thereof), eliminating some redundant checks
(thanks Eli!) and adding some tests where the behavior differs in
C++98/03 vs. C++0x.
John McCall [Fri, 27 May 2011 20:01:14 +0000 (20:01 +0000)]
Implement a new, much improved version of the cleanup hack. We just need
to be careful to emit landing pads that are always prepared to handle a
cleanup path. This is correct mostly because of the fix to the LLVM
inliner, r132200.
Douglas Gregor [Fri, 27 May 2011 16:05:29 +0000 (16:05 +0000)]
Update the jump-scope checker for local variables with initializers,
so that it looks at the initializer of a local variable of class type
(or array thereof) to determine whether it's just an implicit
invocation of the trivial default constructor. Fixes PR10034.
Chandler Carruth [Fri, 27 May 2011 01:33:31 +0000 (01:33 +0000)]
Enhance Clang to start instantiating static data member definitions
within class templates when they are necessary to complete the type of
the member. The canonical example is code like:
template <typename T> struct S {
static const int arr[];
static const int x;
static int f();
};
We need to instantiate S<T>::arr's definition to pick up its initializer
and complete the array type. This involves new code to specially handle
completing the type of an expression where the type alone is
insufficient. It also requires *updating* the expression with the newly
completed type. Fortunately, all the other infrastructure is already in
Clang to do the instantiation, do the completion, and prune out the
unused bits of code that result from this instantiation.
This addresses the initial bug in PR10001, and will be a step to
fleshing out other cases where we need to work harder to complete an
expression's type. Who knew we still had missing C++03 "features"?
Douglas Gregor [Fri, 27 May 2011 01:19:52 +0000 (01:19 +0000)]
Objective-C doesn't consider the use of incomplete types as method
parameter types to be ill-formed. However, it relies on the
completeness of method parameter types when producing metadata, e.g.,
for a protocol, leading IR generating to crash in such cases.
Since there's no real way to tighten down the semantics of Objective-C
here without breaking existing code, do something safe but lame:
suppress the generation of metadata when this happens.
Richard Trieu [Thu, 26 May 2011 20:49:16 +0000 (20:49 +0000)]
Change the include stack of "instantiated from" notes to fall under the control of f/fno-diagnostics-show-note-include-stack flags. This should help with reducing diagnostic spew from macros instantiations.
Richard Trieu [Thu, 26 May 2011 20:11:09 +0000 (20:11 +0000)]
Add a fix-it and better error recovery for improperly nested namespaces. This will give a better error message for cases such as "namespace foo::bar::baz {}" and a suggested fix-it of "namespace foo { namespace bar { namespace baz {} } }"
Chandler Carruth [Thu, 26 May 2011 08:53:16 +0000 (08:53 +0000)]
Extract two more methods from the unary type trait checking. These
provide re-usable forms of the rest of the custom validation done here.
Still no functionality changed here.
With this it should be possible to have an expression-centric code path
and a type-centric code path which don't duplicate logic.
Chandler Carruth [Thu, 26 May 2011 08:53:14 +0000 (08:53 +0000)]
Remove a no longer relevant comment. It was just repeating the
information in the previous comment which was preserved and moved with
the vec_step implementation code.
Chandler Carruth [Thu, 26 May 2011 08:53:12 +0000 (08:53 +0000)]
Extract the vec_step trait operand checking to a stand alone function.
It has little overlap with other traits' requirements, so the resulting
code is actually simpler.
Chandler Carruth [Thu, 26 May 2011 08:53:10 +0000 (08:53 +0000)]
Add a convenience interface for checking expression arguments to unary
traits which uses the information embedded in the expression. Use this
to simplify several interfaces which repeated information embedded in
the expression through explicit arguments. I added an assertion that the
only extra piece of data to come in from the parser matches what is
stored in the expression. No functionality change intended here.
Also cleaned up the doxygen comments for some of these methods and some
formatting oddities.
Sean Hunt [Thu, 26 May 2011 01:26:05 +0000 (01:26 +0000)]
Implement a new warning for when adding a default argument to a method
makes it into a special member function. This is very bad and can lead
to all sorts of nastiness including implicit member functions violating
the One Definition Rule. This should probably be made ill-formed in a
later version of the standard, but for now we'll just warn.
Eli Friedman [Thu, 26 May 2011 00:10:27 +0000 (00:10 +0000)]
Skip extra copy from aggregate where it isn't necessary; rdar://problem/8139919 . This shouldn't make much of a difference at -O3, but should substantially reduce the number of generated memcpy's at -O0.
Originally r130717, but was backed out due to an ObjC regression.
Sean Hunt [Wed, 25 May 2011 20:50:04 +0000 (20:50 +0000)]
Implement a little bit of cleanup and a lot more of the base work
behind implicit moves. We now correctly identify move constructors and
assignment operators and update bits on the record correctly. Generation
of implicit moves (declarations or definitions) is not yet supported.
A StringRef-ication of the DiagnosticIDs API and internals.
Patch by Matthieu Monrocq with tweaks by me to avoid StringRefs in the static
diagnostic data structures, which resulted in a huge global-var-init function.
Sean Hunt [Tue, 24 May 2011 22:41:36 +0000 (22:41 +0000)]
Implement a new type node, UnaryTransformType, designed to represent a
type that turns one type into another. This is used as the basis to
implement __underlying_type properly - with TypeSourceInfo and proper
behavior in the face of templates.
Douglas Gregor [Tue, 24 May 2011 16:02:01 +0000 (16:02 +0000)]
Implement the initial part of C++0x [expr.const]p2, which specifies
that the unevaluated subexpressions of &&, ||, and ? : are not
considered when determining whether the expression is a constant
expression. Also, turn the "used in its own initializer" warning into
a runtime-behavior warning, so that it doesn't fire when a variable is
used as part of an unevaluated subexpression of its own initializer.
Chandler Carruth [Tue, 24 May 2011 07:43:19 +0000 (07:43 +0000)]
Fix a bug in -Wundefined-reinterpret-cast where we failed to look
through sugared types when testing for TagTypes. This was the actual
cause of the only false positive in Clang+LLVM.
Next evaluation will be over a much larger selection of code including
large amounts of open source code.
Sean Hunt [Mon, 23 May 2011 23:56:01 +0000 (23:56 +0000)]
Delete the extraneous return statement that was causing my earlier
issues and also add a test.
We should now handle defaulted members of templates properly. No
comment as to whether or not this also holds for templated functions,
but defaulting those is kind of insane.
Sean Hunt [Mon, 23 May 2011 23:14:04 +0000 (23:14 +0000)]
Implement explicit specialization of explicitly-defaulted constructors.
The general out-of-line case (including explicit instantiation mostly
works except that the definition is being lost somewhere between the AST
and CodeGen, so the definition is never emitted.
Sean Hunt [Mon, 23 May 2011 21:07:59 +0000 (21:07 +0000)]
Correctly propagate defaultedness across template instantiation. This
fixes PR9965, but we're not out of the water yet, as we do not
successfully handle out-of-line definitions, due to my utter
misunderstanding of how we manage templates.
Francois Pichet [Mon, 23 May 2011 03:43:44 +0000 (03:43 +0000)]
Emulate a MSVC bug where if during an using declaration name lookup, the declaration found is unaccessible (private) and that declaration was bring into scope via another using declaration whose target declaration is accessible (public) then no error is generated.
Example:
class A { public: int f(); };
class B : public A { private: using A::f; };
class C : public B { private: using B::f; };
Here, B::f is private so this should fail in Standard C++, but because B::f refers to A::f which is public MSVC accepts it.
This fixes 1 error when parsing MFC code with clang.
Chris Lattner [Sun, 22 May 2011 23:35:00 +0000 (23:35 +0000)]
make the x86-32 backend specify a byval alignment, even when the
code generator will do it. With this patch, clang compiles the example
in PR9794 to not have an alloca temporary.
Chris Lattner [Sun, 22 May 2011 23:21:23 +0000 (23:21 +0000)]
Fix x86-64 byval passing to specify the alignment even when the code
generator will give it something sufficient. This is important because
the mid-level optimizer doesn't know what alignment is required otherwise.
Chris Lattner [Sun, 22 May 2011 22:10:16 +0000 (22:10 +0000)]
Invoke the FileChanged callback before pushing the linemarker for a system
header. Getting it in the wrong order generated incorrect line markers in -E
mode. In the testcase from PR9861 we used to generate:
Douglas Gregor [Sun, 22 May 2011 00:21:10 +0000 (00:21 +0000)]
Add an assertion to tell us when we're going off the deep end trying
to determine outer template arguments lists for template
parameters. This is actually the problem behind PR9643, which I have
yet to figure out how to fix.
Douglas Gregor [Sat, 21 May 2011 23:15:46 +0000 (23:15 +0000)]
Audit and finish the implementation of C++0x nullptr, fixing two
minor issues along the way:
- Non-type template parameters of type 'std::nullptr_t' were not
permitted.
- We didn't properly introduce built-in operators for nullptr ==,
!=, <, <=, >=, or > as candidate functions .
To my knowledge, there's only one (minor but annoying) part of nullptr
that hasn't been implemented: catching a thrown 'nullptr' as a pointer
or pointer-to-member, per C++0x [except.handle]p4.
Douglas Gregor [Sat, 21 May 2011 22:16:50 +0000 (22:16 +0000)]
It's considered poor form to create references to the overloaded
function type. Educate template argument deduction thusly, fixing
PR9974 / <rdar://problem/9479155>.