Added an early implementation of Live-Variables analysis built on
source-level CFGs. This code may change significantly in the near
future as we explore different means to implement dataflow analyses.
Added a driver option, -dump-live-variables, to view the output of
live variable analysis. This output is very ALPHA; it will be improved shortly.
1. Fix parsing of method prototype involving c-style argument declarations.
2. Fixes all allowable key-words used as selectors.
3. Template to do the messaging parse.
4. A test case for all allowable selector names.
Steve Naroff [Tue, 4 Sep 2007 02:20:04 +0000 (02:20 +0000)]
More fun with initializers!
- Fixed many bugs, enhanced test case considerably, added a diagnostic, etc.
- Refactored CheckInitList() into CheckVariableInitList()/CheckConstantInitList().
- Added CheckInitExpr().
- Support for multi-dimensional arrays looking good.
Steve Naroff [Sun, 2 Sep 2007 02:04:30 +0000 (02:04 +0000)]
Start implementing semantic analysis for C initializers.
Step 1: Start instantiating InitListExpr's.
Step 2: Call newly added function Sema::CheckInitializer() from Sema::ParseDeclarator().
Step 3: Give InitListExpr's a preliminary type.
Step 4: Start emitting diagnostics for simple assignments.
Note:
As a result of step 1, the CodeGen/mandel.c test asserts "Unimplemented agg expr!", which is expected.
As a result of step 4, the test below now fails. This isn't expected and needs to be investigated (it appears type checking for C++ references is flawed in some way).
******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************
Command:
clang -fsyntax-only Sema/cxx-references.cpp
Output:
Sema/cxx-references.cpp:8:12: warning: incompatible pointer types assigning 'int &*' to 'int *'
int *p = &r;
^~
Sema/cxx-references.cpp:10:20: error: incompatible types assigning 'int (int)' to 'int (&)(int)'
int (&rg)(int) = g;
^
Sema/cxx-references.cpp:13:18: error: incompatible types assigning 'int [3]' to 'int (&)[3]'
int (&ra)[3] = a;
^
Sema/cxx-references.cpp:16:14: error: incompatible types assigning 'int *' to 'int *&'
int *& P = Q;
^
4 diagnostics generated.
******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************
Ted Kremenek [Fri, 31 Aug 2007 21:30:12 +0000 (21:30 +0000)]
Added "PrinterHelper" interface (include/AST/PrinterHelper) that can
be passed as an (optional) argument to StmtPrinter to customize
printing of AST nodes.
Used new PrinterHelper interface to enhance printing and visualization
of CFGs. The CFGs now illustrate the semantic connectives between
statements and terminators, wheras in the previous printing certain
expressions would (visible) be printed multiple times to reflect which
expressions used the results of other expressions.
The end result is that the CFG is easier to read for flow of
expression values (following principles similar to the LLVM IR).
Steve Naroff [Fri, 31 Aug 2007 17:20:07 +0000 (17:20 +0000)]
Removed Sema::VerifyConstantArrayType(). With the new Array/ConstantArray/VariableArray nodes, this
routine was causing more trouble than it was worth. Anders/Chris noticed that it could return an error code
without emiting a diagnostic (which results in an silent invalid decl, which should *never* happen). In addition,
this routine didn't work well for typedefs and field decls. Lastly, it didn't consider that initializers aren't
in place yet.
Added Type::getAsConstantArrayType(), Type::getAsVariableArrayType(), Type::getAsVariablyModifiedType(),
and Type::isVariablyModifiedType();
Modified Sema::ParseDeclarator() and Sema::ParseField() to use the new predicates. Also added a FIXME for
the initializer omission. Also added a missing test for "static" @ file scope.
Chris Lattner [Fri, 31 Aug 2007 04:44:06 +0000 (04:44 +0000)]
Implement codegen support for lowering "library builtins" like __builtin_isinf
to their corresponding library routines (e.g. isinf). This allows us to handle
all the stuff in macos math.h, and other stuff as it's added to *Builtins.def.
Steve Naroff [Thu, 30 Aug 2007 22:35:45 +0000 (22:35 +0000)]
Final phase of array cleanup (for now), removing a FIXME from yesterday.
Moved several array constraints checks from Sema::VerifyConstantArrayType() to
Sema::GetTypeForDeclarator(). VerifyConstantArrayType() is now very simple, and
could be removed eventually.
Now, we get the following (correct) messages for BlockVarDecls:-)
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang x.c -pedantic
x.c:4:20: error: size of array has non-integer type 'float'
int size_not_int[f];
^
x.c:5:21: error: array size is negative
int negative_size[1-2];
^~~
x.c:6:17: warning: zero size arrays are an extension
int zero_size[0];
^
3 diagnostics generated.
Ted Kremenek [Thu, 30 Aug 2007 18:48:11 +0000 (18:48 +0000)]
Fixed a bug in constructing CFG blocks for case statement fall-through
introduced by moving "CaseStmt" pointers out of the list of statements
and into the explicit "label" associated with a CFGBlock. --This
line, and those below, will be ignored--
Steve Naroff [Thu, 30 Aug 2007 18:10:14 +0000 (18:10 +0000)]
Polish yesterday's Array/ConstantArray/VariableArray rewrite, removing a couple FIXME's.
Refactored Array/VariableArray, moving SizeModifier/IndexTypeQuals back up to Array. These
attributes are not specific to VLA's. Most of them are specific to array parameter types.
Ted Kremenek [Thu, 30 Aug 2007 16:50:46 +0000 (16:50 +0000)]
Fixed bug for CaseStmt where the child_begin/child_end methods were not
including the expressions in the case statement itself (not the body of
the case).
This required moving SubStmt out of SwitchCase into CaseStmt and DefaultStmt
respectively. getSubStmt() now is a virtual call for SwitchCase, but is
a direct (static) call for CaseStmt and DefaultStmt.
It turns out that this exposed a fairly major flaw in the type system,
array types were never getting uniqued! This is because all array types
contained an expression, which aren't unique.
To solve this, we now have 2 array types, ConstantArrayType and
VariableArrayType. ConstantArrayType's are unique, VAT's aren't.
This is a fairly extensive set of fundamental changes. Fortunately,
all the tests pass. Nevertheless, there may be some collateral damage:-)
If so, let me know!
Chris Lattner [Thu, 30 Aug 2007 01:00:35 +0000 (01:00 +0000)]
Previous commit should have been:
Use Ted's child walking interface to allow the dumper to walk the tree
in one place and only have node-specific callbacks worry about
formatting the nodes (instead of formatting the nodes plus walking the
tree).
This commit eliminates now default cases by letting them fall through with
the normal visitor stuff.
Ted Kremenek [Wed, 29 Aug 2007 23:20:49 +0000 (23:20 +0000)]
Added an (optional) explicit "Label" statement to CFGBlock. If a
block begins with a label or case statement, CFGBlock::getLabel() will
return the corresponding LabelStmt/CaseStmt/DefaultStmt.
LabelStmts and SwitchCases no longer appear within the "executable"
statements of a CFGBlock.
More cleanups on visualization/pretty-printing of CFGs (less verbose).
Ted Kremenek [Wed, 29 Aug 2007 21:56:09 +0000 (21:56 +0000)]
Added GraphTraits to source-level CFGs (CFG and CFGBlock) to allow
(LLVM-provided) graph algorithms such as DFS and graph visualization
to work effortless on source-level CFGs.
Further cleanup on pretty printing of CFGs. CFGBlock::dump and
CFGBlock::print now take the parent CFG as an argument. This allows
CFGBlocks to print their own appropriate label indicating whether or
not they are the Entry/Exit/IndirectGotoBlock without the CFG::print
routine doing it instead.
Added Graphviz visualization for CFGs: CFG::viewCFG. This employs the
GraphTraits just implemented.
Added "-view-cfg" mode the to clang driver. This is identical to
"-dump-cfg" except that it calls Graphviz to visualize the CFGs
instead of dumping them to the terminal.
Chris Lattner [Wed, 29 Aug 2007 17:48:46 +0000 (17:48 +0000)]
Teach Type::is[un]SignedIntegerType about enum decls. This allows the code generator
to emit signed comparisons when needed for enum decl references. This implements
test/CodeGen/enum.c. I think enums should be good now.