- Fixed a recent regression discovered by Keith Bauer (thanks!).
The fix involved adding (back) two arguments to UsualArithmeticConversions.
Without the reference arguments, no unary conversions were being passed back
to the caller. This had the effect of turning off the UsualUnaryConversions.
- Refactored CheckAssignmentConstraints into 3 functions. CheckAssignmentConstraints,
CheckSingleAssignmentConstraints, and CheckCompoundAssignmentConstraints.
- Changed the argument type of DefaultFunctionArrayConversion from QualType->Expr*&.
- Removed a bunch of casts in routines I was working on (cleanup).
- Fixed the visitor for ImplicitCastExpr (oops).
llvm-svn: 39840
code generator. Source translation tools can simply ignore this node.
- Added a new Expr node, ImplicitCastExpr.
- Changed UsualUnaryConversions/UsualArithmeticConversions to take references
to Expr *'s. This will allow these routines to instantiate the new AST node
and pass it back.
- Changed all clients of UsualUnary/UsualArithmetic (lot's of diff's).
- Changed some names in CheckConditionalOperands. Several variables where
only distinguished by their case (e.g. Cond, cond). Yuck (what was I thinking).
- Removed an old/crufty constructor in CastExpr (cleanup).
This check-in does not actually create the new AST node. I wanted to separate
the mechanical changes from the semantic changes. In addition, I need to
coordinate with Chris, since the semantic change will break the code generator.
llvm-svn: 39814
Both in one patch, and the test case that Chris didn't commit last
time is in there too...
I'll split the patch up if somebody wants it split."
Patch by Keith Bauer.
llvm-svn: 39796
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