Ted Kremenek [Mon, 1 Oct 2007 16:34:52 +0000 (16:34 +0000)]
Removed "hasImplicitControlFlow" from class CFG, and moved it to class Stmt
as a member function. This function is no longer needed within the CFG
class, and logically belongs to the Stmt class as a predicate for a
Stmt instance.
Chris Lattner [Sun, 30 Sep 2007 08:32:27 +0000 (08:32 +0000)]
Add a new getLength() method to IdentifierInfo, which relies on a newly added
method to StringMapEntry. Steve, please use this to remove the
strlen calls in selector processing.
Patch to remove use of has table for protocol name lookup. This patch mirrors my
previous patch to do the same for class name lookup using a hash table.
Removed use of hash table for class decls and do a name look up directly.
There is still an issue if doing ScopedLookup is an overkill and we can
just access the decl using the identifier.
Added ProgramEdge.h, which defines ProgramEdge (and subclasses) that
encapsulate a program point within a CFG for use by our path-sensitive
dataflow solver.
Steve Naroff [Fri, 28 Sep 2007 22:22:11 +0000 (22:22 +0000)]
Yesterday I discovered that 78% of all selectors in "Cocoa.h" take 0/1 argument.
This motivated implementing a devious clattner inspired solution:-)
This approach uses a small value "Selector" class to point to an IdentifierInfo for the 0/1 case. For multi-keyword selectors, we instantiate a MultiKeywordSelector object (previously known as SelectorInfo). Now, the incremental cost for selectors is only 24,800 for Cocoa.h! This saves 156,592 bytes, or 86%!! The size reduction is also the result of getting rid of the AST slot, which was not strictly necessary (we will associate a selector with it's method using another table...most likely in Sema).
This change was critical to make now, before we have too many clients.
I still need to add some comments to the Selector class...will likely add later today/tomorrow.
Patch for method implementation. It populates ObjcImplementationDecl object with method implementation declarations .
It checks and warns on those methods declared in class interface and not implemented.
Created new "ExprDeclBitVector" type bundle for dataflow analyses that need boolean
values associated with ScopedDecls and CFGBlock-level Exprs. This is the common
boilerplate needed by UninitializedValues and LiveVariables.
Refactored UninitializedValues to use ExprDeclBitVector.
Shortened the string diagnostic for UninitializedValues.
Steve Naroff [Thu, 27 Sep 2007 14:38:14 +0000 (14:38 +0000)]
Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.
#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.
#3: It results in many API simplifications. Here are some highlights:
- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).
I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.
Thanks to Chris for talking this through with me and suggesting this approach.
CFG failed to build for empty functions, or functions containing only
NullStmts or empty compound statements.
We now handle such cases, although now we cannot test for CFG
construction failure by asserting that the last block constructed is
not NULL (since it now may be).
BUG 2)
CFG construction segfaulted on some cases when walking the AST and not
taking into account that some children of a statement may be NULL.
Moved "VerifyDiagnostics" variable declaration to right below ProgAction
declaration. This is because this option is logically tightly connected
to the actions defined in ProgAction.
Refactored driver so that any action that is implemented using an
ASTConsumer can also be verified using the diagnostics checker. From
the command line, users may activate diagnostic checking using the
"-verify" option. For example, "clang -verify -warn-dead-stores"
checks if the warnings flagged by the dead store checker match those
in the comments.
Note that we still have the option "-parse-ast-check" for backwards
comptability with existing test cases. This option is now equivalent to
"-parse-ast -verify".
This patch inserts ivars declared in @implementation in its object and verifies
that they conform(in type, name and numbers) to those declared in @interface.
Test case highlights kind of checking we do here.
Moved "DataflowSolver.h" to the "include/" subtree. Adjusted client
code that uses the solver to reflect the new location.
Created "FlowSensitive" subdirectory in include/clang/Analysis to hold
header files relating to flow-sensitive analyses. Moved
"DataflowValues.h" into this subdirectory.
This patch introduces a new class to keep track of class implementation info. It also adds more
semantic checks for class and protocol declarations. Test cases are good indications of kind of
checking being done in this patch.
Added "CheckASTConsumer", a function that generalizes
"CheckDiagnostics" (used for -parse-ast-check) to check the
diagnostics of any ASTConsumer.
Reimplemented CheckDiagnostics to use CheckASTConsumer instead.
Added driver option -warn-dead-stores-check, which checks the
diagnostics generated by the DeadStores checker. This is implemented
using CheckASTConsumer.111
Further refactored DataflowSolver. Now most code for the solver is shared
between forward and backward analyses, with trait classes being used
to implement the key differences in operations/functionality.
Converted the LiveVariables analysis to use the generic DataflowSolver. This,
along with removing some extra functionality that was not needed, reduced
the code for LiveVariables by over half.
Modified Driver code to handle the updated interface to LiveVariables.
Modified the DeadStores checker to handle the update interface to
LiveVariables.
Updated DataflowValues (generic ADT to store dataflow values) to also
store values for blocks. This is used by DeadStores. Updated some comments.
Added PersistentMap, an ADT that implements a map data structure that
is persistent. Adds/removals to a PersistentMap do not result in
a map being modified, but a new map being created. This will be useful
for path-sensitive analyses.
The current implementation mainly makes copies to implement this
functionality. If the map turns out to be extensively used, this
implementation will be replaced with a more efficient one that uses
data sharing (see comments in PersistentMap.h for more information).
Added smart pointer class "IntrusiveSPtr" that handles reference
counted objects that maintain their own internal reference count.
This smart pointer implementation is compatible with LLVM-style
down-casting (see in llvm: include/llvm/Support/Casting.h).
Implemented "RefCounted", a base class that objects that wish to be
managed using IntrusiveSPtrs can subclass.
Reference counted objects are being targeted for use in path-sensitive
dataflow analyses where managing many live objects becomes difficult.
This patch adds to new things to clang:
1. Handles saving and checking on protocols used in an @interface declaration
2. Checks and saves class's super class.
3. Adds semantic check to category declarations.
Match to do some semantic analysis on objective-c class decl.
1. Detect used of undeclared/forward declared super class.
2. Detect duplicate definition of a class.
Moved GraphTraits<Stmt*> to StmtGraphTraits.h. This allows consumers of Stmt.h not to have to pay the cost
of parsing the GraphTraits templates if they don't need that functionality.
Defined nodes_iterator for GraphTraits<Stmt*> to be based on llvm::df_iterator.
Added two new visitors that extend CFGStmtVisitor: CFGRecStmtVisitor and CFGRecStmtDeclVisitor.
The extended functionality of these visitors is that they automatically visit all statements in
an AST (no explicit recursion is required from subclasses), and the for the latter, decls are visited
as well.
Steve Naroff [Wed, 19 Sep 2007 16:18:46 +0000 (16:18 +0000)]
Remove SelectorTable/SelectorInfo, simply store all selectors in the central IdentifierTable.
Rationale:
We currently have a separate table to unique ObjC selectors. Since I don't need all the instance data in IdentifierInfo, I thought this would save space (and make more sense conceptually).
It turns out the cost of having duplicate entries for unary selectors (i.e. names without colons) outweighs the cost difference between the IdentifierInfo & SelectorInfo structures. Here is the data:
DataflowSolver now acccepts an "_Equal" template parameter that allows the user
to specify how two dataflow values should be compared for equality. The default
is to use std::equal_to.
Modified DataFlowValues and DataflowSolver to associate dataflow value
with CFG *edges* instead of blocks. This will fascilitate dataflow
analyses that are sensitive to block terminators, and also simplifies
some reasoning.
Updated UninitializedValues to comply to this new interface.