Sebastian Redl [Wed, 7 Jul 2010 23:17:38 +0000 (23:17 +0000)]
Rip out the C++0x-specific handling of destructor names. The specification is still in flux and unclear, and our interim workaround was broken. Fixes PR7467.
Douglas Gregor [Wed, 7 Jul 2010 23:08:52 +0000 (23:08 +0000)]
A using declaration can redeclare a typedef to the same type. These
typedefs won't have the same canonical declaration (since they are
distinct), so we need to check for this case specifically. Fixes
<rdar://problem/8018262>.
Douglas Gregor [Wed, 7 Jul 2010 22:35:13 +0000 (22:35 +0000)]
Do not use CXXZeroValueInitExpr for class types. Instead, use
CXXConstructExpr/CXXTemporaryObjectExpr/CXXNewExpr as
appropriate. Fixes PR7556, and provides a slide codegen improvement
when copy-initializing a POD class type from a value-initialized
temporary. Previously, we weren't eliding the copy.
Zhanyong Wan [Wed, 7 Jul 2010 21:36:58 +0000 (21:36 +0000)]
Changes how the TypeLoc traverser invokes the Type traverser: before,
VisitFooTypeLoc() calls VisitFooType(); now, TraverseFooTypeLoc()
calls WalkUpFromFooType(). This allows clients that override
WalkUpFromFooType() to continue to work. It also preserves the
property that Visit*() in the base visitor class is a no-op (s.t. a
subclass doesn't have to call Base::Visit*() when overriding
Visit*()).
Also fixes some typos in comments.
Also added a missing getDerived() inside
TraverseQualifiedTypeLoc(). The call is needed in case a subclass
overrides TraverseTypeLoc().
This has 2 (slight) advantages:
-Make explicit at getBody()'s callsite that we expect/handle only CompoundStmt and not CXXTryStmt.
-Better tracking of Decl::getBody()'s callsites.
Introduce Decl::hasBody() and FunctionDecl::hasBody() and use them instead of getBody() when we are just checking the existence of a body, to avoid de-serialization of the body from PCH.
Makes de-serialization of the function body even more "lazier".
Jordy Rose [Wed, 7 Jul 2010 08:15:01 +0000 (08:15 +0000)]
Add memcmp() and bcmp() to CStringChecker. These check for valid access to the buffer arguments and have a special-case for when the buffer arguments are known to be the same address, or when the size is zero.
Chris Lattner [Wed, 7 Jul 2010 06:14:23 +0000 (06:14 +0000)]
implement PR7569, warning about assignment to null, which
people seem to write when they want a deterministic trap.
Suggest instead that they use a volatile pointer or
__builtin_trap.
Avoid double-traversing for QualifiedTypeLoc -- we were calling
VisitTypeLoc twice for qualified types, once for the qualified form
and once for the unqualified (though they looked the same by the time
we got to visittypeloc). Now only visit once, which matches previous
behavior.
Silence an annoying GCC warning about use of an uninitialized variable. Even
making the other switch case unreachable, or sinking the 'continue' into it
doesn't silence this.
John McCall [Tue, 6 Jul 2010 23:57:41 +0000 (23:57 +0000)]
Provide a hook for the benefit of clients using clang IR gen as a subroutine:
emit metadata associating allocas and global values with a Decl*. This feature
is controlled by an option that (intentionally) cannot be enabled on the command
line.
To use this feature, simply set
CodeGenOptions.EmitDeclMetadata = true;
and then interpret the completely underspecified metadata. :)
Jordy Rose [Tue, 6 Jul 2010 23:11:01 +0000 (23:11 +0000)]
Add a new path-sensitive checker for functions in <string.h>, for both null-terminated strings and memory blocks. Currently only checks memcpy(), memmove(), and bcopy(), but this is intended to be expanded soon.
Tom Care [Tue, 6 Jul 2010 21:43:29 +0000 (21:43 +0000)]
Added a path-sensitive idempotent operation checker (-analyzer-idempotent-operation). Finds idempotent and/or tautological operations in a path sensitive context, flagging operations that have no effect or a predictable effect.
Example:
{
int a = 1;
int b = 5;
int c = b / a; // a is 1 on all paths
}
- New IdempotentOperationChecker class
- Moved recursive Stmt functions in r107675 to IdempotentOperationChecker
- Minor refactoring of SVal to allow checking for any integer
- Added command line option for check
- Added basic test cases
Douglas Gregor [Tue, 6 Jul 2010 18:42:40 +0000 (18:42 +0000)]
Improve the accuracy of getSourceRange() for DeclaratorDecl and
TagDecl subclasses when out-of-line template declaration information
is available, from Peter Collingbourne!
Douglas Gregor [Tue, 6 Jul 2010 18:29:01 +0000 (18:29 +0000)]
Remove my egregious hack that forced deserialization of visible
declarations when implicitly declaring the default constructor, copy
constructor, destructor, and copy-assignment operators of a
class. Argiris fixed the underlying problem in r107596.
Pacify versions of gcc that think these variables may be used
uninitialized (which doesn't seem to be the case), by giving
them arbitrary initial values.
Collect function definitions in the Indexer when indexing through the ASTs.
Add an API to get an Entity associated with a name in the global namespace.
Jordy Rose [Tue, 6 Jul 2010 04:12:24 +0000 (04:12 +0000)]
Remove the now-unused GRState::isEqual method. Instead of asking if an expression equals a certain value, use SValuator::EvalEQ and GRState::Assume to see if it can, must, or must not equal that value.
Jordy Rose [Tue, 6 Jul 2010 02:34:42 +0000 (02:34 +0000)]
Improve NULL-checking for CFRetain/CFRelease. We now remember that the argument was non-NULL, and we report where the null assumption came from (like AttrNonNullChecker already did).
John McCall [Tue, 6 Jul 2010 01:34:17 +0000 (01:34 +0000)]
Validated by nightly-test runs on x86 and x86-64 darwin, including after
self-host. Hopefully these results hold up on different platforms.
I tried to keep the GNU ObjC runtime happy, but it's hard for me to test.
Reimplement how clang generates IR for exceptions. Instead of creating new
invoke destinations which sequentially chain to the previous destination,
push a more semantic representation of *why* we need the cleanup/catch/filter
behavior, then collect that information into a single landing pad upon request.
Also reorganizes how normal cleanups (i.e. cleanups triggered by non-exceptional
control flow) are generated, since it's actually fairly closely tied in with
the former. Remove the need to track which cleanup scope a block is associated
with.
Document a lot of previously poorly-understood (by me, at least) behavior.
The new framework implements the Horrible Hack (tm), which requires every
landing pad to have a catch-all so that inlining will work. Clang no longer
requires the Horrible Hack just to make exceptions flow correctly within
a function, however. The HH is an unfortunate requirement of LLVM's EH IR.
Chris Lattner [Mon, 5 Jul 2010 20:21:00 +0000 (20:21 +0000)]
in the "coerce" case, the ABI handling code ends up making the
alloca for an argument. Make sure the argument gets the proper
decl alignment, which may be different than the type alignment.
Although in C++ class name has external linkage, usually the definition of the
class is available in the same translation unit when it's needed. So we make
all of them invalid Entity.
Fix a regression of a previous commit of mine (rdar://8158953).
Some of the invariant checks for creating Record/Enum types don't hold true during PCH reading.
Introduce more suitable ASTContext::getRecordType() and getEnumType().
When adding a visible decl, deserialize the visible decls and add it.
Before this commit, visible decls added before deserialization were ignored.
This was not an issue since name lookup (that usually comes before the addition) forces deserialization
but it is an issue for lazily declared class implicit members.
Don't try to install the __[u]int128_t identifier if it is already installed by PCHReader.
Currently, adding it to visible decls of a PCH'ed translation unit has no effect because
adding visible decls before deserialization has no effect (the decls won't be visible).
This will be fixed in a future commit; then it will force deserialization of visible decls, so avoid pointlessly installing it.
Nick Lewycky [Sun, 4 Jul 2010 21:29:45 +0000 (21:29 +0000)]
Add TypeLoc traversal to the RecursiveASTVisitor! Because the TypeLocs don't
contain all the same information that their Types do, we will fall back to
traversing the Types instead. The default TypeLoc visitor calls the matching
Type visitor so that existing clients should continue to work with no change.
Nick Lewycky [Sun, 4 Jul 2010 01:41:30 +0000 (01:41 +0000)]
Fix ObjCInterfaceTypeLoc to inherit from ObjCObjectTypeLoc so as to match the
Type hierarchy. Without this, TypeLocNodes.def will give you wrong type
hierarchy information (claiming that ObjCObjectTypeLoc is the base of
ObjCInterfaceTypeLoc, which it wasn't).
Jordy Rose [Sun, 4 Jul 2010 00:00:41 +0000 (00:00 +0000)]
Add a new symbol type, SymbolExtent, to represent the extents of memory regions that may not be known at compile-time (such as those created by malloc). This replaces the old setExtent/getExtent API on Store, which used the GRState's GDM to store SVals.
Also adds a getKnownValue() method to SValuator, which gets the integer value of an SVal if it is known to only have one possible value. There are more places in the code that could be using this, but in general we want to be dealing entirely in SVals, so its usefulness is limited.
The only visible functionality change is that extents are now honored for any DeclRegion, such as fields and Objective-C ivars, rather than just variables. This shows up in bounds-checking and cast-size-checking.
Charles Davis [Sat, 3 Jul 2010 16:56:59 +0000 (16:56 +0000)]
Mangle Objective-C pointers and block pointers in the Microsoft C++ Mangler.
ObjC pointers were easy enough (as far as the ABI is concerned, they're
just pointers to structs), but I had to invent a new mangling for block
pointers. This is particularly worrying with the Microsoft ABI, because
it is a vendor-specific ABI; extending it could come back to bite us
later when MS extends it on their own (and you know they will).
When setting the anonymous namespace at PCH reading, it may still be initializing so avoid
the invariant checks at NamespaceDecl::setAnonymousNamespace().
Charles Davis [Sat, 3 Jul 2010 02:41:45 +0000 (02:41 +0000)]
Fix mangling of array parameters for functions in the Microsoft C++ Mangler.
Only actual functions get mangled correctly; I don't know how to fix it for
function pointers yet. Thanks to John McCall for the hint.
Also, mangle anonymous tag types. I don't have a suitable testcase yet; I have
a feeling that that's going to need support for static locals, and I haven't
figured out exactly how MSVC's scheme for mangling those works.
Douglas Gregor [Sat, 3 Jul 2010 00:47:00 +0000 (00:47 +0000)]
Lazily declare default constructors. We now delay the construction of
declarations for implicit default constructors, copy constructors,
copy assignment operators, and destructors. On a "simple" translation
unit that includes a bunch of C++ standard library headers, we
generate relatively few of these implicit declarations now:
4/159 implicit default constructors created
18/236 implicit copy constructors created
70/241 implicit copy assignment operators created
0/173 implicit destructors created
And, on this translation unit, this optimization doesn't really
provide any benefit. I'll do some more performance measurements soon,
but this completes the implementation work for <rdar://problem/8151045>.