Commit Graph

15575 Commits

Author SHA1 Message Date
Jordan Rose 710f6b1259 [analyzer] Be more careful when downcasting for devirtualization.
Virtual base regions are never layered, so simply stripping them off won't
necessarily get you to the correct casted class. Instead, what we want is
the same logic for evaluating dynamic_cast: strip off base regions if possible,
but add new base regions if necessary.

llvm-svn: 161808
2012-08-13 23:46:01 +00:00
Jordan Rose 574ef152fc [analyzer] Handle dynamic_casts that turn out to be upcasts.
This can occur with multiple inheritance, which jumps from one parent to
the other, and with virtual inheritance, since virtual base regions always
wrap the actual object and can't be nested within other base regions.

This also exposed some incorrect logic for multiple inheritance: even if B
is known not to derive from C, D might still derive from both of them.

llvm-svn: 161798
2012-08-13 22:11:42 +00:00
Jordan Rose 07a7ed80cb [analyzer] Don't strip CXXBaseObjectRegions when checking dynamic_casts.
...and /do/ strip CXXBaseObjectRegions when casting to a virtual base class.

This allows us to enforce the invariant that a CXXBaseObjectRegion can always
provide an offset for its base region if its base region has a known class
type, by only allowing virtual bases and direct non-virtual bases to form
CXXBaseObjectRegions.

This does mean some slight problems for our modeling of dynamic_cast, which
needs to be resolved by finding a path from the current region to the class
we're trying to cast to.

llvm-svn: 161797
2012-08-13 22:11:34 +00:00
Richard Smith 47726b2f02 PR13570: When an unresolved overloaded call appeared in a dependent context, we
forgot to set it as being instantiation-dependent as well as being type- and
value-dependent.

llvm-svn: 161791
2012-08-13 21:29:18 +00:00
Manman Ren 6c30e137d0 ARM: enable struct byval for AAPCS-VFP.
rdar://9877866

llvm-svn: 161790
2012-08-13 21:23:55 +00:00
Fariborz Jahanian 7513fa346c c: small refactoring of checking for __attribute__(const))
per Richard's comment.

llvm-svn: 161786
2012-08-13 21:15:02 +00:00
Chad Rosier 65a8e0b69f [ms-inline asm] Have patchMSAsmStrings() return a vector or AsmStrings.
The AsmParser expects a single asm instruction, but valid ms-style inline asm
statements may contain  multiple instructions.

This happens with asm blocks

__asm {
  mov ebx, eax
  mov ecx, ebx
}

or when multiple asm statements are adjacent to one another

__asm mov ebx, eax
__asm mov ecx, ebx

and

__asm mov ebx, eax __asm mov ecx, ebx

Currently, asm blocks are not properly handled.

llvm-svn: 161780
2012-08-13 20:32:07 +00:00
Fariborz Jahanian 794ae1ea77 c: make __has_attribute(const) work for const
function attribute. // rdar://10253857

llvm-svn: 161767
2012-08-13 18:04:58 +00:00
Douglas Gregor 35ceb27fa4 When looking for the comment associated with a declaration, adjust the
'templated' declaration for a function or class template to refer to
the function or class template itself, to which the documentation will
be attached. Fixes PR13593.

llvm-svn: 161762
2012-08-13 16:37:30 +00:00
Alexander Kornienko bf4871d363 Implemented -ast-dump, -ast-print, -ast-dump-filter options in clang-check
llvm-svn: 161753
2012-08-13 10:50:08 +00:00
Dmitri Gribenko a43ec186a4 Attaching comments to declarations: find comment attached to any redeclaration
Not only look for the comment near the declaration itself, but also walk the
redeclaration chain: the previous declaration might have had a documentation
comment.

llvm-svn: 161722
2012-08-11 00:51:43 +00:00
Jordan Rose 02e5309b35 [analyzer] Strip CXXBaseObjectRegions when devirtualizing method calls.
This was causing a crash when we tried to re-apply a base object region to
itself. It probably also caused incorrect offset calculations in RegionStore.

PR13569 / <rdar://problem/12076683>

llvm-svn: 161710
2012-08-10 22:26:46 +00:00
Jordan Rose 51bcb226a2 [analyzer] Try to devirtualize even if the static callee has no definition.
This mostly affects pure virtual methods, but would also affect parent
methods defined inline in the header when analyzing the child's source file.

llvm-svn: 161709
2012-08-10 22:26:43 +00:00
Jordan Rose 13937b1d7a [analyzer] Add clang_analyzer_checkInlined for debugging purposes.
This check is also accessible through the debug.ExprInspection checker.
Like clang_analyzer_eval, you can use it to test the analyzer engine's
current state; the argument should be true or false to indicate whether or
not you expect the function to be inlined.

When used in the positive case (clang_analyzer_checkInlined(true)), the
analyzer prints the message "TRUE" if the function is ever inlined. However,
clang_analyzer_checkInlined(false) should never print a message; this asserts
that there should be no paths on which the current function is inlined, but
then there are no paths on which to print a message! (If the assertion is
violated, the message "FALSE" will be printed.)

This asymmetry comes from the fact that the only other chance to print a
message is when the function is analyzed as a top-level function. However,
when we do that, we can't be sure it isn't also inlined elsewhere (such as
in a recursive function, or if we want to analyze in both general or
specialized cases). Rather than have all checkInlined calls have an appended,
meaningless "FALSE" or "TOP-LEVEL" case, there is just no message printed.

void clang_analyzer_checkInlined(int);

For debugging purposes only!

