Jay Foad [Mon, 20 Jun 2011 14:38:01 +0000 (14:38 +0000)]
Change how PHINodes store their operands.
Change PHINodes to store simple pointers to their incoming basic blocks,
instead of full-blown Uses.
Note that this loses an optimization in SplitCriticalEdge(), because we
can no longer walk the use list of a BasicBlock to find phi nodes. See
the comment I removed starting "However, the foreach loop is slow for
blocks with lots of predecessors".
Extend replaceAllUsesWith() on a BasicBlock to also update any phi
nodes in the block's successors. This mimics what would have happened
when PHINodes were proper Users of their incoming blocks. (Note that
this only works if OldBB->replaceAllUsesWith(NewBB) is called when
OldBB still has a terminator instruction, so it still has some
successors.)
Chandler Carruth [Mon, 20 Jun 2011 08:59:25 +0000 (08:59 +0000)]
Use an explicitly 64-bit triple flag to ensure we can easily verify the
types printed in various diagnostics.
We could omit checking for the types, but that can mask errors where the
wrong type is streamed into the diagnostic. There was at least one of
these caught by this test already.
Chandler Carruth [Mon, 20 Jun 2011 07:52:11 +0000 (07:52 +0000)]
Fix a problem with the diagnostics of invalid arithmetic with function
pointers I found while working on the NULL arithmetic warning. We here
always assuming the LHS was the pointer, instead of using the selected
pointer expression.
Chandler Carruth [Mon, 20 Jun 2011 07:38:51 +0000 (07:38 +0000)]
Move away from the poor "abstraction" I added to Type. John argued
effectively that this abstraction simply doesn't exist. That is
highlighted by the fact that by using it we were papering over a more
serious error in this warning: the fact that we warned for *invalid*
constructs involving member pointers and block pointers.
I've fixed the obvious issues with the warning here, but this is
confirming an original suspicion that this warning's implementation is
flawed. I'm looking into how we can implement this more reasonably. WIP
on that front.
Chris Lattner [Mon, 20 Jun 2011 04:01:35 +0000 (04:01 +0000)]
Update to match mainline ConstantStruct::get API change. Also, use
ConvertType on InitListExprs as they are being converted. This is
needed for a forthcoming patch, and improves the IR generated anyway
(see additional type names in testcases).
This patch also converts a bunch of std::vector's in CGObjCMac to use
C arrays. There are a ton more that should be converted as well.
Jordy Rose [Mon, 20 Jun 2011 03:49:16 +0000 (03:49 +0000)]
[analyzer] Re-enable checking for strncpy, along with a new validation of the size argument. strncat is not yet up-to-date, but I'm leaving it enabled for now (there shouldn't be any false positives, at least...)
Jordy Rose [Mon, 20 Jun 2011 02:06:40 +0000 (02:06 +0000)]
[analyzer] Eliminate "byte string function" from CStringChecker's diagnostics, and make it easier to provide custom messages for overflow checking, in preparation for re-enabling strncpy checking.
Chandler Carruth [Mon, 20 Jun 2011 01:23:19 +0000 (01:23 +0000)]
Restructure the API in Type based on a conversation with Richard Smith.
This makes 'isPointerLikeType' a little less confusing, and pulls the
decay check into a separate interface that is much more clear and
concrete. Also, just implement these as logical wrappers around other
predicates. Having a switch based implementation isn't likely to be
necessary. We can try to optimize them later if they show up on
a profile.
Chandler Carruth [Sun, 19 Jun 2011 09:05:19 +0000 (09:05 +0000)]
Turn -Wnull-arithmetic back on by default -- we now have tests for the
false positives, including those in the GCC test suite, and don't warn
about them.
Let me know if this causes fallout, we can turn it back off if needed.
Chandler Carruth [Sun, 19 Jun 2011 09:05:14 +0000 (09:05 +0000)]
Add test cases for false positives on -Wnull-arithmetic from Richard
Trieu, and fix them by checking for array and function types as well as
pointer types.
I've added a predicate method on Type to bundle together the logic we're
using here: isPointerLikeType(). I'd welcome better names for this
predicate, this is the best I came up with. It's implemented as a switch
to be a touch lighter weight than all the chained isa<...> casts that
would result otherwise.
John McCall [Sat, 18 Jun 2011 07:31:30 +0000 (07:31 +0000)]
A couple of minor changes to the ARC spec, plus a new section
specifying that retain/release/autorelease/retainCount are forbidden,
plus a section talking about the behavior of dealloc.
Chandler Carruth [Sat, 18 Jun 2011 01:19:03 +0000 (01:19 +0000)]
Accept no-return stripping conversions for pointer type arguments after
deducing template parameter types. Recently Clang began enforcing the
more strict checking that the argument type and the deduced function
parameter type (after substitution) match, but that only consideres
qualification conversions.
One problem with this patch is that we check noreturn conversions and
qualification conversions independently. If a valid conversion would
require *both*, perhaps interleaved with each other, it will be
rejected. If this actually occurs (I'm not yet sure it does) and is in
fact a problem (I'm not yet sure it is), there is a FIXME to implement
more intelligent conversion checking.
However, this step at least allows Clang to resume accepting valid code
we're seeing in the wild.
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.