Thread safety analysis: add two new attributes to the thread safety analysis:
assert_exclusive_lock and assert_shared_lock. These attributes are used to
mark functions that dynamically check (i.e. assert) that a lock is held.
Objective-C++ (and c++) Sema: Patch fixes a sema crash when gnu’s ?: extension
is used for Objective-C++’s dictionary subscripting. This is done by filtering
out all placeholder types before check on lowering of the
common expression is done. // rdar://1374918.
Reviewed by John McCall.
Ted Kremenek [Fri, 17 May 2013 09:41:40 +0000 (09:41 +0000)]
[analyzer; alternate edges] improve support for edges with PseudoObjectExprs.
This optimizes some spurious edges resulting from PseudoObjectExprs.
This required far more changes than I anticipated. The current
ParentMap does not record any hierarchy information between
a PseudoObjectExpr and its *semantic* expressions that may be
wrapped in OpaqueValueExprs, which are the expressions actually
laid out in the CFG. This means the arrow pruning logic could
not map from an expression to its containing PseudoObjectExprs.
To solve this, this patch adds a variant of ParentMap that
returns the "semantic" parentage of expressions (essentially
as they are viewed by the CFG). This alternate ParentMap is then
used by the arrow reducing logic to identify edges into pseudo
object expressions, and then eliminate them.
Daniel Jasper [Fri, 17 May 2013 09:35:01 +0000 (09:35 +0000)]
Slightly modify the formatting rules for braced lists.
Basically, the new rule is: The opening "{" always has to be on the
same line as the first element if the braced list is nested
(e.g. in another braced list or in a function).
The solution that clang-format produces almost always adheres to this
rule anyway and this makes clang-format significantly faster for larger
lists. Added a test cases for the only exception I could find
(which doesn't seem to be very important at first sight).
Ted Kremenek [Fri, 17 May 2013 06:48:22 +0000 (06:48 +0000)]
[analyzer; alternate edges] don't add an edge incoming from the start of a function
for a nested call. This matches what we do with the first stack frame.
Richard Smith [Fri, 17 May 2013 02:19:35 +0000 (02:19 +0000)]
PR15757: When we instantiate an inheriting constructor template, also
instantiate the inherited constructor template and mark that as the constructor
which the instantiated specialization is inheriting. This fixes a
crash-on-valid when trying to compute the exception specification of a
specialization of the inheriting constructor.
Jordan Rose [Fri, 17 May 2013 02:16:49 +0000 (02:16 +0000)]
[analyzer] Don't inline ~shared_ptr.
The analyzer can't see the reference count for shared_ptr, so it doesn't
know whether a given destruction is going to delete the referenced object.
This leads to spurious leak and use-after-free warnings.
For now, just ban destructors named '~shared_ptr', which catches
std::shared_ptr, std::tr1::shared_ptr, and boost::shared_ptr.
Anna Zaks [Thu, 16 May 2013 22:30:45 +0000 (22:30 +0000)]
[analyzer] Add an option to use the last location in the main source file as the report location.
Previously, we’ve used the last location of the analyzer issue path as the location of the
report. This might not provide the best user experience, when one analyzer a source
file and the issue appears in the header. Introduce an option to use the last location
of the path that is in the main source file as the report location.
New option can be enabled with -analyzer-config report-in-main-source-file=true.
Richard Smith [Thu, 16 May 2013 22:18:32 +0000 (22:18 +0000)]
Since we're counting number of steps, switch to turing machines which maximize
#steps not #1s, and use a more traditional step count where the 'halt' step is
not counted.
Objective-C arc: Diagnose when user attempts to
synthesize a property getter method that overrides
a method definition named 'retain' and the like.
Fixes // rdar://13885083
Daniel Jasper [Thu, 16 May 2013 10:40:07 +0000 (10:40 +0000)]
Add a more convenient interface to use clang-format.
It turns out that several implementations go through the trouble of
setting up a SourceManager and Lexer and abstracting this into a
function makes usage easier.
Also abstracts SourceManager-independent ranges out of
tooling::Refactoring and provides a convenience function to create them
from line ranges.
Clang has an issue between mingw/include/float.h and clang/Headers/float.h with cyclic include_next.
For now, it should work to suppress #include_next in clang/float.h with an explicit target.
(It may work with -U__MINGW32__, though.)
Richard Smith [Thu, 16 May 2013 06:20:58 +0000 (06:20 +0000)]
First pass of semantic analysis for init-captures: check the initializer, build
a FieldDecl from it, and propagate both into the closure type and the
LambdaExpr.
You can't do much useful with them yet -- you can't use them within the body
of the lambda, because we don't have a representation for "the this of the
lambda, not the this of the enclosing context". We also don't have support or a
representation for a nested capture of an init-capture yet, which was intended
to work despite not being allowed by the current standard wording.
Rafael Espindola [Thu, 16 May 2013 04:30:21 +0000 (04:30 +0000)]
Fix pr15930.
In the case of inline functions, we have to special case local types
when they are used as template arguments to make sure the template
instantiations are still uniqued in case the function itself is inlined.
Richard Trieu [Thu, 16 May 2013 01:46:09 +0000 (01:46 +0000)]
Return QualType() when a too large array is attempting to be created. This
prevents further errors and some overflows in size calculations.
One overflow was previously triggering an assert.
Richard Smith [Thu, 16 May 2013 01:23:30 +0000 (01:23 +0000)]
Start a page tracking which C++ defect reports have been implemented in Clang.
The page is generated from a text file listing DR numbers and implementation
status, plus a copy of the cwg_index.html from the WG21 website. Recipe:
The intent here is to go through all the DRs, add tests for each one, then mark
them as done once such tests are committed and passing. I've not linked to this
page from anywhere, since it doesn't contain any useful information yet.
Adrian Prantl [Thu, 16 May 2013 00:41:29 +0000 (00:41 +0000)]
Set the debug location for landing pad code to the canonical EH location.
It used to point to the first call that caused the landing pad to
be generated.
This seems to be emitting too much extra debug info for two (known)
reasons:
* full class definitions are emitted when only declarations are expected
* unused using declarations still produce DW_TAG_imported_declarations
Jordan Rose [Wed, 15 May 2013 23:22:55 +0000 (23:22 +0000)]
Remove unused, awkward CFGStmtVisitor and subclasses.
This class is a StmtVisitor that distinguishes between block-level and
non-block-level statements in a CFG. However, it does so using a hard-coded
idea of which statements might be block-level, which probably isn't accurate
anymore. The only implementer of the CFGStmtVisitor hierarchy was the
analyzer's DeadStoresChecker, and the analyzer creates a linearized CFG
anyway (every non-trivial statement is a block-level statement).
This also allows us to remove the block-expr map ("BlkExprMap"), which
mapped statements to positions in the CFG. Apart from having a helper type
that really should have just been Optional<unsigned>, it was only being
used to ask /if/ a particular expression was block-level, for traversal
purposes in CFGStmtVisitor.
Jordan Rose [Wed, 15 May 2013 18:08:15 +0000 (18:08 +0000)]
[analyzer] Put back DefaultBool's implicit conversion to bool.
DefaultBool is basically just "bool with a default constructor", so it
really should implicitly convert to bool. In fact, it should convert to
bool&, so that it could be passed to functions that take bools by reference.
This time, mark the operator bool& as implicit to promise that it's
deliberate.
Rationale:
a) Having anything other than forward declaration on the same line
as a namespace looks confusing.
b) Formatting namespace-forward-declaration-combinations different
from other stuff is inconsistent.
c) Wasting vertical space close to such forward declarations really
does not affect readability.
Hans Wennborg [Wed, 15 May 2013 11:03:04 +0000 (11:03 +0000)]
Better diagnostics for string initialization.
This commit improves Clang's diagnostics for string initialization.
Where it would previously say:
/tmp/a.c:3:9: error: array initializer must be an initializer list
wchar_t s[] = "Hi";
^
/tmp/a.c:4:6: error: array initializer must be an initializer list or string literal
char t[] = L"Hi";
^
Daniel Jasper [Wed, 15 May 2013 07:51:51 +0000 (07:51 +0000)]
Improve formatting of function types.
The function type detection in r181438 and r181764 detected function
types too eagerly. This led to inconsistent formatting of inline
assembly and (together with r181687) to an incorrect formatting of calls
in macros.
Before: #define DEREF_AND_CALL_F(parameter) f (*parameter)
After: #define DEREF_AND_CALL_F(parameter) f(*parameter)
David Blaikie [Wed, 15 May 2013 07:37:26 +0000 (07:37 +0000)]
Use only explicit bool conversion operator
The most common (non-buggy) case are where such objects are used as
return expressions in bool-returning functions or as boolean function
arguments. In those cases I've used (& added if necessary) a named
function to provide the equivalent (or sometimes negative, depending on
convenient wording) test.
DiagnosticBuilder kept its implicit conversion operator owing to the
prevalent use of it in return statements.
One bug was found in ExprConstant.cpp involving a comparison of two
PointerUnions (PointerUnion did not previously have an operator==, so
instead both operands were converted to bool & then compared). A test
is included in test/SemaCXX/constant-expression-cxx1y.cpp for the fix
(adding operator== to PointerUnion in LLVM).
Jim Grosbach [Wed, 15 May 2013 02:40:04 +0000 (02:40 +0000)]
ARM: Improve codegen for vget_low_* and vget_high_ intrinsics.
These intrinsics use the __builtin_shuffle() function to extract the
low and high half, respectively, of a 128-bit NEON vector. Currently,
they're defined to use bitcasts to simplify the emitter, so we get code
like:
uint16x4_t vget_low_u32(uint16x8_t __a) {
return (uint32x2_t) __builtin_shufflevector((int64x2_t) __a,
(int64x2_t) __a,
0);
}
While this works, it results in those bitcasts going all the way through
to the IR, resulting in code like:
%1 = bitcast <8 x i16> %in to <2 x i64>
%2 = shufflevector <2 x i64> %1, <2 x i64> undef, <1 x i32>
%zeroinitializer
%3 = bitcast <1 x i64> %2 to <4 x i16>
We can instead easily perform the operation directly on the input vector
like:
Objective-C [diagnostics] [QOI], when method is not
found for a receiver, note where receiver class
is declaraed (this is most common when receiver is a forward
class). // rdar://3258331
Richard Trieu [Tue, 14 May 2013 21:59:17 +0000 (21:59 +0000)]
When computing the size of large arrays, use char units instead of bits.
This prevents an overflow and assertion when the number of bits cannot be
stored in 64-bits.
David Blaikie [Tue, 14 May 2013 21:04:00 +0000 (21:04 +0000)]
Provide operator<< for stream output of DeclarationNames
ASTDumper was already trying to do this & instead got an implicit bool
conversion by surprise (thus printing out 0 or 1 instead of the name of
the declaration). To avoid that issue & simplify call sites, simply make
it the normal/expected operator<<(raw_ostream&, ...) overload & simplify
all the existing call sites. (bonus: this function doesn't need to be a
member or friend, it's just using public API in DeclarationName)
Reid Kleckner [Tue, 14 May 2013 20:30:42 +0000 (20:30 +0000)]
[ms-cxxabi] Mangle in an implicit 'E' for certain types on win64
Most of the complexity of this patch is figuring out which types get the
qualifier and which don't. If we implement __ptr32/64, then we should
check the qualifier instead of assuming all pointers are 64-bit.
Daniel Jasper [Tue, 14 May 2013 10:31:09 +0000 (10:31 +0000)]
Correctly determine ranges for clang-format.
We have been assuming that CharSourceRange::getTokenRange() by itself
expands a range until the end of a token, but in fact it only sets
IsTokenRange to true. Thus, we have so far only considered the first
character of the last token to belong to an unwrapped line. This
did not really manifest in symptoms as all edit integrations
expand ranges to fully lines.
Daniel Jasper [Tue, 14 May 2013 09:30:02 +0000 (09:30 +0000)]
Fix clang-format bug in unwrapped-line merging.
Before (in styles that allow it), clang-format would not merge an
if statement onto a single line, if only the second line was format
(e.g. in an editor integration):
if (a)
return; // clang-format invoked on this line.
Manuel Klimek [Tue, 14 May 2013 09:13:00 +0000 (09:13 +0000)]
First revision of the dynamic ASTMatcher library.
This library supports all the features of the compile-time based ASTMatcher
library, but allows the user to specify and construct the matchers at runtime.
It contains the following modules:
- A variant type, to be used by the matcher factory.
- A registry, where the matchers are indexed by name and have a factory method
with a generic signature.
- A simple matcher expression parser, that can be used to convert a matcher
expression string into actual matchers that can be used with the AST at
runtime.
Many features where omitted from this first revision to simplify this code
review. The main ideas are still represented in this change and it already has
support working use cases.
Things that are missing:
- Support for polymorphic matchers. These requires supporting code in the
registry, the marshallers and the variant type.
- Support for numbers, char and bool arguments to the matchers. This requires
supporting code in the parser and the variant type.
- A command line program putting everything together and providing an already
functional tool.
Manuel Klimek [Tue, 14 May 2013 09:04:24 +0000 (09:04 +0000)]
Implement string literal breaking on unbreakable token sequences.
This fixes indentation where there are for example multiple closing
parentheses after a string literal, and where those parentheses
run over the end of the line.
During testing this revealed a bug in the implementation of
breakProtrudingToken: we don't want to change the state if we didn't
actually do anything.
Tim Northover [Tue, 14 May 2013 08:26:14 +0000 (08:26 +0000)]
AArch64: correct definition of __clear_cache
According to libgcc document __clear_cache takes two char*
pointers. I suspect GCC's actual behaviour is more subtle than that,
but char* should clearly be preferred to void*.