llvm-svn: 161708
2012-08-10 22:26:29 +00:00
Fariborz Jahanian 29622c1f0b objective-C: test for delayed parsing of K&R funcitons
inside objc class implementation. // rdar://10387088

llvm-svn: 161705
2012-08-10 22:01:36 +00:00
Fariborz Jahanian f64b4722eb objective-C++: dalyed parsing of ctors with member
initializer list defined inside an objc class
implementation. wip

llvm-svn: 161699
2012-08-10 21:15:06 +00:00
Ted Kremenek 5d858cb916 Fix horrible regression in control of warnings caused by introduction of -Wpedantic.
While -Wpedantic was reasonable, -Wno-pedantic would turn off a bunch of warnings that
are on by default.  This counters the intention of this warning flag.

To fix this, -Wpedantic now includes extentions that are not on by default.  The
remaining warnings will manifest anyway, and won't accidentally get turned off
by -Wno-pedantic.

Fixes <rdar://problem/12076105>

llvm-svn: 161695
2012-08-10 20:50:00 +00:00
Manman Ren d4badd7420 ARM: enable struct byval for AAPCS.
rdar://9877866
PR://13350

llvm-svn: 161694
2012-08-10 20:42:31 +00:00
Fariborz Jahanian 053227f808 objective-C++: delay parsing of ctor with try block
with member initializer list defined inside
an objc implementation block. wip.

llvm-svn: 161692
2012-08-10 20:34:17 +00:00
DeLesley Hutchins 0c90c2bc4b Thread-safety-analysis: adds existential quantification over lock
expressions.  The syntax &MyClass::mutex is interpreted as a
pattern that matches m->mutex for any object m of type MyClass.

llvm-svn: 161691
2012-08-10 20:29:46 +00:00
DeLesley Hutchins 9b1d72f3e3 Thread safety analysis: refactor to support more sophisticated handling
of expressions, and better error messages.

llvm-svn: 161690
2012-08-10 20:19:55 +00:00
Dylan Noblesmith 8d48c8c675 Frontend: define _LP64 in a target-independent way
Instead of adding it to each individual subclass in
Targets.cpp, simply check the appropriate target
values.

Where before it was only on x86_64 and ppc64, it's now
also defined on mips64 and nvptx64.

Also add a bunch of negative tests to ensure it is *not*
defined on any other architectures while we're here.

llvm-svn: 161685
2012-08-10 19:12:37 +00:00
Anna Zaks d4e65373f3 [analyzer] ObjC Inlining: add tests for ivars and properties.
TODO:
 - Handle @syncronized properties.
 - Always inline properties declared publicly (do not split the path).
This is tricky since there is no mapping from a Decl to the property in
the AST as far as I can tell.

llvm-svn: 161683
2012-08-10 18:56:01 +00:00
Anna Zaks 75f49a9c07 [analyzer] Track if a region can be a subclass in the dynamic type info.
When object is allocated with alloc or init, we assume it cannot be a
subclass (currently used only for bifurcation purposes).

llvm-svn: 161682
2012-08-10 18:55:58 +00:00
Anna Zaks 920af014c1 [analyzer] Optimize dynamic dispatch bifurcation by detecting the cases
when we don't need to split.

In some cases we know that a method cannot have a different
implementation in a subclass:
 - the class is declared in the main file (private)
 - all the method declarations (including the ones coming from super
classes) are in the main file.

This can be improved further, but might be enough for the heuristic.
(When we are too aggressive splitting the state, efficiency suffers.
When we fail to split the state coverage might suffer.)

llvm-svn: 161681
2012-08-10 18:55:53 +00:00
Fariborz Jahanian 8cecfe9fc9 objective-C++: delayed parsing of member function with
function-try-block occuring in objc's implementation
block. wip.

llvm-svn: 161675
2012-08-10 18:10:56 +00:00
Fariborz Jahanian 712bb81a6d objective-C++: Delayed parsing of most common
member functions defined inside an objc class
implementation. wip.

llvm-svn: 161667
2012-08-10 15:54:40 +00:00
John McCall a0a9689550 Check access to friend declarations. There's a number of different
things going on here that were problematic:
  - We were missing the actual access check, or rather, it was suppressed
    on account of being a redeclaration lookup.
  - The access check would naturally happen during delay, which isn't
    appropriate in this case.
  - We weren't actually emitting dependent diagnostics associated with
    class templates, which was unfortunate.
  - Access was being propagated incorrectly for friend method declarations
    that couldn't be matched at parse-time.

llvm-svn: 161652
2012-08-10 03:15:35 +00:00
Jordan Rose b00073db80 Update VerifyDiagnosticConsumer to only get directives during parsing.
The old behavior was to re-scan any files (like modules) where we may have
directives but won't actually be parsing during the -verify invocation.
Now, we keep the old behavior in Debug builds as a sanity check (though
modules are a known entity), and expect all legitimate directives to come
from comments seen by the preprocessor.

This also affects the ARC migration tool, which captures diagnostics in
order to filter some out. This change adds an explicit cleanup to
CaptureDiagnosticsConsumer in order to let its sub-consumer handle the
real end of diagnostics.

This was originally split into four patches, but the tests do not run
cleanly without all four, so I've combined them into one commit.

Patches by Andy Gibbs, with slight modifications from me.

llvm-svn: 161650
2012-08-10 01:06:16 +00:00
Chad Rosier 1426a81a74 [ms-inline asm] Use the new Inline Asm Non-Standard Dialect attribute.
llvm-svn: 161642
2012-08-10 00:00:34 +00:00
Jordan Rose a44a55a8f2 [analyzer] Cluster bindings in RegionStore by base region.
This should speed up activities that need to access bindings by cluster,
such as invalidation and dead-bindings cleaning. In some cases all we save
is the cost of building the region cluster map, but other times we can
actually avoid traversing the rest of the store.

