Ted Kremenek [Wed, 22 Aug 2007 21:03:50 +0000 (21:03 +0000)]
Added explicit pointer within class CFG to the Entry block.
Before we assumed that the first block in the list of blocks was the entry
block, but this has posed hurdles during CFG construction.
Ted Kremenek [Wed, 22 Aug 2007 18:22:34 +0000 (18:22 +0000)]
Added CFG support for: for loops
In CFG dumper, refactored the code to print block terminators into a
StmtVisitor.
Added the method "FinishBlock" to CFGBuilder to do the reversal of statements
in a block instead of calling "reverseStmts" for a block directly. This
was necessary to fix a bug in how blocks with labels were being processed
(some cases would cause the statements to be reversed twice). FinishBlock
detects blocks that start with labels and doesn't do a second reversal.
Steve Naroff [Wed, 22 Aug 2007 16:35:03 +0000 (16:35 +0000)]
Add support for parsing method prototypes (and other stuff required by @interface).
Still need to finish Parser::ParseObjCMethodDecl(). Before I do, I need to do a minor
refactoring of ParseDeclarationOrFunctionDefinition(), to disallow function definitions.
At the moment, @inteface allows function defs (which is incorrect).
Chris Lattner [Tue, 21 Aug 2007 05:54:00 +0000 (05:54 +0000)]
Split complex arithmetic codegen out from aggregate codegen.
This means that we get rid of tons of intermediate allocas. For
example:
void foo(double _Complex a, double _Complex b) {
a = b+a+a;
}
this used to have 4 temporary allocas, now it has zero of them.
This also simplifies the individual visitor methods because they
now can all operate on real/imag pairs instead of having to
load/store all over the place.
Chris Lattner [Tue, 21 Aug 2007 04:04:25 +0000 (04:04 +0000)]
Switch StmtVisitor from using dynamic to static dispatch. This makes it
significantly faster and actually reduces the amount of code in the system.
This also allows for future visitor changes.
Ted Kremenek [Mon, 20 Aug 2007 16:18:38 +0000 (16:18 +0000)]
Modified ArraySubscriptExpr to have accessors getLHS and getRHS in addition
to getBase and getIdx. getBase and getIdx now return a "normalized" view
of the expression (e.g., always "A[4]" instead of possibly "4[A]"). getLHS
and getRHS return the expressions with syntactic fidelity to the original
source code.
Also modified client code of ArraySubscriptExpr, including the AST dumper
and pretty printer, the return-stack value checker, and the LLVM code
generator.
Ted Kremenek [Fri, 17 Aug 2007 16:46:58 +0000 (16:46 +0000)]
Added extra semantic checking to do basic detection of
"return of stack addresses." ParseReturnStmt now calls CheckReturnStackAddr
to determine if the expression in the return statement evaluates to an
address of a stack variable. If so, we issue a warning.
Steve Naroff [Thu, 16 Aug 2007 21:48:38 +0000 (21:48 +0000)]
Fixed Sema::CheckEqualityOperands() and Sema::CheckRelationalOperands() to deal more
thoughtfully with incompatible pointers. This includes:
- Emit a diagnostic when two pointers aren't compatible!
- Promote one of the pointers/integers so we maintain the invariant expected by the
code generator (i.e. that the left/right types match).
- Upgrade the pointer/integer comparison diagnostic to include the types.
Ted Kremenek [Wed, 15 Aug 2007 22:33:19 +0000 (22:33 +0000)]
Added a comment to ArraySubscriptExpr to note that the expressions like
"A[4]" are equivalent to "4[A]", and that a test that the expression
returned by "getBase()" has a pointer type is required to resolve which
subexpression is the "true" base expression of the array index.
Ted Kremenek [Tue, 14 Aug 2007 17:39:48 +0000 (17:39 +0000)]
Added support for additional format string checking for the printf
family of functions. Previous functionality only included checking to
see if the format string was a string literal. Now we check parse the
format string (if it is a literal) and perform the following checks:
(1) Warn if: number conversions (e.g. "%d") != number data arguments.
(2) Warn about missing format strings (e.g., "printf()").
(3) Warn if the format string is not a string literal.
(4) Warn about the use se of '%n' conversion. This conversion is
discouraged for security reasons.
(5) Warn about malformed conversions. For example '%;', '%v'; these
are not valid.
(6) Warn about empty format strings; e.g. printf(""). Although these
can be optimized away by the compiler, they can be indicative of
broken programmer logic. We may need to add additional support to
see when such cases occur within macro expansion to avoid false
positives.
(7) Warn if the string literal is wide; e.g. L"%d".
(8) Warn if we detect a '\0' character WITHIN the format string.
Ted Kremenek [Mon, 13 Aug 2007 22:26:47 +0000 (22:26 +0000)]
Added documentation to StringLiteral noting that the strings returned by
getStrData() are not null-terminated, and the lengths of these strings should
be determined using getByteLength().
Chris Lattner [Sat, 11 Aug 2007 00:04:45 +0000 (00:04 +0000)]
start splitting out aggregate value computation from EmitExpr into EmitAggExpr.
aggregate value and scalar expression computation are very different, this
gets them away from each other. This causes a temporary regression on some
complex number examples.
Ted Kremenek [Fri, 10 Aug 2007 21:21:05 +0000 (21:21 +0000)]
Added "id_idx" parameter to CheckPrintfArguments. This will be used
by CheckPrintfArguments to determine if a given printf function
accepts a va_arg argument.
Ted Kremenek [Fri, 10 Aug 2007 21:13:51 +0000 (21:13 +0000)]
Moved id_asprintf before id_vsnprintf in the enum used for indexing
KnownFunctionIDs. This allows us to test for a printf-like function
that accepts a va_arg argument using a range comparison.
Chris Lattner [Fri, 10 Aug 2007 20:18:51 +0000 (20:18 +0000)]
initial support for checking format strings, patch by Ted Kremenek:
"I've coded up some support in clang to flag warnings for non-constant format strings used in calls to printf-like functions (all the functions listed in "man fprintf"). Non-constant format strings are a source of many security exploits in C/C++ programs, and I believe are currently detected by gcc using the flag -Wformat-nonliteral."
Chris Lattner [Fri, 10 Aug 2007 18:27:41 +0000 (18:27 +0000)]
Build ASTs before relexing the file. This avoids having comment finding mutate the
preprocessor state, causing bogus diagnostics when the file is parsed for real. This
implements Misc/diag-checker.c. Thanks to Ted for noticing this.
Chris Lattner [Thu, 9 Aug 2007 00:36:22 +0000 (00:36 +0000)]
Dump out types for expressions, and handle typedefs nicely.
This allows us to dump:
typedef short S;
int test(S X, long long Y) {
return X < ((100));
}
as:
typedef short S;
int test(S X, long long Y)
(CompoundStmt 0x2905d40
(ReturnStmt 0x2905d30
(BinaryOperator 0x2905d10 'int' '<'
(ImplicitCastExpr 0x2905d00 'int'
(DeclRefExpr 0x2905c80 'S':'short' Decl='X' 0x2905c20))
(ParenExpr 0x2905ce0 'int'
(ParenExpr 0x2905cc0 'int'
(IntegerLiteral 0x2905ca0 'int' 100))))))
Chris Lattner [Wed, 8 Aug 2007 22:51:59 +0000 (22:51 +0000)]
add a new AST dumper interface (E->dump()). This dumps out
the AST in a structural, non-pretty, form useful for understanding
the AST. It isn't quite done yet, but is already somewhat useful.
For this example:
int test(short X, long long Y) {
return X < ((100));
}
we get (with -parse-ast-dump):
int test(short X, long long Y)
(CompoundStmt 0x2905ce0
(ReturnStmt 0x2905cd0
(BinaryOperator 0x2905cb0 '<'
(ImplicitCastExpr 0x2905ca0
(DeclRefExpr 0x2905c20 Decl='X' 0x2905bb0))
(ParenExpr 0x2905c80
(ParenExpr 0x2905c60
(IntegerLiteral 0x2905c40 100))))))
Steve Naroff [Wed, 8 Aug 2007 17:48:34 +0000 (17:48 +0000)]
Add support for __builtin_classify_type(). This builtin function isn't "public", however
it is used by "tgmath.h" (so we need to support it). It might also come in handy when
developing the overloaded function macros for OpenCU.
Next check-in will make this an integer constant expression...