Submitted by:
Reviewed by:
Removed Attr.[h,cpp]...they didn't have any useful content.
When more (GCC) attributes are added, we might want to create a file
of this ilk. For now, it's better to remove them (to eliminate any confusion).
I also update the Xcode project file...
llvm-svn: 39729
Submitted by:
Reviewed by:
Two vector fixes:
- Sema::CheckAssignmentConstraints() needs to compare the canonical type.
- Expr::isLvalue() needs to disallow subscripting into a vector returned by a function. This
follows the rules for struct returns (in C, at least...C++ is another story:-)
Here is an example...
float4 float4_return()
{
float4 xx;
return xx;
}
void add_float4_void_return(float4 *a, float4 *b, float4 *result)
{
float f;
float4_return()[1] = f; // now illegal
}
llvm-svn: 39728
Submitted by:
Reviewed by:
Support the following...
1. Type checking and codegen support for V[i] on vectors. Hacked
Sema::ParseArraySubscriptExpr().
2. Unary bitwise complement ("~") on vectors. Hacked Sema::ParseUnaryOp().
llvm-svn: 39723
typedef float float4 __attribute__((vector_size (16)));
void addFloat4(float4 a, float4 b) {
float4 temp;
}
make sure to add 'temp' to the stmt tree as a declstmt.
llvm-svn: 39722
Submitted by:
Reviewed by:
Typechecking support for vectors...
- Added CheckVectorOperands(). Called from CheckAdditionOperands,
CheckMultiplyDivideOperands, CheckSubstractionOperands, and CheckBitwiseOperands.
- Added diagnostic for converting vector values of different size.
- Modified Type::isArithmeticType to include vectors.
Sould be ready for Chris to add code generation. I will continue testing/refining.
llvm-svn: 39717
Submitted by:
Reviewed by:
Fix a bozo bug in HandleDeclAttribute...only install a new type when appropriate.
Also changed setType/setUnderlyingType to return void.
llvm-svn: 39716
Submitted by:
Reviewed by:
- Finished semantic analysis for vectors, added some diagnostics.
- Added AST for vectors (instantiation, installation into the decl).
- Fixed bug in ParseArraySubscriptExpr()...this crasher was introduced by me
when we added the range support.
- Turned pedantic off by default. Since vectors are gcc extensions, having
pedantic on by default was annoying. Turning it off by default is also
consistent with gcc (but this wasn't my primary motivation).
- Tweaked some comments and diagnostics.
Note: The type checking code is still under construction (for vectors). This
will be my next check-in.
llvm-svn: 39715
Reviewed by: Chris Lattner
- Fix for C++ casting operators failing during parsing. Deriving the C++ cast
expressions from CastExpr was the wrong way to go. Its constructor creates
null QualTypes in one of its constructors. This doesn't work well with how
the C++ casting expression class wanted to do things. Derive just from Expr
instead.
llvm-svn: 39714
For example, for:
int test(short S, long L) {
return S /= L;
}
record that the division is done as a long, even though the result type is
short.
llvm-svn: 39700
- Chris noticed that if there were multiple warnings/errors expected
throughout the file and we were checking only one of them, then it
would go ahead and say that the whole file was okay. Fixed this by
adding a check for the line number as well as the string.
llvm-svn: 39689
Reviewed by: Chris Lattner
- Added a new diagnostic client, TextDiagnosticBuffer. It buffers all
reported diagnostics.
- Use the new diagnostic client to check that expected diagnostics are
actually emitted. The way this is done is to put the expected
diagnostic in a comment on the line you expect it to be emitted for.
Like this:
int X = A; // expected-warning {{blah}}
- Use -parse-ast-check to use this feature.
llvm-svn: 39678
out of the llvm namespace. This makes the clang namespace be a sibling of
llvm instead of being a child.
The good thing about this is that it makes many things unambiguous. The
bad things is that many things in the llvm namespace (notably data structures
like smallvector) now require an llvm:: qualifier. IMO, libsystem and libsupport
should be split out of llvm into their own namespace in the future, which will fix
this issue.
llvm-svn: 39659
Reviewed by: Chris Lattner
- Refactor some code from main() and ProcessInputFile() so that it helps to
decouple the initialization of the Preprocessor object from the
diagnostic client.
llvm-svn: 39657
Submitted by:
Reviewed by:
Fix CheckRelationalOperands/CheckEqualityOperands to deal with null pointer
constants. The new logic also deals (more) correctly for non-pointer/integer
operands.
llvm-svn: 39654
Reviewed by: Chris Lattner
- Created a base class (TextDiagnostics) for all text diagnostic classes.
Moved the "IgnoreDiagnostic" method up there, and created a method that
will format the diagnostic string, replacing %# with the appropriate
string. This is in preparation for adding a text diagnostic checker.
llvm-svn: 39650
Submitted by:
Reviewed by:
Fixed typechecking bugs wrt UsualUnaryConversions. Includes two distinct fixes:
#1: Call UsualUnaryConversions in CheckRelationalOperands/CheckEqualityOperands.
#2: UsualArithmeticConversions arguments are now output parameters. This insures
the implicit conversion is seen by clients (and fixes bugs in CheckAdditionOperands
and CheckSubtractionOperands when doing pointer arithmetic).
~
llvm-svn: 39649
Reviewed by: Chris Lattner
- Added a method "IgnoreDiagnostic" so that the diagnostic client can
tell the diagnostic object that it doesn't want to handle a particular
diagnostic message. In which case, it won't be counted as either a
diagnostic or error.
llvm-svn: 39641
Submitted by:
Reviewed by:
Changed the name of DeclSpec.AddAttribute and Declarator.AddAttribute to
AddAttributes(). Also added some (much needed) comments. While documenting,
realized I could simplify & tighten up Declarator.AddAttributes...
llvm-svn: 39640
Submitted by:
Reviewed by:
Add initialization and memory management for AttributeList.
Added a big FIXME comment for handling expressions (which are currently leaked).
llvm-svn: 39639
2005-10-18-VariableSizedElementCrash.c:5:41: warning: expected ';' at end of declaration list
struct bar {foo f1; int f2:3; int f3:4} *p = (struct bar *) pi;
^
llvm-svn: 39633
Submitted by:
Reviewed by:
Lot's of attribute scaffolding.
Modernized ParseArraySubscriptExpr...call DefaultFunctionArrayConversion (which
simplified the logic considerably) and upgrade Diags to use the range support.
llvm-svn: 39629
Submitted by:
Reviewed by:
Lot's of attribute scaffolding.
Modernized ParseArraySubscriptExpr...call DefaultFunctionArrayConversion (which
simplified the logic considerably) and upgrade Diags to use the range support.
llvm-svn: 39628
like: int X, Y, Z;
This is required for the code gen to get to all of the declarations in a
DeclStmt, and should simplify some other code.
llvm-svn: 39623
Reviewed by: Chris Lattner
- Make the counting of errors and diagnostic messages sane. Place them into the
Diagnostic class instead of in the DiagnosticClient class.
llvm-svn: 39615
diag.c:1:9: error: invalid digit '8' in octal constant
int x = 000080;
^
diag.c:2:9: error: invalid digit 'A' in decimal constant
int z = 1000080ABC;
^
instead of:
diag.c:1:9: error: invalid suffix '80' on integer constant
int x = 000080;
^
diag.c:2:9: error: invalid suffix 'ABC' on integer constant
int z = 1000080ABC;
^
llvm-svn: 39605
Reviewed by: Chris Lattner
- Separated out the diagnostic client from the clang driver. This is in
preparation for creating a diagnostic client that will be used to check
error and warning messages.
llvm-svn: 39603
Submitted by:
Reviewed by:
Fixed a bug in the parser's handling of attributes on pointer declarators.
For example, the following code was producing a syntax error...
int *__attribute(()) foo;
attrib.c:10:25: error: expected identifier or '('
int *__attribute(()) foo;
^
Changed Parser::ParseTypeQualifierListOpt to not consume the token following
an attribute declaration.
Also added LexerToken::getName() convenience method...useful when tracking
down errors like this.
llvm-svn: 39602
Submitted by:
Reviewed by:
The following code illustrates a bug in the semantic analysis for assignments:
int func() {
int *P;
char *x;
P = x; // type of this assignment expression should be "int *", NOT "char *".
}
While the type checking/diagnostics are correct, the type of the assignment
expression is incorrect (which shows up during code gen). With the fix,
the llvm code looks correct...
[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang cast.c -emit-llvm
cast.c:4:5: warning: incompatible pointer types assigning 'char *' to 'int *'
P = x; // type of assignment expression is "int *", NOT "char *".
~ ^ ~
; ModuleID = 'foo'
define i32 @func() {
entry:
%P = alloca i32* ; <i32**> [#uses=1]
%x = alloca i8* ; <i8**> [#uses=1]
%allocapt = bitcast i32 undef to i32 ; <i32> [#uses=0]
%tmp = load i8** %x ; <i8*> [#uses=1]
%conv = bitcast i8* %tmp to i32* ; <i32*> [#uses=1]
store i32* %conv, i32** %P
ret i32 undef
}
Even though the fix was simple, I decided to rename/refactor the surrounding code
to make a clearer distinction between constraint checking and conversion.
- Renamed AssignmentConversionResult -> AssignmentCheckResult.
- Renamed UsualAssignmentConversions -> CheckAssignmentConstraints.
- Changed the return type of CheckAssignmentConstraints and CheckPointerTypesForAssignment
from QualType -> AssignmentCheckResult. These routines no longer take a reference to the result (obviously).
- Changed CheckAssignmentOperands to return the correct type (with spec annotations).
llvm-svn: 39601
after the expr along with the expr. If we don't do this, the semicolon
gets parsed as a nullstmt, which makes the generated AST very strange.
llvm-svn: 39600
int *P2;
P2(1, 2, 3);
register short X;
X();
emit:
ds.c:10:3: error: called object is not a function or function pointer
P2(1, 2, 3);
^~~~~~~~~~~
ds.c:13:3: error: called object is not a function or function pointer
X();
^~~
instead of aborting.
llvm-svn: 39599
check canonical types in a few places. Tighten up VerifyConstantArrayType
to diagnose more errors, now that we can evaluate i-c-e's. Add some fixmes
about poor diagnostics.
We now correctly typecheck this example:
void s(void) {
typedef int a[(int) +1.0];
static a b; // invalid, static VLA
static int c[(int) +1.0]; // invalid, static VLA
}
void t(void) {
typedef int a[(int)1.0];
static a b; // valid, constant size
}
void u() {
static int X[-1];
static int Y[0];
}
producing:
static-vla.c:3:12: error: variable length array declared outside of any function
static a b; // invalid, static VLA
^
static-vla.c:5:14: error: variable length array declared outside of any function
static int c[(int) +1.0]; // invalid, static VLA
^ ~~~~~~~~~~
static-vla.c:15:14: error: array size is negative
static int X[-1];
^ ~~
static-vla.c:16:14: warning: zero size arrays are an extension
static int Y[0];
^ ~
llvm-svn: 39587
1. Compute and return the value of the i-c-e if the expression is one.
2. Use this computation to correctly track whether subexprs are being
evaluated, and use this to guide diagnostics appropriately.
This allows us to correctly handle all the cases in:
void bar() {
int foo();
switch (1) {
case 1 ? 0 : foo(): // bad
case 0 ? 0 : foo(): // bad
case 0 ? 1/0 : 14 : // ok
case 1 ? 1/0 : 14 : // bad
;
}
switch (1) {
case 1 ? 2: (2, 3): // ok
case 0 ? 2: (2, 3): // invalid comma.
;
}
}
This code has numerous todo items. Specifically, we need to:
1. Pass in target info, so we know the size of the integers we are producing.
2. Model type sizes and alignments correctly, so we can eval sizeof/alignof
3. Handle promotions (need to talk to steve about this).
4. Return an enum that can be used to better diagnose problems with i-c-e's.
instead of just saying "this isn't valid" we should be able to say why.
5. Various other miscellanea, like handling enums and character literals
properly.
llvm-svn: 39585
Submitted by:
Reviewed by:
Fixed an "impurity" in the typechecking code (to more closely model the
C99 spec)...
- Added function Sema::DefaultFunctionArrayConversion(). This is called
by UsualUnaryConversions(). It is also called from several contexts that
don't call for integer promotions (logical negation for expressions, and
while/if/do/for conditions in statements). It is also used in
UsualAssignmentConversions (which is cleaner than the check I was using
before).
- Changed the name from UsualUnaryConversion->UsualUnaryConversions.
- Added comments to the header.
Since several contexts don't call for integer
promotions,
llvm-svn: 39581
Submitted by:
Reviewed by:
Apply UsualUnaryConversion() to statement conditions that expect scalars.
UsualUnaryConversion() converts function/arrays to pointers.
This fixes the following...
int func() {
int A[10];
while (A) {
}
if (A) ;
for (; A; ) ;
}
llvm-svn: 39580
'char', which varies based on the target.
Instead of spreading target knowledge throughout the compiler, bifurcate char
into Char_S and Char_U, and have ASTContext create the right one based on the
target, when it starts up.
llvm-svn: 39577
ints to long long etc. For int to longlong, we now get:
%tmp = load i64* %F ; <i64> [#uses=1]
%tmp1 = load i32* %D ; <i32> [#uses=1]
%promote = sext i32 %tmp1 to i64 ; <i64> [#uses=1]
%tmp2 = add i64 %tmp, %promote ; <i64> [#uses=0]
llvm-svn: 39576
Reviewed by: Chris Lattner
- Added a method to determine if two types, where at least one is a
reference, are compatible. That is you can assign the RHS to the LHS.
llvm-svn: 39566
Submitted by:
Reviewed by:
After speaking with Chris, decided not to have GCC "attributes" inherit
from Decl. This will enable us to grow the attribute hierarchy over time
without effecting Decls.
llvm-svn: 39543
Submitted by:
Reviewed by:
Implement support for GCC __attribute__.
- Implement "TODO" in Parser::ParseAttributes. Changed the return type from
void to Parser::DeclTy. Changed all call sites to accept the return value.
- Added Action::ParseAttribute and Sema::ParseAttribute to return an
appropriate AST node. Added new node AttributeDecl to Decl.h.
Still to do...hook up to the Decl...
llvm-svn: 39539
Submitted by:
Reviewed by:
- ParseForStatement(): Put back a test/assignment. My removal of
ParseExprStmt() was a bit over zealous:-(thanks to Chris for pointing it out)
- Add assert to VisitDeclStmt().
- Removed an out-of-date FIXME
- Added some curlies for a couple multi-line calls to Diag().
llvm-svn: 39528
Submitted by:
Reviewed by:
- Many tweaks to various diagnostics.
- Fixed some location/range issues.
- Bug fix to Sema::ParseDeclStmt() - error return code is "true", not 0.
llvm-svn: 39526
Submitted by:
Reviewed by:
Unified the diagnostics for function calls. Since we have range support,
there is no need for including the argument number. Instead, I've made
the diags more expressive by including more type info.
Also improved the indentation of many calls to Diag (which can be 2-3
lines now).
llvm-svn: 39523
Submitted by:
Reviewed by:
Implement some FIXME's that stand in the way of fully typechecking "for"
statements. This involved:
- Adding a DeclStmt AST node (with statement visitor). The DeclStmt
printer is preliminary.
- Added a ParseDeclStmt action, called from Parser::ParseForStatement()
and Parser::ParseStatementOrDeclaration(). DID NOT add to
Parser::ParseIdentifierStatement()...probably could have, however didn't
really understand the context of this rule (will speak with Chris).
- Removed ParseExprStmt (and it's clients)...it was vestigial.
llvm-svn: 39518
Submitted by:
Reviewed by:
- Finished Sema::ParseReturnStmt(). Still need to tweak ranges.
- Tweaked location for function arguments (they now point at the expression directly, no parens or commas).
- Added InvalidOperands helper...was sick of looking at the same 3 lines in ~9 Check functions.
- Added a few diags and moved a group of statement diags to the proper comment/category.
llvm-svn: 39517
extern int pintFunc(int *, int *);
int test() {
pintFunc(0,
3);
}
We now print:
t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
pintFunc(0,
~~~~~~~~ ^
instead of:
t3.c:4:13: warning: passing argument 2 makes pointer from integer without a cast
pintFunc(0,
~~~~~~~~
llvm-svn: 39516
Submitted by:
Reviewed by:
Implement type checking for ParseDoStmt, ParseWhileStmt, ParseIfStmt, and
ParseForStmt. ParseForStmt still under construction (contains a FIXME).
llvm-svn: 39515
Submitted by:
Reviewed by:
Refine Sema::ParseCallExpr() diags (range support, add types).
Before:
func-assign.c:27:11: warning: passing argument 1 from incompatible pointer type
pintFunc(&FOO);
^
func-assign.c:28:12: error: incompatible type for argument 1
floatFunc(&FOO);
^
func-assign.c:29:12: error: too many arguments to function
floatFunc(1,2,3);
^
After:
func-assign.c:27:11: warning: passing incompatible pointer 'struct foo *' to function expecting 'int *'
pintFunc(&FOO);
~~~~~~~~^~~~~
func-assign.c:28:12: error: passing incompatible type 'struct foo *' to function expecting 'float'
floatFunc(&FOO);
~~~~~~~~~^~~~~
func-assign.c:29:12: error: too many arguments to function
floatFunc(1,2,3);
~~~~~~~~~^ ~
llvm-svn: 39513
the label identifier. Handle fwd references etc. This allows us to detect
uses of undefined labels and label redefinitions, such as:
t.c:2:12: error: redefinition of label 'abc'
abc: ; abc:
^
t.c:2:3: error: previous definition is here
abc: ; abc:
^
t.c:12:12: error: use of undeclared label 'hijl'
goto hijl;
^
llvm-svn: 39509
void foo() {
if (0) break;
abc:
def:
hij:
break;
into:
void foo() {
if ((0)')
;
abc:
def:
hij:
;
instead of dropping the if and labels (due to break not being in a loop).
llvm-svn: 39508
Submitted by:
Reviewed by:
- Added type checking to Sema::ParseReturnStmt (still under construction).
- Improved Expr::isLvalue() and Expr::isModifiableLvalue() to return more
info. Used the info in Sema::CheckAssignmentOperands() to produce more
descriptive diagnostics. Added FIXME to other clients of isLvalue()/etc.
- Added a SourceLocation slot to MemberExpr...changed the implementation
of getSourceRange().
- Added getResultType() helper to FunctionDecl.
- Changed many Diag calls to use the SourceRange support (now that it's
a big hit...we better milk it:-).
llvm-svn: 39501
Submitted by: Bill Wendling
Reviewed by: Steve Naroff
- Steve suggested avoiding the dyn_cast by using the "Tagged" type class
and having the "default" just return false.
llvm-svn: 39499
Submitted by: Bill Wendling
Reviewed by: Chris Lattner
- Rework the isDerivedType method so that if a language doesn't support
references, it won't have to pay the price for them. This inlines the
checks for derived types and turns it into a switch statement instead.
llvm-svn: 39498
Submitted by: Bill Wendling
Reviewed by: Chris Lattner
- Initial support for C++ references. Adding to the AST and Parser.
Skeletal support added in the semantic analysis portion. Full semantic
analysis is to be done soon.
llvm-svn: 39496