In casual testing, this produced a speedup of nearly 10% analyzing SQLite,
with /less/ memory used.

llvm-svn: 161636
2012-08-09 22:55:51 +00:00
Jordan Rose 996d309fb7 [analyzer] A CXXBaseObjectRegion should correspond to a DIRECT base.
An ASTContext's RecordLayoutInfo can only be used to look up offsets of
direct base classes, and we need the offset to make non-symbolic bindings
in RegionStore. This change makes sure that we have one layer of
CXXBaseObjectRegion for each base we are casting through.

This was causing crashes on an internal buildbot.

llvm-svn: 161621
2012-08-09 21:24:02 +00:00
Richard Smith 10c6072d61 In 'delete []', the '[]' never starts a lambda. Update a FIXME with a standard reference and add a test.
llvm-svn: 161604
2012-08-09 19:01:51 +00:00
Dmitri Gribenko bacbc08b98 Remove absolute file path in test.
llvm-svn: 161602
2012-08-09 18:35:49 +00:00
Dmitri Gribenko ba7aca3b38 Comment to HTML and XML conversion: ignore commands that contain a declaration
as their argument.  For example, \fn, \function, \typedef, \method, \class etc.

llvm-svn: 161601
2012-08-09 18:20:29 +00:00
Simon Atanasyan 38c63ed5f8 Fix the test case. Now it does not depend on the method used to pass vector arguments to the function.
Reviewed by Anton Lokhmotov.

llvm-svn: 161597
2012-08-09 17:49:22 +00:00
Dmitri Gribenko dcbc8ce2b5 Comment to HTML and XML conversion: use CommandTraits to classify commands.
This also fixes a bug in comment to XML conversion: \result was just an
ordinary paragraph, not an alias for \returns.

llvm-svn: 161596
2012-08-09 17:33:20 +00:00
Eli Friedman e66abdafa6 Fix AAPCS ABI. I can't actually test this, but it restores the behavior from before r159168. PR13562.
llvm-svn: 161554
2012-08-09 00:31:40 +00:00
Anna Zaks 123af098b8 [analyzer] Bifurcate the path with dynamic dispatch.
This is an initial (unoptimized) version. We split the path when
inlining ObjC instance methods. On one branch we always assume that the
type information for the given memory region is precise. On the other we
assume that we don't have the exact type info. It is important to check
since the class could be subclassed and the method can be overridden. If
we always inline we can loose coverage.

Had to refactor some of the call eval functions.

llvm-svn: 161552
2012-08-09 00:21:33 +00:00
Eli Friedman 89b1f2c7e1 Handle deprecation diagnostics correctly for C struct fields and Objective-C properties/ivars. <rdar://problem/6642337>.
llvm-svn: 161534
2012-08-08 23:04:35 +00:00
Dmitri Gribenko 6cffc1928a Comment XML: use xml:space="preserve" in Verbatim tags, so that XML tidy does
not compress spaces in verbatim content.

llvm-svn: 161531
2012-08-08 22:10:24 +00:00
Eli Friedman 971bfa11c6 Unify the codepaths for emitting deprecation warnings. The test changes are just to account for us emitting notes more consistently.
llvm-svn: 161528
2012-08-08 21:52:41 +00:00
Anna Zaks 13b0857ad0 Address code review comments for Wstrncat-size warning (r161440).
llvm-svn: 161527
2012-08-08 21:42:23 +00:00
Jordan Rose 742c6079e2 Implicitly annotate __CFStringMakeConstantString with format_arg(1).
We handled the builtin version of this function in r157968, but the builtin
isn't used when compiling as -fno-constant-cfstrings.

This should complete <rdar://problem/6157200>.

llvm-svn: 161525
2012-08-08 21:17:31 +00:00
Chad Rosier 360e1763d5 [ms-inline asm] Add basic codegen support for simple asm stmts. Currently,
only machine specific clobbers are modeled.

llvm-svn: 161524
2012-08-08 21:15:52 +00:00
Eli Friedman 0415f3e138 Don't add attributes for "#pragma pack" and friends to tag declarations which
are not definitions. This follows the behavior of both gcc and earlier
versions of clang. Regression from r156531.  <rdar://problem/12048621>.

llvm-svn: 161523
2012-08-08 21:08:34 +00:00
Chad Rosier 83916498b8 [ms-inline asm] Add a very simple test case. Basically, we're only testing for
crashers at the moment (and coincidentally this case was causing a crash).

llvm-svn: 161520
2012-08-08 20:37:31 +00:00
Jordan Rose d86b3bdb7a [analyzer] Clean up the printing of FieldRegions for leaks.
Unfortunately, generalized region printing is very difficult:
- ElementRegions are used both for casting and as actual elements.
- Accessing values through a pointer means going through an intermediate
  SymbolRegionValue; symbolic regions are untyped.
- Referring to implicitly-defined variables like 'this' and 'self' could be
  very confusing if they come from another stack frame.

We fall back to simply not printing the region name if we can't be sure it
will print well. This will allow us to improve in the future.

llvm-svn: 161512
2012-08-08 18:23:36 +00:00
Jordan Rose 356279ca2d [analyzer] Track malloc'd regions stored in structs.
The main blocker on this (besides the previous commit) was that
ScanReachableSymbols was not looking through LazyCompoundVals.
Once that was fixed, it's easy enough to clear out malloc data on return,
just like we do when we bind to a global region.

<rdar://problem/10872635>

