Douglas Gregor [Fri, 17 Jun 2011 23:16:24 +0000 (23:16 +0000)]
Objective-C++ ARC: eliminate the utterly unjustified loophole that
silently dropped ownership qualifiers that were being applied to
ownership-qualified, substituted type that was *not* a substituted
template type parameter. We now provide a diagnostic in such cases,
and recover by dropping the added qualifiers.
Douglas Gregor [Fri, 17 Jun 2011 22:26:49 +0000 (22:26 +0000)]
Objective-C++ ARC: do not mangle __unsafe_unretained lifetime
qualifiers, so that an __unsafe_unretained-qualified type T in ARC code
will have the same mangling as T in non-ARC code, improving ABI
interoperability. This works now because we infer or require a
lifetime qualifier everywhere one can appear in an external
interface. Another part of <rdar://problem/9595486>.
Douglas Gregor [Fri, 17 Jun 2011 22:11:49 +0000 (22:11 +0000)]
Objective-ARC++: infer template type arguments of
ownership-unqualified retainable object type as __strong. This allows
us to write, e.g.,
std::vector<id>
and we'll infer that the vector's element types have __strong
ownership semantics, which is far nicer than requiring:
std::vector<__strong id>
Note that we allow one to override the ownership qualifier of a
substituted template type parameter, e.g., given
template<typename T>
struct X {
typedef __weak T type;
};
X<id> is treated the same as X<__strong id>. At instantiation type,
the __weak in "__weak T" overrides the (inferred or specified)
__strong on the template argument type, so that we can still provide
metaprogramming transformations.
Richard Trieu [Fri, 17 Jun 2011 20:35:48 +0000 (20:35 +0000)]
Put the new warning from revision 133196 on NULL arithmetic behind the flag -Wnull-arthimetic and set to DefaultIgnore. A few edge cases need to be worked out before this can be set to default.
Douglas Gregor [Fri, 17 Jun 2011 16:37:20 +0000 (16:37 +0000)]
When emitting a compound literal of POD type, continue to emit a
separate aggregate temporary and then memcpy it over to the
destination. This fixes a regression I introduced with r133235, where
the compound literal on the RHS of an assignment makes use of the
structure on the LHS of the assignment.
I'm deeply suspicious of AggExprEmitter::VisitBinAssign()'s
optimization where it emits the RHS of an aggregate assignment
directly into the LHS lvalue without checking whether there is any
aliasing between the LHS/RHS. However, I'm not in a position to
revisit this now.
John McCall [Fri, 17 Jun 2011 06:42:21 +0000 (06:42 +0000)]
Objective-C fast enumeration loop variables are not retained in ARC, but
they should still be officially __strong for the purposes of errors,
block capture, etc. Make a new bit on variables, isARCPseudoStrong(),
and set this for 'self' and these enumeration-loop variables. Change
the code that was looking for the old patterns to look for this bit,
and change IR generation to find this bit and treat the resulting
variable as __unsafe_unretained for the purposes of init/destroy in
the two places it can come up.
Douglas Gregor [Fri, 17 Jun 2011 05:18:17 +0000 (05:18 +0000)]
Factor the checking of the deduced argument type against the actual
argument type for C++ [temp.deduct.call]p4 out of
Sema::FinishTemplateArgumentDeduction(). No functionality change.
Douglas Gregor [Fri, 17 Jun 2011 05:09:08 +0000 (05:09 +0000)]
When an explicit specialization has a storage specifier, error if that
storage specifier is different from the storage specifier on the
template. If that storage specifier is the same, then we only warn.
Douglas Gregor [Fri, 17 Jun 2011 04:59:12 +0000 (04:59 +0000)]
Implement proper support for generating code for compound literals in
C++, which means:
- binding the temporary as needed in Sema, so that we generate the
appropriate call to the destructor, and
- emitting the compound literal into the appropriate location for
the aggregate, rather than trying to emit it as a temporary and
memcpy() it.
Douglas Gregor [Fri, 17 Jun 2011 03:41:35 +0000 (03:41 +0000)]
Downgrade the error complaining about presence of a storage class
specifier on an explicit specialization to a warning, since neither
EDG nor GCC diagnose this code as ill-formed.
Eric Christopher [Fri, 17 Jun 2011 01:53:34 +0000 (01:53 +0000)]
Check the specific target to figure out if a constraint is a valid
register constraint. Note that we're not checking if the register itself
is valid for the constraint.
John McCall [Fri, 17 Jun 2011 00:18:42 +0000 (00:18 +0000)]
When synthesizing implicit copy/move constructors and copy/move assignment
operators, don't make an initializer or sub-operation for zero-width
bitfields.
Chris Lattner [Thu, 16 Jun 2011 22:58:10 +0000 (22:58 +0000)]
Fix a regression introduced by r131955 which broke #include_next in subtle situations
because the Angled directories and the System directories were not being uniqued
together, breaking #include_next. I'll see about a testcase, but it will be insane.
Douglas Gregor [Thu, 16 Jun 2011 17:56:04 +0000 (17:56 +0000)]
Teach the warning about non-POD memset/memcpy/memmove to deal with the
__builtin_ versions of these functions as well as the normal function
versions, so that it works on platforms where memset/memcpy/memmove
are macros that map down to the builtins (e.g., Darwin). Fixes
<rdar://problem/9372688>.
Douglas Gregor [Thu, 16 Jun 2011 16:50:48 +0000 (16:50 +0000)]
Implement the consistency checking for C++ [temp.deduct.call]p3, which
checks that the deduced argument type for a function call matches the
actual argument type provided. The only place we've found where the
consistency checking should actually cause template argument deduction
failure is due to qualifier differences that don't fall into the realm
of qualification conversions (which are *not* checked when we
initially perform deduction). However, we're performing the full
checking as specified in the standard to ensure that no other cases
exist.
Chandler Carruth [Thu, 16 Jun 2011 16:17:05 +0000 (16:17 +0000)]
Raise the ARCMT functionality in Clang into proper FrontendActions.
These are somewhat special in that they wrap any other FrontendAction,
running various ARC transformations or checks prior to the standard
action's run. To implement them easily, this extends FrontendAction to
have a WrapperFrontendAction utility class which forwards all calls by
default to an inner action setup at construction time. This is then
subclassed to override the specific behavior needed by the different
ARCMT tools.
Finally, FrontendTool is taught how to create these wrapper actions from
the existing flags and options structures.
The result is that clangFrontend no longer depends on clangARCMigrate.
This is very important, as clangARCMigrate *heavily* depends on
clangFrontend. Fundamentally ARCMigrate is at the same layer as
a library like Rewrite, sitting firmly on top of the Frontend, but tied
together with the FrontendTool when building the clang binary itself.
NAKAMURA Takumi [Thu, 16 Jun 2011 12:43:57 +0000 (12:43 +0000)]
Be aware of (x86_64-redhat-linux6E-)g++44 on RHEL5.
AFAIK, RHEL5 (and its clones) provides g++44 as the package "gcc44-c++".
By default, g++-4.1.1 is available, though, its libstdc++ would not be suitable to clang++.
Chandler Carruth [Thu, 16 Jun 2011 09:09:40 +0000 (09:09 +0000)]
Rework the warning for 'memset(p, 0, sizeof(p))' where 'p' is a pointer
and the programmer intended to write 'sizeof(*p)'. There are several
elements to the new version:
1) The actual expressions are compared in order to more accurately flag
the case where the pattern that works for an array has been used, or
a '*' has been omitted.
2) Only do a loose type-based check for record types. This prevents us
from warning when we happen to be copying around chunks of data the
size of a pointer and the pointer types for the sizeof and
source/dest match.
3) Move all the diagnostics behind the runtime diagnostic filter. Not
sure this is really important for this particular diagnostic, but
almost everything else in SemaChecking.cpp does so.
4) Make the wording of the diagnostic more precise and informative. At
least to my eyes.
5) Provide highlighting for the two expressions which had the unexpected
similarity.
6) Place this diagnostic under a flag: -Wsizeof-pointer-memaccess
This uses the Stmt::Profile system for computing #1. Because of the
potential cost, this is guarded by the warning flag. I'd be interested
in feedback on how bad this is in practice; I would expect it to be
quite cheap in practice. Ideas for a cheaper / better way to do this are
also welcome.
The diagnostic wording could likely use some further wordsmithing.
Suggestions welcome here. The goals I had were to: clarify that its the
interaction of 'memset' and 'sizeof' and give more reasonable
suggestions for a resolution.
An open question is whether these diagnostics should have the note
attached for silencing by casting the dest/source pointer to void*.
Jordy Rose [Thu, 16 Jun 2011 07:13:34 +0000 (07:13 +0000)]
[analyzer] Clean up modeling of strcmp, including cases where a string literal has an embedded null character, and where both arguments are the same buffer. Also use nested ifs rather than early returns; in this case early returns will lose any assumptions we've made earlier in the function.
Chandler Carruth [Thu, 16 Jun 2011 06:47:06 +0000 (06:47 +0000)]
Make the Stmt::Profile method const, and the StmtProfile visitor
a ConstStmtVisitor. This also required adding some const iteration
support for designated initializers and making some of the getters on
the designators const.
It also made the formatting of StmtProfile.cpp rather awkward. I'm happy
to adjust any of the formatting if folks have suggestions. I've at least
fitted it all within 80 columns.
Chandler Carruth [Thu, 16 Jun 2011 02:01:48 +0000 (02:01 +0000)]
Add the new arcmt-test tool to the clang-test dependencies with
c-index-test and friends. This brings the failures on CMake clang tests
from 23 to 2 on Linux.
Chandler Carruth [Thu, 16 Jun 2011 02:00:04 +0000 (02:00 +0000)]
Skip both character pointers and void pointers when diagnosing bad
argument types for mem{set,cpy,move}. Character pointers, much like void
pointers, often point to generic "memory", so trying to check whether
they match the type of the argument to 'sizeof' (or other checks) is
unproductive and often results in false positives.
Nico, please review; does this miss any of the bugs you were trying to
find with this warning? The array test case you had should be caught by
the array-specific sizeof warning I think.
Chandler Carruth [Thu, 16 Jun 2011 01:05:14 +0000 (01:05 +0000)]
Refactor parentheses suggestion notes to have less code duplication and
be more consistent in how parenthesized ranges which hit macros are
handled. Also makes the code significantly shorter, and the diagnostics
when macros are present a bit more useful.
Chandler Carruth [Thu, 16 Jun 2011 01:05:12 +0000 (01:05 +0000)]
Make the presentation of the warnings on 'x + y ? 1 : 0' a bit more
pretty. In particular this makes it much easier for me to read messages
such as:
x.cc:42: ?: has lower ...
Where I'm inclined to associate the third ':' with a missing column
number, but in fact column numbers have been turned off. Similar
punctuation collisions happened elsewhere as well.
Devang Patel [Wed, 15 Jun 2011 17:57:08 +0000 (17:57 +0000)]
Do not emit stoppoint before emitting debug info for parameters.
- llvm.dbg.declare already receives line number information from ParmDecl
- Additional extra stoppoint messes up gdb's understanding of where function body starts.
Douglas Gregor [Wed, 15 Jun 2011 16:02:29 +0000 (16:02 +0000)]
Eliminate a 'default' case in template argument deduction, where we
were just punting on template argument deduction for a number of type
nodes. Most of them, obviously, didn't matter.
As a consequence of this, make extended vector types (via the
ext_vector_type attribute) actually work properly for several
important cases:
- If the attribute appears in a type-id (i.e, not attached to a
typedef), actually build a proper vector type
- Build ExtVectorType whenever the size is constant; previously, we
were building DependentSizedExtVectorType when the size was constant
but the type was dependent, which makes no sense at all.
- Teach template argument deduction to handle
ExtVectorType/DependentSizedExtVectorType.
Douglas Gregor [Wed, 15 Jun 2011 14:20:42 +0000 (14:20 +0000)]
When performing substitution of default template template parameters
before the template parameters have acquired a proper context (e.g.,
because the enclosing context has yet to be built), provide empty
parameter lists for all outer template parameter scopes to inhibit any
substitution for those template parameters. Fixes PR9643 /
<rdar://problem/9251019>.