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.
Ted Kremenek [Tue, 28 Aug 2007 19:26:49 +0000 (19:26 +0000)]
Added support for indirect-gotos (GCC extension) in source-level CFGs.
This involves the construction of a specialized "dispatch" block that
all basic blocks containing indirect gotos unconditionally transfer
control-flow to. The successors of the dispatch block has as its successors
all of the blocks containing labels whose address was taken somewhere in
the function.
Chris Lattner [Tue, 28 Aug 2007 18:24:31 +0000 (18:24 +0000)]
Change EnumDecl to store its corresponding integer type
directly in it. Remove TargetInfo::getEnumPolicy, as there is only
one policy that we support right now.
Steve Naroff [Tue, 28 Aug 2007 03:03:08 +0000 (03:03 +0000)]
Implement more thoughful error recovery when dealing with bogus declarator types.
For example, the following code was resulting in spurious warnings. This was the result of
Sema::GetTypeForDeclarator() synthesizing a type to hand back to the caller (in this case,
"int []", instead of "struct s[]", which is invalid).
struct s;
struct s* t (struct s z[]) { // expected-error {{array has incomplete element type}}
return z;
}
Strategy: Flag the error in Declarator/DeclaratorChunk. This info is later stored in
the ParmVarDecl. If the decl is referenced, Sema::ParseIdentifierExpr() will check if
the type is invalid. If so, it quietly returns "true", without instantiating a DeclRefExpr.
This seems to work nicely. If Chris is happy with the approach, I will generalize this to
all VarDecls.
Ted Kremenek [Mon, 27 Aug 2007 19:46:09 +0000 (19:46 +0000)]
Changes to CFGBuilder:
+ Added the creation of an empty Entry block at the end of CFG
construction if the Entry block in the CFG contains multiple
predecessors (which can happen with labels and do loops).
+ Fixed bug in the creation of an empty Exit block with functions where not
all paths end in a return statement (but some do). Basic blocks with
return statements were jumping to a (sometimes) non-empty block.
+ FinishBlock no longer checks for labels at the beginning of a basic
block before reversing the statements in the block. This is because
the recursion invariants of the builder methods have been cleaned up,
and blocks are only passed to FinishBlock at most once.
+ Modified handling of "if", "for", "while", "do", and "switch" to allow
condition expressions that can span multiple basic blocks. This allows
such conditions to contain short-circuit expressions (which span multiple
blocks in the CFG).
Ted Kremenek [Mon, 27 Aug 2007 16:39:17 +0000 (16:39 +0000)]
Updated checker for "return of address of stack variable" to look for
implicit casts from T to T& at the topmost part of the return-value expression.
This checking may be needed within EvalAddr later on. We'll wait until
test cases show this kind of logic is necessary (as more C++ features are
implemented in clang).
Steve Naroff [Mon, 27 Aug 2007 01:27:54 +0000 (01:27 +0000)]
Replaced ASTContext::maxComplexType() with ASTContext::getFloatingTypeOfSizeWithinDomain().
Changed Sema::UsualArithmeticConversions to correctly implement complex/float conversions,
using maxFloatingType() with getFloatingTypeOfSizeWithinDomain().