llvm-svn: 161511
2012-08-08 18:23:31 +00:00
Jordan Rose 3a80cec5e9 [analyzer] Revamp RegionStore to distinguish regions with symbolic offsets.
RegionStore currently uses a (Region, Offset) pair to describe the locations
of memory bindings. However, this representation breaks down when we have
regions like 'array[index]', where 'index' is unknown. We used to store this
as (SubRegion, 0); now we mark them specially as (SubRegion, SYMBOLIC).

Furthermore, ProgramState::scanReachableSymbols depended on the existence of
a sub-region map, but RegionStore's implementation doesn't provide for such
a thing. Moving the store-traversing logic of scanReachableSymbols into the
StoreManager allows us to eliminate the notion of SubRegionMap altogether.

This fixes some particularly awkward broken test cases, now in
array-struct-region.c.

llvm-svn: 161510
2012-08-08 18:23:27 +00:00
David Blaikie 1c7c8f7637 Implement warning for integral null pointer constants other than the literal 0.
This is effectively a warning for code that violates core issue 903 & thus will
become standard error in the future, hopefully. It catches strange null
pointers such as: '\0', 1 - 1, const int null = 0; etc...

There's currently a flaw in this warning (& the warning for 'false' as a null
pointer literal as well) where it doesn't trigger on comparisons (ptr == '\0'
for example). Fix to come in a future patch.

Also, due to this only being a warning, not an error, it triggers quite
frequently on gtest code which tests expressions for null-pointer-ness in a
SFINAE context (so it wouldn't be a problem if this was an error as in an
actual implementation of core issue 903). To workaround this for now, the
diagnostic does not fire in unevaluated contexts.

Review by Sean Silva and Richard Smith.

llvm-svn: 161501
2012-08-08 17:33:31 +00:00
Fariborz Jahanian a5063a6208 objc: Include all types when issuing warning under
-Wdirect-ivar-access.

llvm-svn: 161500
2012-08-08 16:41:04 +00:00
Dylan Noblesmith 4c004f3e13 Preprocessor: fix __OPTIMIZE_SIZE__ and -Oz
Add some tests for __OPTIMIZE_SIZE__ and  __NO_INLINE__,
removing the superfluous copies in the target-specific
tests, since it's target-independent.

This uncovered a bug in the handling of -Oz: it would
attempt to store the value 2 in the 1-bit bitfield OptimizeSize,
leaving a value of 0 and never defining __OPTIMIZE_SIZE__.

llvm-svn: 161495
2012-08-08 16:09:15 +00:00
Richard Smith f2b084fc5a Implement final piece of DR963 and also DR587:
A conditional operator between glvalues of types cv1 T and cv2 T produces a
glvalue if the expressions are of the same value kind and one of cv1 and cv2
is a subset of the other.

A conditional operator between two null pointer constants is permitted if one
of them is of type std::nullptr_t.

