Jordan Rose [Fri, 8 Feb 2013 22:30:22 +0000 (22:30 +0000)]
Pull Lexer's CharInfo table out for general use throughout Clang.
Rewriting the same predicates over and over again is bad for code size and
code maintainence. Using the functions in <ctype.h> is generally unsafe
unless they are specified to be locale-independent (i.e. only isdigit and
isxdigit).
The next commit will try to clean up uses of <ctype.h> functions within Clang.
Future improvements:
- Get rid of some of the hacky ways to nicely format certain constructs.
- Merge this parser and the AnnotatingParser as we now have several parsers
that analyze (), [], etc.
Tim Northover [Fri, 8 Feb 2013 08:00:13 +0000 (08:00 +0000)]
Improve filechecking of volatile test.
My previous attempt was extremely deficient, allowing more volatiles
to be introduced and not even checking all of the ones that are
present.
This attempt doesn't try to keep track of the values stored or offsets
within particular objects, just that the correct objects are accessed
in a correctly volatile manner throughout.
Jordan Rose [Fri, 8 Feb 2013 07:28:25 +0000 (07:28 +0000)]
CMake: Include Clang unit tests in check-clang target in standalone builds.
Also, remove CLANG_BUILD_TESTS option. It won't have consistent behavior
between standalone and non-standalone builds, so I'm not going to bother
hooking it up for standalone builds. LLVM_BUILD_TESTS will continue to
control unit test inclusion in the "all" target in non-standalone builds.
Finally, fix the default value of CLANG_INCLUDE_TESTS, which was being set
to the boolean value of "LLVM_INCLUDE_TESTS", i.e. OFF, rather than actually
reading the variable ${LLVM_INCLUDE_TESTS}! If you picked up my earlier
commit, YOU WILL HAVE TO MANUALLY SET THIS OPTION BACK ON. My apologies!
Part two of r174691 (allow the unit tests to be built in standalone mode).
Nick Lewycky [Fri, 8 Feb 2013 02:38:30 +0000 (02:38 +0000)]
Fix test failure by making sure this file isn't identical to any other file
included in the same test. Clang gets confused about whether it's already built
a module for this file, when running on a content-addressible filesystem.
Jordan Rose [Fri, 8 Feb 2013 01:42:37 +0000 (01:42 +0000)]
CMake: Optionally allow running the Clang unit tests in standalone builds.
The reason this is not enabled by default is because there is no way for
Clang to guarantee that the LLVM unit testing infrastruture has been built.
However, if it /has/ been built, there's no reason why the standalone Clang
build can't use it!
This should have no effect on existing builds -- in a combined build the
value of the CLANG_INCLUDE_TESTS option defaults to the LLVM equivalent,
and in a standalone build it defaults to off.
[libclang] Attribute visitation happens out-of-source-order, make sure
we annotate properly when there is an attribute and not skip type specs
if the attribute is after the declaration.
Richard Smith [Fri, 8 Feb 2013 00:37:45 +0000 (00:37 +0000)]
Fix stack overflow and improve performance when a module contains many
overloads of a name by claiming that there are no lookup results for that name
in modules while loading the names from the module. Lookups in deserialization
really don't want to find names which they themselves are in the process of
introducing. This also has the pleasant side-effect of automatically caching
PCH lookups which found no names.
The runtime here is still quadratic in the number of overloads, but the
constant is lower.
Anna Zaks [Thu, 7 Feb 2013 23:05:47 +0000 (23:05 +0000)]
[analyzer] Report bugs when freeing memory with offset pointer
The malloc checker will now catch the case when a previously malloc'ed
region is freed, but the pointer passed to free does not point to the
start of the allocated memory. For example:
int *p1 = malloc(sizeof(int));
p1++;
free(p1); // warn
From the "memory.LeakPtrValChanged enhancement to unix.Malloc" entry
in the list of potential checkers.
Anna Zaks [Thu, 7 Feb 2013 23:05:43 +0000 (23:05 +0000)]
[analyzer] Add pointer escape type param to checkPointerEscape callback
The checkPointerEscape callback previously did not specify how a
pointer escaped. This change includes an enum which describes the
different ways a pointer may escape. This enum is passed to the
checkPointerEscape callback when a pointer escapes. If the escape
is due to a function call, the call is passed. This changes
previous behavior where the call is passed as NULL if the escape
was due to indirectly invalidating the region the pointer referenced.
Anna Zaks [Thu, 7 Feb 2013 23:05:37 +0000 (23:05 +0000)]
[analyzer] Don't reinitialize static globals more than once along a path
This patch makes sure that we do not reinitialize static globals when
the function is called more than once along a path. The motivation is
code with initialization patterns that rely on 2 static variables, where
one of them has an initializer while the other does not. Currently, we
reset the static variables with initializers on every visit to the
function along a path.
Dmitri Gribenko [Thu, 7 Feb 2013 19:09:22 +0000 (19:09 +0000)]
libclang: reduce CXString abuse
ContainerUSR is not really a CXString, but it should own the underlying memory
buffer. Thus, it is better to change the type to std::string. This will not
introduce extra copying overhead, since the workaround that is being removed
was already making a copy.
Tim Northover [Thu, 7 Feb 2013 15:11:48 +0000 (15:11 +0000)]
Only check for volatile memcpys in test.
AArch64 handles aggFct's return struct slightly differently, leading
to an extra memcpy. This test is fortunately only concerned about
volatile copies, so we can modify the grep text to filter it.
Tim Northover [Thu, 7 Feb 2013 15:11:40 +0000 (15:11 +0000)]
XFAIL test that's inappropriate for AArch64 ABI
Only some ABIs require the "signext" attribute on parameters. On most
platforms, however, it's a useful test so it's best not to limit it to some
random arbitrary platform.
Manuel Klimek [Thu, 7 Feb 2013 12:42:10 +0000 (12:42 +0000)]
Implements equalsNode for Decl and Stmt.
This is a powerful tool when doing iterative refined matches,
where another match is started inside the match callback of the first
one; this allows for example to find out whether the node was in
the condition or body of its parent if-statement.
Richard Smith [Thu, 7 Feb 2013 03:37:08 +0000 (03:37 +0000)]
Fix handling of module imports adding names to a DeclContext after qualified
name lookup has been performed in that context (this probably only happens in
C++).
1) Whenever we add names to a context, set a flag on it, and if we perform
lookup and discover that the context has had a lookup table built but has the
flag set, update all entries in the lookup table with additional names from
the external source.
2) When marking a DeclContext as having external visible decls, mark the
context in which lookup is performed, not the one we are adding. These won't
be the same if we're adding another copy of a pre-existing namespace.
Richard Smith [Thu, 7 Feb 2013 03:30:24 +0000 (03:30 +0000)]
Simplify FindExternalVisibleDeclsByName by making it return a bool indicating
if it found any decls, rather than returning a list of found decls. This
removes a returning-ArrayRef-to-deleted-storage bug from
MultiplexExternalSemaSource (in code not exercised by any of the clang
binaries), reduces the work required in the found-no-decls case with PCH, and
importantly removes the need for DeclContext::lookup to be reentrant.
-Wimplicit-fallthrough: fixed two cases where "fallthrough annotation in unreachable code" was issued incorrectly.
Summary:
-Wimplicit-fallthrough: fixed two cases where "fallthrough annotation in unreachable code" was issued incorrectly:
1. In actual unreachable code, but not immediately on a fall-through execution
path "fallthrough annotation does not directly precede switch label" is better;
2. After default: in a switch with covered enum cases. Actually, these shouldn't
be treated as unreachable code for our purpose.
Richard Smith [Thu, 7 Feb 2013 01:35:44 +0000 (01:35 +0000)]
AST dumping: indicate the previous declaration for a redeclaration, and
indicate the semantic DC if it's not the lexical DC. In passing, correct
the ascii-art child marker for a child of a FriendDecl.
Douglas Gregor [Thu, 7 Feb 2013 00:21:12 +0000 (00:21 +0000)]
Introduce -fmodules-ignore-macro=NNN to ignore a macro when building/loading modules.
The use of this flag enables a modules optimization where a given set
of macros can be labeled as "ignored" by the modules
system. Definitions of those macros will be completely ignored when
building the module hash and will be stripped when actually building
modules. The overall effect is that this flag can be used to
drastically reduce the number of
Eventually, we'll want modules to tell us what set of macros they
respond to (the "configuration macros"), and anything not in that set
will be excluded. However, that requires a lot of per-module
information that must be accurate, whereas this option can be used
more readily.
Douglas Gregor [Wed, 6 Feb 2013 22:40:31 +0000 (22:40 +0000)]
Detect when we end up trying to load conflicting module files.
This can happen when one abuses precompiled headers by passing more -D
options when using a precompiled hedaer than when it was built. This
is intentionally permitted by precompiled headers (and is exploited by
some build environments), but causes problems for modules.
First part of <rdar://problem/13165109>, detecting when something when
horribly wrong.
Manuel Klimek [Wed, 6 Feb 2013 20:36:22 +0000 (20:36 +0000)]
Cleanup of ASTMatcher macros and adding support for overloaded matchers.
This is in preparation for adding other overloaded matchers. This change
alone is a net win in LOC.
I went through all matchers and looked whether we could now encode them
as macro, or simplify them with the matcher atoms that were not
available before.
Douglas Gregor [Wed, 6 Feb 2013 18:08:37 +0000 (18:08 +0000)]
Eliminate a race condition with the global module index.
Essentially, a module file on disk could change size between the time
we stat() it and the time we open it, and we need to be robust against
such a problem.
Manuel Klimek [Wed, 6 Feb 2013 16:40:56 +0000 (16:40 +0000)]
Fix handling of comments in macros.
We now correctly format:
// Written as a macro, it is reformatted from:
#define foo(a) \
do { \
/* Initialize num to zero. */ \
int num = 10; \
/* This line ensures a is never zero. */ \
int i = a == 0 ? 1 : a; \
i = num / i; /* This division is OK. */ \
return i; \
} while (false)
Daniel Jasper [Wed, 6 Feb 2013 14:22:40 +0000 (14:22 +0000)]
Optionally derive formatting information from the input file.
With this patch, clang-format can analyze the input file for two
properties:
1. Is "int *a" or "int* a" more common.
2. Are non-C++03 constructs used, e.g. A<A<A>>.
With Google-style, clang-format will now use the more common style for
(1) and format C++03 compatible, unless it finds C++11 constructs in the
input.
Manuel Klimek [Wed, 6 Feb 2013 10:33:21 +0000 (10:33 +0000)]
Adds a convenience function selectFirst to simplify matching.
A very common use case is to search for the first occurrence of
a certain node that is a descendant of another node. In that
case, selectFirst significantly simplifies the code at the client side.
Daniel Jasper [Wed, 6 Feb 2013 10:05:46 +0000 (10:05 +0000)]
Handle nested ObjC calls.
Properly handle annotation contexts while calculating extra information
for each token. This enable nested ObjC calls and thus solves (most of)
llvm.org/PR15164. E.g., we can now format:
Nico Weber [Wed, 6 Feb 2013 06:20:11 +0000 (06:20 +0000)]
Formatter: No space after & and * in front of ObjC message expressions.
1. let determineStarAmp() check of unary operators before checking for
"is next '['". That check was added in r173150, and the test from that
revision passes either way.
2. change determineStarAmp() to categorize '*' and '&' after '=' as unary
operator.
3. don't let parseSquare() overwrite the type of a '*' or '&' before the start
of an objc message expression if has the role of unary operator.
Anna Zaks [Wed, 6 Feb 2013 00:01:14 +0000 (00:01 +0000)]
[analyzer]Revert part of r161511; suppresses leak false positives in C++
This is a "quick fix".
The underlining issue is that when a const pointer to a struct is passed
into a function, we do not invalidate the pointer fields. This results
in false positives that are common in C++ (since copy constructors are
prevalent). (Silences two llvm false positives.)
Ted Kremenek [Tue, 5 Feb 2013 22:00:19 +0000 (22:00 +0000)]
Change subexpressions to be visited in the CFG from left-to-right.
This is a more natural order of evaluation, and it is very important
for visualization in the static analyzer. Within Xcode, the arrows
will not jump from right to left, which looks very visually jarring.
It also provides a more natural location for dataflow-based diagnostics.
Along the way, we found a case in the analyzer diagnostics where we
needed to indicate that a variable was "captured" by a block.
-fsyntax-only timings on sqlite3.c show no visible performance change,
although this is just one test case.
Jordan Rose [Tue, 5 Feb 2013 17:31:34 +0000 (17:31 +0000)]
[analyzer] Add a doc describing the internals of RegionStore.
This is a text file with Markdown-ish formatting because we haven't decided
where analyzer internal documents should go, but it's probably better to
have this in source control than sitting on my local drive forever.
[frontend] Don't put a PCH/PTH filename into the set of includes in the preprocessor options;
since only one of them is allowed in command-line, process them separately.
Otherwise, if more than one is specified in the command-line, one is processed normally
and the others are going to be treated and included as header files.
Daniel Jasper [Tue, 5 Feb 2013 10:07:47 +0000 (10:07 +0000)]
Initial support for formatting ObjC method declarations/calls.
We can now format stuff like:
- (void)doSomethingWith:(GTMFoo *)theFoo
rect:(NSRect)theRect
interval:(float)theInterval {
[myObject doFooWith:arg1 //
name:arg2
error:arg3];
}
This seems to fix everything mentioned in llvm.org/PR14939.