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.
llvm-svn: 41554
Converted ParmVarDecl, FileVarDecl, BlockVarDecl, and Sema::ParseIdentifierExpr() to use the idiom.
Updated array-constraint.c to make sure we no longer get "undeclared identifier" errors:-)
llvm-svn: 41552
variables that have a pointer type, or arrays that contain pointers.
This fixes a crash on the following code:
int *h[3];
int **foo(int i)
{
return &(h[i]);
}
This bug was reported by Keith Bauer (thanks!).
llvm-svn: 41546
t.c:1:12: warning: ISO C restricts enumerator values to range of 'int' (180388626432 is too large)
enum e {A, B = 42LL << 32, C = -4, D = 12456 };
^
llvm-svn: 41530
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.
llvm-svn: 41521
+ 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).
llvm-svn: 41508
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).
llvm-svn: 41493
Modified Type::typesAreCompatible() to use the above.
This fixes the following bug submitted by Keith Bauer (thanks!).
int equal(char *a, const char *b)
{
return a == b;
}
Also tweaked Sema::CheckCompareOperands() to ignore the qualifiers when
comparing two pointer types (though it doesn't relate directly to this bug).
llvm-svn: 41476
Changed Sema::UsualArithmeticConversions to correctly implement complex/float conversions,
using maxFloatingType() with getFloatingTypeOfSizeWithinDomain().
llvm-svn: 41474
Remove bogus type conversions in Sema::GetTypeForDeclarator(). This commit
only deals with the array types (DeclaratorCheck::Array), though the
rest of this routine should be reviewed. Given the complexity of C declarators,
I don't want to change the entire routine now (will discuss with Chris tomorrow).
llvm-svn: 41443
hold declarations. Instead, introduce a new "DeclScope" scope type that
holds them explicitly. For now, all scopes have this bit, but in the
future we can use them to fix some issues Neil noticed.
llvm-svn: 41431
2) Add support for lexing imaginary constants (a GCC extension):
t.c:5:10: warning: imaginary constants are an extension
A = 1.0iF;
^
3) Make the 'invalid suffix' diagnostic pointer more accurate:
t.c:6:10: error: invalid suffix 'qF' on floating constant
A = 1.0qF;
^
instead of:
t.c:6:10: error: invalid suffix 'qF' on floating constant
A = 1.0qF;
^
llvm-svn: 41411
char *C;
C != ((void*)0);
Should not warn about incompatible pointer types. Also, make sure to
insert an implicit conversion even if the operand is null.
llvm-svn: 41408
eliminates the possibility that the left hand expression is an ImplicitCastExpr.
As a result, I removed the check for ImplicitCastExpr in Expr::isLvalue().
This results in the following AST's...
[dylan:~/llvm/tools/clang] admin% cat fix.c
short x; void test4(char c) {
x += c;
x = x + c;
}
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang fix.c -parse-ast-dump
Read top-level variable decl: 'x'
void test4(char c)
(CompoundStmt 0x2605d30
(CompoundAssignOperator 0x2605c40 'short' '+='
(DeclRefExpr 0x2605c00 'short' Decl='x' 0x2605a80)
(DeclRefExpr 0x2605c20 'char' Decl='c' 0x2605bc0))
(BinaryOperator 0x2605d10 'short' '='
(DeclRefExpr 0x2605c60 'short' Decl='x' 0x2605a80)
(ImplicitCastExpr 0x2605d00 'short'
(BinaryOperator 0x2605ce0 'int' '+'
(ImplicitCastExpr 0x2605cc0 'int'
(DeclRefExpr 0x2605c80 'short' Decl='x' 0x2605a80))
(ImplicitCastExpr 0x2605cd0 'int'
(DeclRefExpr 0x2605ca0 'char' Decl='c' 0x2605bc0))))))
llvm-svn: 41404
This fixes the following bug...
t.c:1:31: error: expression is not assignable
short x; void foo(char c) { x += c; }
This case, among others are now captured in implicit-casts.c.
llvm-svn: 41402
it is o.k. for the LHS and RHS to have different types. Converting the type can cause
errors like the one Chris noticed (below).
This change required a fair number of diffs (since there is a lot of shared code
between single and compound assignments). This makes the API's look a bit uglier,
however I couldn't think of a better way to do it (without duplicating code).
Fix the following (incorrect) error:
int A;
long long B;
void foo() {
A /= B;
}
$ clang ~/scalar.c -emit-llvm
/Users/sabre/scalar.c:6:5: error: expression is not assignable
A /= B;
~ ^
Now it works properly...
[dylan:~/llvm/tools/clang] admin% cat compound.c
int A;
long long B;
void foo() {
A /= B;
}
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang compound.c -parse-ast-dump
Read top-level variable decl: 'A'
Read top-level variable decl: 'B'
void foo()
(CompoundStmt 0x2605c40
(BinaryOperator 0x2605c20 'int' '/=' ComputeTy='long long'
(DeclRefExpr 0x2605be0 'int' Decl='A' 0x2605a80)
(DeclRefExpr 0x2605c00 'long long' Decl='B' 0x2605ab0)))
llvm-svn: 41364
subclass of Stmt will implement child_begin() and child_end(), which will
be used to iterate over all the children (subexpressions/substatements) of
a Stmt object. This will provide for easy traversal over the AST, which
is useful for a variety of purposes.
None of the interfaces to subclasses of Stmt will be changed (other than
adding the child_begin and child_end methods).
The only caveat is that the implementation of subclasses of Stmt will require
colocating all substatements (subexpressions) in an array. This is because
we define child_iterator as Stmt**. All accessor methods to subexpressions
will need to be altered to reflect this new implementation.
This patch includes the typedefs for child_iterator, as well the implementation
for child_begin/child_end for the primary expressions and some postfix
expressions.
llvm-svn: 41363
Now we emit the following when -pedantic-errors is enabled...
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang complex.c -pedantic-errors
complex.c:4:3: error: ISO C does not support '++'/'--' on complex integer types
++x;
^ ~
complex.c:9:7: error: ISO C does not support '~' for complex conjugation
X = ~Y;
^
complex.c:10:7: error: ISO C does not support '~' for complex conjugation
x = ~y;
^
llvm-svn: 41362
block (because we are creating a CFG from an incomplete AST) we now
(gracefully) have a block ending with such statements not have any successors
instead of firing an assertion.
llvm-svn: 41327
Added explicit "Exit" CFGBlock pointer to the source-level CFG.
Changed the construction of blocks with "return" statements to have the
return statement appear both as a statement in the list of statements for
a CFGBlock as well as appear as a control-flow terminator. Also removed
the implicit linearization of "return" so that the return value and the
return statement did not appear as separate statements in the block.
llvm-svn: 41323
where break targets weren't being set and restored properly. Also
cleaned up CFGBuilder code for "for" and "while" to use less reliance
on globals and to have clearer semantics.
llvm-svn: 41302
Adjusted printing of source-level CFGs to account that the entry block
may not be the first block in the list of blocks a CFG object maintains.
llvm-svn: 41294
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.
llvm-svn: 41281
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).
llvm-svn: 41275
Added builder code to translate ASTs to CFGs. This currently supports
if, return, and non-control flow statements.
Added pretty-printer to debug CFGs.
Added a "-dump-cfg" option to the clang driver to dump CFGs for code
sent through the frontend.
llvm-svn: 41252
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.
llvm-svn: 41217
Next step, refactor Parser::ParseStructUnionBody() so that struct declarations can
be shared with Objective-C (for declaring instance variables).
llvm-svn: 41200
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.
llvm-svn: 41180
"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.
llvm-svn: 41141
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.
llvm-svn: 41127
"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.
llvm-svn: 41113
canonicalized queries of a variable's storage:
hasAutoStorage - Does a variable have (implicit) auto storage?
hasStaticStorage - Does a variable have (implicit) static storage?
hasLocalStorage - Is the variable a non-static local variable?
hasGlobalStorage - Is the variable a global variable or a static
local variable?
Additional comments documenting these functions are included in the
source.
llvm-svn: 41092
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.
Test cases are included.
llvm-svn: 41076
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.
llvm-svn: 41014
"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."
llvm-svn: 41003
preprocessor state, causing bogus diagnostics when the file is parsed for real. This
implements Misc/diag-checker.c. Thanks to Ted for noticing this.
llvm-svn: 41000
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))))))
llvm-svn: 40956
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))))))
llvm-svn: 40954
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...
llvm-svn: 40930
to Sema::ParseParamDeclarator(). After discussing this with Chris, we decided this
approach has more immediate benefit (though we loose some information in the AST).
The comment below should describe more (if interested).
llvm-svn: 40907
[dylan:clang/test/Parser] admin% ../../../../Debug/bin/clang -parse-ast-check typeof.c
Warnings expected but not seen:
Line 21: incompatible types assigning 'typeof(*pi) const' to 'int *'
Warnings seen but not expected:
Line 21: incompatible types assigning 'typeof(*pi) const' to 'int *'
Also corrected a typo from my previous commit.
llvm-svn: 40832
This resulted in the following error...
[dylan:clang/test/Parser] admin% cat parmvardecl_conversion.c
// RUN: clang -parse-ast-check %s
void f (int p[]) { p++; }
[dylan:clang/test/Parser] admin% clang -parse-ast-check parmvardecl_conversion.c
Errors seen but not expected:
Line 3: cannot modify value of type 'int []'
With this fix, the test case above succeeds.
llvm-svn: 40831
Chris suggested this, since it simplifies the code generator.
If this features is needed (and we don't think it is), we can revisit.
The following test case now produces an error.
[dylan:~/llvm/tools/clang] admin% cat t.c
typedef __attribute__(( ocu_vector_type(4) )) float float4;
static void test() {
float4 vec4;
vec4.rg.g;
vec4.rg[1];
}
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang t.c
t.c:8:12: error: vector component access limited to variables
vec4.rg.g;
^~
t.c:9:12: error: vector component access limited to variables
vec4.rg[1];
^~~
2 diagnostics generated.
llvm-svn: 40795
This test case currently generates the following unexpected warnings (when compared with gcc).
[dylan:clang/test/Parser] admin% ../../../../Debug/bin/clang -parse-ast-check builtin_types_compatible.c
Warnings seen but not expected:
Line 28: expression result unused
Line 29: expression result unused
Line 30: expression result unused
Line 31: expression result unused
Line 32: expression result unused
Line 33: expression result unused
llvm-svn: 40789