Douglas Gregor [Fri, 11 Feb 2011 19:46:30 +0000 (19:46 +0000)]
Rename the operation that loads a preprocessed entity from a given offset to indicate that we're loading from an offset, not an index, lest one be confused. No functionality change.
Fix a block sema bug where result type of initializer
is unqualified but its initialized is qualified.
This is for c only and fixes the imm. problem.
c++ is more involved and is wip.
// rdar://8979379
Zhanyong Wan [Fri, 11 Feb 2011 18:44:49 +0000 (18:44 +0000)]
Improves Clang's virtual file handling.
This patch contains:
- making some of the existing comments more accurate in the presence
of virtual files/directories.
- renaming some private data members of FileManager to match their roles better.
- creating 'DirectorEntry's for the parent directories of virtual
files, such that we can tell whether two virtual files are from the
same directory. This is useful for injecting virtual files whose
directories don't exist in the real file system.
- minor clean-ups and adding comments for class
FileManager::UniqueDirContainer and FileManager::UniqueFileContainer.
- adding statistics on virtual files to FileManager::PrintStats().
- adding unit tests to verify the existing and new behavior of FileManager.
Ken Dyck [Fri, 11 Feb 2011 01:54:29 +0000 (01:54 +0000)]
Add a helper function, ASTContext::toBits(), that converts sizes in
CharUnits to sizes in bits, and use it to tidy up the places where the
conversion was done explicitly.
Douglas Gregor [Fri, 11 Feb 2011 00:52:17 +0000 (00:52 +0000)]
Eliminate a major performance problem with chained PCH, where we were
causing the deserialization of a large number of declarations when
writing the visible-updates record for the translation unit in C. This
takes us from:
when generating a chained PCH for a header that #includes Cocoa.h
(from a PCH file) and adds one simple function declaration. The
generated PCH file is now only 9580 bytes (down from > 2MB).
Douglas Gregor [Fri, 11 Feb 2011 00:26:14 +0000 (00:26 +0000)]
Implement AST/PCH chaining support for macro definitions. Previously,
we would deserialize all of the macro definitions we knew about while
serializing the macro definitions at the end of the AST/PCH file. Even
though we skipped most of them (since they were unchanged), it's still
a performance problem.
Now, we do the standard AST/PCH chaining trick: watch what identifiers
are deserialized as macro names, and consider only those identifiers
(along with macro definitions that have been deserialized/written in
the source) when serializing the preprocessor state.
Douglas Gregor [Thu, 10 Feb 2011 18:20:09 +0000 (18:20 +0000)]
When we're writing macro definitions to an AST/PCH File, sort the
macro definitions by macro name first. That way, we'll get a stable
ordering in the AST/PCH file.
Douglas Gregor [Thu, 10 Feb 2011 17:09:37 +0000 (17:09 +0000)]
Implement two related optimizations that make de-serialization of
AST/PCH files more lazy:
- Don't preload all of the file source-location entries when reading
the AST file. Instead, load them lazily, when needed.
- Only look up header-search information (whether a header was already
#import'd, how many times it's been included, etc.) when it's needed
by the preprocessor, rather than pre-populating it.
Previously, we would pre-load all of the file source-location entries,
which also populated the header-search information structure. This was
a relatively minor performance issue, since we would end up stat()'ing
all of the headers stored within a AST/PCH file when the AST/PCH file
was loaded. In the normal PCH use case, the stat()s were cached, so
the cost--of preloading ~860 source-location entries in the Cocoa.h
case---was relatively low.
However, the recent optimization that replaced stat+open with
open+fstat turned this into a major problem, since the preloading of
source-location entries would now end up opening those files. Worse,
those files wouldn't be closed until the file manager was destroyed,
so just opening a Cocoa.h PCH file would hold on to ~860 file
descriptors, and it was easy to blow through the process's limit on
the number of open file descriptors.
By eliminating the preloading of these files, we neither open nor stat
the headers stored in the PCH/AST file until they're actually needed
for something. Concretely, we went from
*** HeaderSearch Stats:
835 files tracked.
364 #import/#pragma once files.
823 included exactly once.
6 max times a file is included.
3 #include/#include_next/#import.
0 #includes skipped due to the multi-include optimization.
1 framework lookups.
0 subframework lookups.
*** Source Manager Stats:
835 files mapped, 3 mem buffers mapped.
37460 SLocEntry's allocated, 11215575B of Sloc address space used.
62 bytes of files mapped, 0 files with line #'s computed.
with a trivial program that uses a chained PCH including a Cocoa PCH
to
*** HeaderSearch Stats:
4 files tracked.
1 #import/#pragma once files.
3 included exactly once.
2 max times a file is included.
3 #include/#include_next/#import.
0 #includes skipped due to the multi-include optimization.
1 framework lookups.
0 subframework lookups.
*** Source Manager Stats:
3 files mapped, 3 mem buffers mapped.
37460 SLocEntry's allocated, 11215575B of Sloc address space used.
62 bytes of files mapped, 0 files with line #'s computed.
John McCall [Thu, 10 Feb 2011 06:50:24 +0000 (06:50 +0000)]
Move the check that gives functions with unique-external types unique-external
linkage into Decl.cpp. Disable this logic for extern "C" functions, because
the operative rule there is weaker. Fixes rdar://problem/8898466
Ted Kremenek [Thu, 10 Feb 2011 01:03:09 +0000 (01:03 +0000)]
Add hack to CMakeLists.txt so that StaticAnalyzer libraries find their corresponding headers.
This is a hack because we really should only search in the 'include/clang/StaticAnalyzer' directory
if we are in 'lib/StaticAnalyzer'. My CMake knowledge is limited, so I appeal to anyone with
more expertise.
Douglas Gregor [Wed, 9 Feb 2011 18:47:31 +0000 (18:47 +0000)]
Finish up the diagnostic client before we've torn down the ASTReader,
since the diagnostic client might poke at source locations that have
not yet been deserialized.
John McCall [Wed, 9 Feb 2011 08:16:59 +0000 (08:16 +0000)]
Remove vtables from the Stmt hierarchy; this was pretty easy as
there were only three virtual methods of any significance.
The primary way to grab child iterators now is with
Stmt::child_range children();
Stmt::const_child_range children() const;
where a child_range is just a std::pair of iterators suitable for
being llvm::tie'd to some locals. I've left the old child_begin()
and child_end() accessors in place, but it's probably a substantial
penalty to grab the iterators individually now, since the
switch-based dispatch is kindof inherently slower than vtable
dispatch. Grabbing them together is probably a slight win over the
status quo, although of course we could've achieved that with vtables, too.
I also reclassified SwitchCase (correctly) as an abstract Stmt
class, which (as the first such class that wasn't an Expr subclass)
required some fiddling in a few places.
There are somewhat gross metaprogramming hooks in place to ensure
that new statements/expressions continue to implement
getSourceRange() and children(). I had to work around a recent clang
bug; dgregor actually fixed it already, but I didn't want to
introduce a selfhosting dependency on ToT.
Douglas Gregor [Wed, 9 Feb 2011 02:03:05 +0000 (02:03 +0000)]
When IRgen refers to a function declaration that is not a definition,
and we later find the definition, make sure that we add the definition
(not the declaration) to the list of deferred definitions to
emit. Fixes PR8864.
Ted Kremenek [Wed, 9 Feb 2011 01:27:33 +0000 (01:27 +0000)]
static analyzer: Further reduce the analyzer's memory usage when analyzing sqlite3 by 7-10% by recylcing "uninteresting" ExplodedNodes.
The optimization involves eagerly pruning ExplodedNodes from the ExplodedGraph that contain
practically no difference between the predecessor and successor nodes. For example, if
the state is different between a predecessor and a node, the node is left in. Only for
the 'environment' component of the state do we not care if the ExplodedNodes are different.
This paves the way for future optimizations where we can reclaim the environment objects.
John McCall [Tue, 8 Feb 2011 22:35:49 +0000 (22:35 +0000)]
When checking the 'weak' and 'weakref' attributes, look for non-external
linkage rather than the presence of the 'static' storage class specifier.
Fixes rdar://problem/8814626.
[analyzer] Move the files in lib/StaticAnalyzer to lib/StaticAnalyzer/Core.
Eventually there will also be a lib/StaticAnalyzer/Frontend that will handle initialization and checker registration.
Yet another library to avoid cyclic dependencies between Core and Checkers.
Douglas Gregor [Tue, 8 Feb 2011 21:58:10 +0000 (21:58 +0000)]
Split the serialized representation for the detailed preprocessing
record away from the core processor record. The tangling of these two
data structures led to some inefficiencies (e.g., deserializing all
of the detailed preprocessing record when we didn't need it, such as
while performing code completion) along with some unnecessary
ugliness.
In Sema::CheckShadow, get the DeclContext from the variable that we are checking
instead from the Scope; Inner scopes in bodies don't have DeclContexts associated with them.
Douglas Gregor [Tue, 8 Feb 2011 02:14:35 +0000 (02:14 +0000)]
Sema::MaybeBindToTemporary() shouldn't treat any expression returning
a glvalue as a temporary. Previously, we were enumerating all of the
cases that coul return glvalues and might be called with
Sema::MaybeBindToTemporary(), but that was gross and we missed the
Objective-C property reference case.
John McCall [Mon, 7 Feb 2011 10:33:21 +0000 (10:33 +0000)]
A few more tweaks to the blocks AST representation:
- BlockDeclRefExprs always store VarDecls
- BDREs no longer store copy expressions
- BlockDecls now store a list of captured variables, information about
how they're captured, and a copy expression if necessary
With that in hand, change IR generation to use the captures data in
blocks instead of walking the block independently.
Additionally, optimize block layout by emitting fields in descending
alignment order, with a heuristic for filling in words when alignment
of the end of the block header is insufficient for the most aligned
field.
Douglas Gregor [Sat, 5 Feb 2011 19:42:43 +0000 (19:42 +0000)]
Improve our uniquing of file entries when files are re-saved or are
overridden via remapping. Thus, when we create a "virtual" file in the
file manager, we still stat() the real file that lives behind it so
that we can provide proper uniquing based on inodes. This helps keep
the file manager much more consistent.
To take advantage of this when reparsing files in libclang, we disable
the use of the stat() cache when reparsing or performing code
completion, since the stat() cache is very likely to be out of date in
this use case.