Eli Friedman [Wed, 8 Aug 2012 21:08:34 +0000 (21:08 +0000)]
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>.
Chad Rosier [Wed, 8 Aug 2012 20:37:31 +0000 (20:37 +0000)]
[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).
Jordan Rose [Wed, 8 Aug 2012 18:23:36 +0000 (18:23 +0000)]
[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.
Jordan Rose [Wed, 8 Aug 2012 18:23:31 +0000 (18:23 +0000)]
[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.
Jordan Rose [Wed, 8 Aug 2012 18:23:27 +0000 (18:23 +0000)]
[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.
Chad Rosier [Wed, 8 Aug 2012 18:22:06 +0000 (18:22 +0000)]
[ms-inline asm] Add support for detecting simple ms-style inline asm. Simple
asm statements are those that don't reference variable names, function names,
and labels.
Add logic to generate a patched AsmString that will eventually be consumed by
the AsmParser. No functional change at this point, so unfortunately no test
case.
David Blaikie [Wed, 8 Aug 2012 17:33:31 +0000 (17:33 +0000)]
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.
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__.
Richard Smith [Wed, 8 Aug 2012 06:13:49 +0000 (06:13 +0000)]
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.
Eli Friedman [Wed, 8 Aug 2012 04:39:56 +0000 (04:39 +0000)]
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.
Richard Smith [Tue, 7 Aug 2012 22:06:48 +0000 (22:06 +0000)]
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.
Richard Smith [Tue, 7 Aug 2012 21:30:42 +0000 (21:30 +0000)]
-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.
Anna Zaks [Tue, 7 Aug 2012 18:36:58 +0000 (18:36 +0000)]
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().)
Dmitri Gribenko [Tue, 7 Aug 2012 17:54:38 +0000 (17:54 +0000)]
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!
Richard Smith [Tue, 7 Aug 2012 05:18:29 +0000 (05:18 +0000)]
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.
Ted Kremenek [Tue, 7 Aug 2012 05:01:49 +0000 (05:01 +0000)]
Enhance ClangDiagnosticsEmitter to reject diagnostics that are errors that are also
included in warning groups. Warning groups can only contain warnings, because only
warnings can be mapped to errors or ignored.
This caught a few diagnostics that were incorrectly in diagnostic groups, and
could have resulted in a compiler crash when those diagnostic groups were mapped.
Richard Smith [Tue, 7 Aug 2012 04:16:51 +0000 (04:16 +0000)]
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.
Ted Kremenek [Tue, 7 Aug 2012 00:34:48 +0000 (00:34 +0000)]
Remove two fall through diagnostics from the IgnoredAttributes group, since they are errors, not warnings.
Only warnings should be in warning groups. This was causing an assertion failure in
code using pragmas to map -Wignored-attributes to ignored, but this kind of
diagnostic mapping is disallowed for builtin errors. We should just wire
up tablegen to reject errors being in diagnostic groups.
Chad Rosier [Tue, 7 Aug 2012 00:29:06 +0000 (00:29 +0000)]
[ms-inline asm] Stmt destructors are never called, so allocate the AsmToks using
the ASTContext BumpPtr. Also use the preferred llvm::ArrayRef interface.
Anna Zaks [Mon, 6 Aug 2012 23:25:45 +0000 (23:25 +0000)]
[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.
Anna Zaks [Mon, 6 Aug 2012 23:25:39 +0000 (23:25 +0000)]
[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.
Jordan Rose [Mon, 6 Aug 2012 21:28:14 +0000 (21:28 +0000)]
[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).
Jordan Rose [Mon, 6 Aug 2012 21:28:02 +0000 (21:28 +0000)]
[analyzer] Ignore OS X 10.8's annotations for NSMakeCollectable.
The frameworks correctly use the 'cf_consumed' and 'ns_returns_retained'
attributes for NSMakeCollectable, but we can model the behavior under
garbage collection more precisely than that.
Richard Trieu [Mon, 6 Aug 2012 21:09:23 +0000 (21:09 +0000)]
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.
Chad Rosier [Mon, 6 Aug 2012 20:03:45 +0000 (20:03 +0000)]
[ms-inline asm] Pass Tokens to Sema and store them in the AST. No functional
change intended. No test case as there's no real way to test at this time.
Dmitri Gribenko [Mon, 6 Aug 2012 17:08:27 +0000 (17:08 +0000)]
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.
Richard Smith [Mon, 6 Aug 2012 04:09:06 +0000 (04:09 +0000)]
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.
Richard Smith [Mon, 6 Aug 2012 03:25:17 +0000 (03:25 +0000)]
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.
Jordan Rose [Sat, 4 Aug 2012 00:25:30 +0000 (00:25 +0000)]
[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.
Jordan Rose [Fri, 3 Aug 2012 23:09:01 +0000 (23:09 +0000)]
[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.