llvm-svn: 161476
2012-08-08 06:13:49 +00:00
Eli Friedman ecffd83c85 Get rid of an early return in Sema::ActOnFields which doesn't make sense anymore.
Fixes a crash (<rdar://problem/11067144>), and generally seems to improve
recovery in other cases.

llvm-svn: 161474
2012-08-08 04:39:56 +00:00
Eli Friedman f6d2184c83 Fix an assertion failure with a C++ constructor initializing a
member of reference type in an anonymous struct.  PR13154.

llvm-svn: 161473
2012-08-08 03:51:37 +00:00
Fariborz Jahanian 285a7cc721 objc-arc: Make -Wdirect-ivar-access accessible to all
memory models, except when arc is accessing a weak
ivar (which is an error). // rdar://6505197

llvm-svn: 161458
2012-08-07 23:48:10 +00:00
Richard Smith 45edb704d3 When building a conditional operator where one operand is a throw-expression
and the other is a glvalue of class type, don't forget to copy-initialize a
temporary when performing the lvalue-to-rvalue conversion on the glvalue.
Strangely, DefaultLvalueConversions misses this part of the lvalue-to-rvalue
conversions.

llvm-svn: 161450
2012-08-07 22:06:48 +00:00
Richard Smith 0a8cfc79b7 -Wunused-private-fields: Don't try to check unresolved initializer expressions
for side-effects. Instead, check for side-effects after performing
initialization. Doing so also removes some strange corner cases and differences
between in-class initialization and constructor initialization.

llvm-svn: 161449
2012-08-07 21:30:42 +00:00
Fariborz Jahanian af264ce12a objc-arc: set nonlazybind attribute on objc_retain/
objc_release for performance for these most often
called APIs. // rdar://12040837

llvm-svn: 161448
2012-08-07 21:30:31 +00:00
Bob Wilson 29536fcbd5 Don't complain about -fobjc-link-runtime being unused with -fobjc-arc.
If you build with -fobjc-arc, then -fobjc-link-runtime is implied but we
don't need to warn about it being unused in that case.  rdar://12039965

llvm-svn: 161444
2012-08-07 19:58:00 +00:00
Dmitri Gribenko 168d23414a Comment AST: DeclInfo: add a special kind for enums.
Comment XML: add a root node kind for enums.

llvm-svn: 161442
2012-08-07 18:59:04 +00:00
Anna Zaks f0267f5c9e Turn on strncat-size warning implemented a while ago.
Warns on anti-patterns/typos in the 'size' argument to strncat. The
correct size argument should look like the following:
 - strncat(dst, src, sizeof(dst) - strlen(dest) - 1);

We warn on: 
 - sizeof(dst)
 - sizeof(src)
 - sizeof(dst) - strlen(dst)
 - sizeof(src) - anything

(This has been implemented in void Sema::CheckStrncatArguments().)

llvm-svn: 161440
2012-08-07 18:36:58 +00:00
Dmitri Gribenko 94ef6357ca Comment AST: treat enumerators as "variables" in DeclInfo.
llvm-svn: 161435
2012-08-07 18:12:22 +00:00
Dmitri Gribenko 740c0fbe0e libclang API for comment-to-xml conversion.
The implementation also includes a Relax NG schema and tests for the schema
itself.  The schema is used in c-index-test to verify that XML documents we
produce are valid.  In order to do the validation, we add an optional libxml2
dependency for c-index-test.

Credits for CMake part go to Doug Gregor.  Credits for Autoconf part go to Eric
Christopher.  Thanks!

llvm-svn: 161431
2012-08-07 17:54:38 +00:00
Fariborz Jahanian a7c9f883e6 objective-c: Exclude -Wdirect-ivar-access for arc.
Allow direct ivar access in init and dealloc methods
in mrr. // rdar://650197

llvm-svn: 161426
2012-08-07 16:38:44 +00:00
Hans Wennborg abc1e22d65 Properly check length modfiers for %n in format strings.
llvm-svn: 161408
2012-08-07 09:13:19 +00:00
Hans Wennborg b1ab2a84f0 Remove ScanfArgType and bake that logic into ArgType.
This is useful for example for %n in printf, which expects
a pointer to int with the same logic for checking as %d
would have in scanf.

llvm-svn: 161407
2012-08-07 08:59:46 +00:00
Douglas Gregor 847cea72e6 Objective-C pointer types don't have C-linkage, even though they are
non-POD. Fixes <rdar://problem/12031870>.

llvm-svn: 161395
2012-08-07 06:14:34 +00:00
Richard Smith a33e4fe603 Update documentation of HasSideEffects to match its callers' expectations, and
update implementation to match. An elidable, non-trivial constructor call is a
side-effect under this definition, but wasn't under the old one, because we are
not required to evaluate it even though it may have an effect.

Also rationalize checking for volatile reads: just look for lvalue-to-rvalue
conversions on volatile glvalues, and ignore whether a DeclRefExpr etc is for
a volatile variable.

llvm-svn: 161393
2012-08-07 05:18:29 +00:00
Anna Zaks b8146afcd1 [analyzer] + New line at end of file
llvm-svn: 161392
2012-08-07 05:12:29 +00:00
Anna Zaks 75930b65b4 [analyzer] Address Jordan's review of DynamicTypePropagation.
llvm-svn: 161391
2012-08-07 05:12:24 +00:00
Eric Christopher 96b5f07808 Fix the test RUN line for this better.
llvm-svn: 161390
2012-08-07 05:04:19 +00:00
Richard Smith 0421ce7b22 Teach Expr::HasSideEffects about all the Expr types, and fix a bug where it
was mistakenly classifying dynamic_casts which might throw as having no side
effects.

Switch it from a visitor to a switch, so it is kept up-to-date as future Expr
nodes are added. Move it from ExprConstant.cpp to Expr.cpp, since it's not
really related to constant expression evaluation.

Since we use HasSideEffect to determine whether to emit an unused global with
internal linkage, this has the effect of suppressing emission of globals in
some cases.

I've left many of the Objective-C cases conservatively assuming that the
expression has side-effects. I'll leave it to someone with better knowledge
of Objective-C than mine to improve them.

llvm-svn: 161388
2012-08-07 04:16:51 +00:00
Jordan Rose c11a33a2bd [analyzer] Add a test case for OS X 10.8's NSMakeCollectable under non-GC.
This is an additional test for r161349 (ignoring 10.8's annotations for
NSMakeCollectable).

llvm-svn: 161380
2012-08-07 01:11:14 +00:00
Eric Christopher 06d29572e1 If we don't have a complete type for the array type yet either then
just let the alignment be zero.

PR13531

llvm-svn: 161379
2012-08-07 00:48:43 +00:00
Eric Christopher 754cedf23f Specify a triple on this to make it easier to test.
llvm-svn: 161372
2012-08-07 00:28:23 +00:00
Eric Christopher 33becaa77a Make sure when we get the replacement type for a template argument
that we attach the lost qualifiers.

Fixes rdar://11882155

llvm-svn: 161368
2012-08-07 00:14:25 +00:00
Anna Zaks 0a5e1b840a [analyzer] DynTypes: Add a test for improper cast performed by user.
Dynamic type inference does the right thing in this case. However, as
Jordan suggested, it would be nice to add a warning here as well.

llvm-svn: 161365
2012-08-06 23:58:16 +00:00
Fariborz Jahanian 14f1aa70a9 objective-c: Implement gcc's -Wdirect-ivar-access option.
// rdar://6505197

llvm-svn: 161362
2012-08-06 23:50:51 +00:00
Anna Zaks 05253782a4 [analyzer] Dynamic type info - propagate through implicit casts.
I currently have a bit of redundancy with the cast kind switch statement
inside the ImplicitCast callback, but I might be adding more casts going
forward.

llvm-svn: 161358
2012-08-06 23:25:45 +00:00
Anna Zaks 472dbcf156 [analyzer] Add a checker to manage dynamic type propagation.
Instead of sprinkling dynamic type info propagation throughout
ExprEngine, the added checker would add the more precise type
information on known APIs (Ex: ObjC alloc, new) and propagate
the type info in other cases (ex: ObjC init method, casts (the second is
not implemented yet)).

Add handling of ObjC alloc, new and init to the checker.

llvm-svn: 161357
2012-08-06 23:25:39 +00:00
Jordan Rose a3e3343e51 [analyzer] Add plist output checks for all four "path notes" tests.
No functionality change, but from now on, any new path notes should be
tested both with plain-text output (for ease of human auditing) and with
plist output (to ensure control flow and events are being correctly
represented in Xcode).

llvm-svn: 161351
2012-08-06 21:28:14 +00:00
Jordan Rose e32e153f7d [analyzer] Improve arrow locations for PseudoObjectExprs.
llvm-svn: 161350
2012-08-06 21:28:11 +00:00
Richard Trieu 43803f0951 For global record types, the self reference checker was called twice, resulting
in duplicate -Wuninitialized warnings.  Change so that only the check in
TryConstructorInitialization() will be used and a single warning be emitted.

llvm-svn: 161345
2012-08-06 21:09:23 +00:00
Simon Atanasyan a1f8c0ab93 Fix MIPS DSP Rev1 intrinsics memory properties.
The patch reviewed by Akira Hatanaka.

llvm-svn: 161333
2012-08-06 19:48:16 +00:00
Dmitri Gribenko 5ec0c7536a Comment diagnostics: warn on duplicate \brief and \return commands.
Doxygen manual claims that multiple \brief or \returns commands will be merged
together, but actual behavior is different (second \brief command becomes a
part of a discussion, second \returns becomes a "Returns: blah" paragraph on
its own).  Anyway, it seems to be a bad idea to use multiple \brief or \returns
commands in a single command.

llvm-svn: 161325
2012-08-06 17:08:27 +00:00
Dmitri Gribenko 558babc53b Comment diagnostics: \return in void function: specialize diagnostic text for
ObjC methods.

llvm-svn: 161324
2012-08-06 16:29:26 +00:00
Craig Topper ef3f5fe6bd Re-enable pcmpistri/pcmpestri builtins in clang now that llvm supports them properly.
llvm-svn: 161319
2012-08-06 07:07:06 +00:00
Richard Smith 403f76ee02 PR13529: Don't crash if the driver sees an unused input file when running as
'clang-cpp'.

For now, the test uses "REQUIRES: shell" to determine if the host system
supports "ln -s", which it uses to create a 'clang-cpp' symlink. This is a bit
hacky and should likely be directly supported by lit.cfg.

llvm-svn: 161317
2012-08-06 04:09:06 +00:00
Richard Smith 18f07db183 PR13499: Don't try to check whether 'override' has been validly applied until
we know whether the function is virtual. But check it as soon as we do know;
in some cases we don't need to wait for an instantiation.

llvm-svn: 161316
2012-08-06 03:25:17 +00:00
Richard Smith f716bb859b PR13527: don't assert if a function is explicitly defaulted when it's already
been defined.

llvm-svn: 161315
2012-08-06 02:25:10 +00:00
Hal Finkel 3fadbb54fd Add __builtin_readcyclecounter() to produce the @llvm.readcyclecounter() intrinsic.
llvm-svn: 161310
2012-08-05 22:03:08 +00:00
Anna Zaks 6ce686e6a4 [analyzer] Malloc: remove assert since is not valid as of r161248
We can be in the situation where we did not track the symbol before
realloc was called on it.

llvm-svn: 161294
2012-08-04 02:04:27 +00:00
Fariborz Jahanian 29489a9e9e objective-C string literal has no side-effect,
resulting in issuance of unused static variable
warning now. // rdar://10777111

llvm-svn: 161291
2012-08-04 01:24:33 +00:00
Jordan Rose a01741fce4 [analyzer] Use a more robust check for null in CallAndMessageChecker.
This should fix the failing test on the buildbot as well.

llvm-svn: 161290
2012-08-04 01:04:52 +00:00
Jordan Rose 4aa80e156d [analyzer] Don't assume values bound to references are automatically non-null.
While there is no such thing as a "null reference" in the C++ standard,
many implementations of references (including Clang's) do not actually
check that the location bound to them is non-null. Thus unlike a regular
null dereference, this will not cause a problem at runtime until the
reference is actually used. In order to catch these cases, we need to not
prune out paths on which the input pointer is null.

llvm-svn: 161288
2012-08-04 00:25:30 +00:00
Jordan Rose 17a8757a46 [analyzer] Update initializer assertion for delegating constructors.
Like base constructors, delegating constructors require no further
processing in the CFGInitializer node.

Also, add PrettyStackTraceLoc to the initializer and destructor logic
so we can get better stack traces in the future.

llvm-svn: 161283
2012-08-03 23:31:15 +00:00
Jordan Rose cfb4eb293f [analyzer] When a symbol is null, we should track its constraints.
Because of this, we would previously emit NO path notes when a parameter
is constrained to null (because there are no stores). Now we show where we
made the assumption, which is much more useful.

llvm-svn: 161280
2012-08-03 23:09:01 +00:00
Jordan Rose 3eb3cd45b8 [analyzer] Flatten path diagnostics for text output like we do for HTML.
llvm-svn: 161279
2012-08-03 23:08:54 +00:00
Jordan Rose 92e1449b55 [analyzer] Track null/uninitialized C++ objects used in method calls.
llvm-svn: 161278
2012-08-03 23:08:49 +00:00
Jordan Rose 16fe35eb2b Enhance getImplicitObjectArgument to look through ->*.
This only applies in the case where ->* is not overloaded, since it
specifically looks for BinaryOperator and not CXXOperatorCallExpr.

llvm-svn: 161275
2012-08-03 23:08:39 +00:00
Jordan Rose 86bedb0de0 [analyzer] Add a test for copy-constructor inlining.
llvm-svn: 161274
2012-08-03 23:08:36 +00:00
Anna Zaks 150843b87e [analyzer] ObjC Inlining: Start tracking dynamic type info in the GDM
In the following code, find the type of the symbolic receiver by
following it and updating the dynamic type info in the state when we
cast the symbol from id to MyClass *.

  MyClass *a = [[self alloc] init];
  return 5/[a testSelf];

llvm-svn: 161264
2012-08-03 21:43:37 +00:00
Dmitri Gribenko 6430583017 Comment diagnostics: warn if \returns is used in a non-function comment or if
the function returns void.

llvm-svn: 161261
2012-08-03 21:15:32 +00:00
Richard Smith ed9430274e Fix crash if a literal operator template's template parameter pack is not a non-type template parameter pack. Patch by Andy Gibbs!
llvm-svn: 161260
2012-08-03 21:14:57 +00:00
Anna Zaks 52242a6677 [analyzer] Malloc: track non-allocated but freed memory
There is no reason why we should not track the memory which was not
allocated in the current function, but was freed there. This would
allow to catch more use-after-free and double free with no/limited IPA.

Also fix a realloc issue which surfaced as the result of this patch.

llvm-svn: 161248
2012-08-03 18:30:18 +00:00
Benjamin Kramer 4a9020839c Flesh out test for defaulted key functions a bit more.
llvm-svn: 161243
2012-08-03 15:43:22 +00:00
Benjamin Kramer 7555b54020 Reduce temp file pollution in some test cases.
llvm-svn: 161237
2012-08-03 10:35:06 +00:00
Benjamin Kramer 73d1be7c56 Fix failed to generate vtables in certain cases.
By C++ standard, the vtable should be generated if the first non-inline
virtual function is defined in the TU.  Current version of clang doesn't
generate vtable if the first virtual function is defaulted, because the
key function is regarded as the defaulted function.

Patch by Li Kan!

llvm-svn: 161236
2012-08-03 08:39:58 +00:00
Anna Zaks 4c03dfd4b1 [analyzer] Solve another source of non-determinism in the diagnostic
engine.

The code that was supposed to split the tie in a deterministic way is
not deterministic. Most likely one of the profile methods uses a
pointer. After this change we do finally get the consistent diagnostic
output. Testing this requires running the analyzer on large code bases
and diffing the results.

llvm-svn: 161224
2012-08-02 23:41:05 +00:00
Dmitri Gribenko baeb60e919 Comments: handle template paramter documentation in alias-declaration
templates.

llvm-svn: 161215
2012-08-02 21:36:57 +00:00
Jordan Rose 9a2eec3826 [analyzer] Add a simple check for initializing reference variables with null.
There's still more work to be done here; this doesn't catch reference
parameters or return values. But it's a step in the right direction.

Part of <rdar://problem/11212286>.

llvm-svn: 161214
2012-08-02 21:33:42 +00:00
Dmitri Gribenko 7f4b3773be Attaching comments to declarations: handle using-declaration.
llvm-svn: 161211
2012-08-02 20:49:51 +00:00
Fariborz Jahanian 9191865b2d objc-arc: Modify test for more prcecise fixit.
// rdar://11913153

llvm-svn: 161194
2012-08-02 18:38:41 +00:00
Fariborz Jahanian 9080491dbd objective-c arc: Patch to suggest bridge casting of CF
objects used as dictionary subscript objects.
// rdar://11913153

llvm-svn: 161187
2012-08-02 18:03:58 +00:00
Nuno Lopes c65c24b178 add a comment to explain this test case
llvm-svn: 161172
2012-08-02 12:12:26 +00:00
Hans Wennborg db7a78c211 test/Sema/tls.c: don't use -verify to check if TLS is supported
Use "%clang_cc1" vs "not %clang_cc1" instead.
Also use -fsyntax-only.

llvm-svn: 161165
2012-08-02 09:04:56 +00:00
Eli Friedman abab776039 Make sure we don't emit IR for unused EH cleanups. PR13359.
llvm-svn: 161148
2012-08-02 00:10:24 +00:00
Dmitri Gribenko 58e4131995 Comment to HTML conversion: correct typo in CSS class name: taram -> tparam
llvm-svn: 161145
2012-08-01 23:47:30 +00:00
Dmitri Gribenko b0ddb66a8d Comment diagnostics fixit tests: move exected-warning constructs from the
comment being tested.

llvm-svn: 161144
2012-08-01 23:29:52 +00:00
Dmitri Gribenko fae2e4ed0a Comment diagnostics: add tests for \tparam fixits.
llvm-svn: 161142
2012-08-01 23:27:13 +00:00
Eli Friedman 22be06a250 Fix an assertion failure instantiating a constexpr function from within a -dealloc method. PR13401.
llvm-svn: 161135
2012-08-01 21:02:59 +00:00
Hans Wennborg 1241731803 TLS is not supported on OpenBSD
This fixes PR13502 and adds a test to keep track of which
targets support TLS and which do not.

llvm-svn: 161124
2012-08-01 18:53:19 +00:00
Nuno Lopes 35b8c509c8 add test for PR13497
llvm-svn: 161119
2012-08-01 17:02:30 +00:00
Manuel Klimek 8c9a6bcae6 Fix typo.
llvm-svn: 161106
2012-08-01 08:48:27 +00:00
John McCall 13a39c6f54 When devirtualizing the conversion to a virtual base subobject,
don't explode if the offset we get is zero.  This can happen if
you have an empty virtual base class.

While I'm at it, remove an unnecessary block from the IR-generation
of the null-check, mark the eventual GEP as inbounds, and generally
prettify.

llvm-svn: 161100
2012-08-01 05:04:58 +00:00
Dmitri Gribenko 307cf89b19 Comment to HTML conversion: skip \tparam commands with whitespace paragraphs
llvm-svn: 161096
2012-08-01 00:48:00 +00:00
Dmitri Gribenko 7c0456f91b Comment to HTML conversion: escape HTML special characters in command arguments
llvm-svn: 161094
2012-08-01 00:21:12 +00:00
Aaron Ballman 899b9c6666 Explicitly defaulted constructors cannot be used for default initialization.
llvm-svn: 161088
2012-07-31 22:40:31 +00:00
Dmitri Gribenko 34df220410 Comment parsing: add support for \tparam command on all levels.
The only caveat is renumbering CXCommentKind enum for aesthetic reasons -- this
breaks libclang binary compatibility, but should not be a problem since API is
so new.

This also fixes PR13372 as a side-effect.

llvm-svn: 161087
2012-07-31 22:37:06 +00:00
Douglas Gregor f4cc61d525 When testing whether we can perform copy or move initialization, be
sure to supply an initialization location. Fixes <rdar://problem/11951661>.

llvm-svn: 161084
2012-07-31 22:15:04 +00:00
Rafael Espindola fb4263f156 Consider the visibility of template template arguments. GCC doesn't, but it also
fails to consider the linkage, which we were already considering.

llvm-svn: 161070
2012-07-31 19:02:02 +00:00
Jordan Rose a765bac7a1 [analyzer] Turn -cfg-add-initializers on by default, and remove the flag.
llvm-svn: 161060
2012-07-31 18:04:59 +00:00
Jordan Rose 6a97d92ef5 [analyzer] Don't try to inline if there's no region for a message receiver.
While usually we'd use a symbolic region rather than a straight-up Unknown,
we can still generate unknowns via array subscripts with symbolic indexes.
(And if this ever changes in the future, we still shouldn't crash.)

llvm-svn: 161059
2012-07-31 18:04:53 +00:00
Hans Wennborg 16250c7c18 -Wformat: better handling of qualifiers on pointer arguments
Warn about using pointers to const-qualified types as arguments to
scanf. Ignore the volatile qualifier when checking if types match.

llvm-svn: 161052
2012-07-31 16:37:47 +00:00
Jordan Rose e8a21b73ac [analyzer] Getting an lvalue for a reference field still requires a load.
This was causing a crash in our array-to-pointer logic, since the region
was clearly not an array.

PR13440 / <rdar://problem/11977113>

llvm-svn: 161051
2012-07-31 16:34:07 +00:00
Douglas Gregor 2d8db8fe7a Tweak code-completion heuristics deciding between a lambda
code-completion and an Objective-C message send, based on Jordan's
feedback.

llvm-svn: 161049
2012-07-31 15:27:48 +00:00
Manuel Klimek d627ec8a05 This test actually works on Win32...
llvm-svn: 161048
2012-07-31 14:45:10 +00:00
Manuel Klimek 3aad855a89 Fixes a segfault in Tooling when using pch's:
Clear the FileManager's stat cache in between running
translation units, as the stat cache loaded from a pch
is only valid for one compiler invocation.

llvm-svn: 161047
2012-07-31 13:56:54 +00:00
Jiangning Liu 5007bb6c0b Add two more .keep files to avoid the missing of empty folders in git repository.
llvm-svn: 161043
2012-07-31 10:52:55 +00:00
Jiangning Liu 43f37dca77 Add two .keep files to avoid the missing of empty folders in git repository.
llvm-svn: 161042
2012-07-31 10:24:27 +00:00
Jiangning Liu 61b06cbcb4 Support ARM hard float (arm-linux-gnueabihf).
llvm-svn: 161038
2012-07-31 08:06:29 +00:00
Sylvestre Ledru a5202660fb Fix some minor typos
llvm-svn: 161036
2012-07-31 06:56:50 +00:00
Rafael Espindola 06b2b4a7c9 Handle functions with struct arguments or return types and the regparm
attribute. It is a variation of the x86_64 ABI:

* A struct returned indirectly uses the first register argument to pass the
  pointer.
* Floats, Doubles and structs containing only one of them are not passed in
  registers.
* Other structs are split into registers if they fit on the remaining ones.
  Otherwise they are passed in memory.
* When a struct doesn't fit it still consumes the registers.

llvm-svn: 161022
2012-07-31 02:44:24 +00:00
Jordan Rose 3865c6e670 [analyzer] Add a test that messages to super invalidate ivars.
llvm-svn: 161021
2012-07-31 02:05:30 +00:00
Rafael Espindola 74ec5c03ca Attributes preceding a function declaration are first applied to the return
type and then propagated to the function. This was failing for destructors,
constructors and constructors templates since they don't have a return type.

Fix that by directly calling processTypeAttrs on the dummy type we use as the
return type in these cases.

llvm-svn: 161020
2012-07-31 01:54:04 +00:00
Aaron Ballman 1f10cc5eb4 No longer emitting a PCH file when using -fsyntax-only on a header file. Fixes PR13343.
llvm-svn: 161019
2012-07-31 01:21:00 +00:00
Douglas Gregor 721b14d1b3 When we encounter a code-completion token while parsing an ill-formed
lambda-introducer in Objective-C++11, fall back to treating the tokens
as an Objective-C message send to provide those (more likely)
completions. Fixes <rdar://problem/11980263>.

llvm-svn: 161015
2012-07-31 00:50:07 +00:00
John McCall ff755cda9c Don't crash *or* insert a bogus autorelease when emitting a
this-adjustment thunk in ARC++.

llvm-svn: 161014
2012-07-31 00:33:55 +00:00