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
For example, before this commit, the following diagnostics would be emitted...
ocu.c:49:12: error: incompatible types assigning 'float __attribute__((ocu_vector_type(3)))' to 'float4'
vec4_2 = vec4.rgb; // shorten
~~~~~~ ^ ~~~~~~~~
ocu.c:51:7: error: incompatible types assigning 'float __attribute__((ocu_vector_type(2)))' to 'float'
f = vec2.xx; // shorten
~ ^ ~~~~~~~
Now, the diagnostics look as you would expect...
ocu.c:49:12: error: incompatible types assigning 'float3' to 'float4'
vec4_2 = vec4.rgb; // shorten
~~~~~~ ^ ~~~~~~~~
ocu.c:51:7: error: incompatible types assigning 'float2' to 'float'
f = vec2.xx; // shorten
~ ^ ~~~~~~~
llvm-svn: 40579
1. Fix a todo in Parser::ParseTag, to recover better. On code like
that in test/Sema/decl-invalid.c it causes us to return a single
error instead of multiple.
2. Fix an error in Sema::ParseDeclarator, where it would crash if the
declarator didn't have an identifier. Instead, diagnose the problem.
3. Start adding infrastructure to track the range of locations covered
by a declspec or declarator. This is mostly implemented for declspec,
but could be improved, it is missing for declarator.
Thanks to Neil for pointing out this crash.
llvm-svn: 40482
- added ocu_vector_type attribute, Sema::HandleOCUVectorTypeAttribute().
- added new AST node, OCUVectorType, a subclass of VectorType.
- added ASTContext::getOCUVectorType.
- changed ASTContext::convertToVectorType() to ASTContext::getVectorType(). This is
unrelated to extended vectors, however I was in the vicinity and it was on my todo list.
Added a FIXME to Sema::HandleVectorTypeAttribute to deal with converting complex types.
llvm-svn: 40007
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
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
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
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
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
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
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
Submitted by:
Reviewed by:
Added "global" statistics gathering for Decls/Stmts/Exprs.
Very useful for working with a single file. When we start compiling
multiple files, will need to enhance this to collect stats on a per-module
basis.
llvm-svn: 39485
Submitted by:
Reviewed by:
Extended Expr's constant expression predicates to return a source location
if the predicate returns false. This enables us to position the cursor
exactly were the error occurred (simple pleasures:-).
constant.c:9:9: error: enumerator value for 'E2' is not an integer constant
E2 = (aconst + 1), // illegal
^
constant.c:10:8: error: enumerator value for 'E3' is not an integer constant
E3 = "abc",
^
constant.c:12:12: error: enumerator value for 'E5' is not an integer constant
E5 = 0?7:printf("xx"), // illegal
^
constant.c:13:12: error: enumerator value for 'E6' is not an integer constant
E6 = 1?7:printf("xx"), // legal
^
constant.c:16:14: error: enumerator value for 'E9' is not an integer constant
E9 = E0 || a, // illegal
^
constant.c:21:6: error: array has incomplete element type 'void'
void ary[7];
^
constant.c:22:28: error: variable length array declared outside of any function
struct { int a; } ary2[1?7:printf("xx")],
^
constant.c:23:34: error: variable length array declared outside of any function
aryIllegal[0?7:printf("yy")];
^
constant.c:25:10: error: variable length array declared outside of any function
int ary3[a]; // illegal
^
constant.c:26:17: error: size of array has non-integer type 'float'
typedef int vla[2.0]; // illegal
^
constant.c:30:22: error: size of array has non-integer type 'float'
int nonIntegerArray2[1+2.0];
^
llvm-svn: 39454
Submitted by:
Reviewed by:
- Added Sema::isConstantArrayType() and Type::isConstantSizeType().
- Implemented type checking for "variably modified" types (i.e. VLA's).
Added checking for file scope variables, static variables, member variables,
and typedefs.
- Changed Expr::isIntegerConstantExpr() to non-virtual implementation.
Fixed bug with sizeof/alignof. Looking at the diff, I may need to
add a check to exclude alignof.
- Added Expr::isConstantExpr()...non-virtual, like above.
- Added typechecking for case statements (found a bug with actions/parsing...).
- Added several diagnostics.
- Fixed several comments.
Started implemented constant expression checking for arrays.
llvm-svn: 39437
Submitted by:
Reviewed by:
Start work on typechecking constant expressions.
- Added isIntegerConstantExpr() predicate to all exprs.
- Use the predicate to implement checking for enum constant initializers.
- Added diagnostic.
- Added Init slot to EnumConstantDecl class/constructor.
llvm-svn: 39436
Submitted by:
Reviewed by:
-Changed the name of TypeRef to QualType. Many diffs.
-Changed the QualType constructor to require Quals be passed. This makes the code a bit
more verbose, however will make the code easier to work on. Given the complexity
of types, this should help spot bogosities.
-Changed the Expr constructor to require a QualType. Same motivation.
llvm-svn: 39395
Submitted by:
Reviewed by:
Fix "FIXME: does this lose qualifiers from the typedef??" in ASTContext::getTypedefType().
This change was fairly pervasive...nevertheless, here are the highlights:
- Change the type of Type::CanonicalType to TypeRef (was "Type *").
- Change the implementation of TypeRef::getCanonicalType() to work for typedefs.
- Make the implementation of Type::getCanonicalType private (only TypeRef should access). This
will force clients to use TypeRef::getCanonicalType (the correct version of the function). Since
TypeRef overloads "->", it was very easy to fall into this bug...
- Changed many references of "Type *" to "TypeRef"...when the raw type pointer is required, use t.getTypePtr().
- Changed all the *Type classes to take a TypeRef.
- Made the Type constructor protected (cleanup).
- Removed function Expr::getType().
- Convert functions in SemaExpr to use the above support. This fixed the "const" bug I was originally investigating.
I will follow this check-in up with a rename of TypeRef->QualType. I will also make sure the constructor does not default to 0 (which can lead to broken code...).
llvm-svn: 39394
Submitted by:
Reviewed by:
- Typechecking for ++/-- not operating on canonical type (fixed).
- Many changes to Decl.h...
-- Changed ObjectDecl->ValueDecl.
-- ValueDecl doesn't define a storage class. The storage class is now
defined by VarDecl/FunctionDecl. EnumConstant decls don't need a storage class.
-- FieldDecl now inherits directly from Decl (it is not a value).
- Changed SemaExpr to use the new Decl.h. Also added a couple diagnostics for
bogus storage class usage. For example:
z.c:6:10: error: illegal storage class on function
auto int func();
^
z.c:7:14: error: illegal storage class on file-scoped variable
register int b;
^
llvm-svn: 39379
Submitted by:
Reviewed by:
Add three new classes to Decl.h: BlockVarDecl, FileVarDecl, and ParmVarDecl.
Made the constructor to VarDecl protected, to indicate it is "abstract".
Reorganized the Decl::Kind enum to allow us to add ObjectDecls/TypeDecls with
minimal breakage. In the process, realized the isa support for ObjectDecl was already broken (so
the reorg paid for itself already:-) The range check should also be more efficient...
llvm-svn: 39373
Submitted by:
Reviewed by:
- Finished up incomplete type analysis for varibles (in Sema::ParseDeclarator()).
- Added many spec refs, since this area is confusing (for top level decls
in particular).
- Added a FIXME to MergeVarDecl()...it needs to be taught about tentative
definitions. As a result, we currently issue some bogus diagnostics.
llvm-svn: 39372
Submitted by:
Reviewed by:
- ParseMemberReferenceExpr wasn't operating on the canonical type. From
now on, I will make sure the prologue to each Parse/Check function has
both the qualified type and the canonical type.
- More refinements to ParseDeclarator. It was allowing variable declarations
to incomplete types (e.g. void, struct foo, where foo wasn't defined).
llvm-svn: 39371
Submitted by:
Reviewed by:
Finish up Sema::ParseMemberReferenceExpr. This involved:
- added a getMember() function to RecordDecl.
- added stronger typing for "Members" (from Decl->FieldDecl).
- added a dignostic for members not found.
- changed MemberExpr to install the correct TypeRef.
- In general, simplified and cleaned up the routing.
llvm-svn: 39364
Submitted by:
Reviewed by:
Implement type checking. First round of changes are:
- Added predicates to Type.
- Added predicates to BinExpr.
- Added Check hooks that model the categories for Binary ops.
- Added TypeRef to Expr. Will lazily eval subclasses...
- Misc bug fixes/cleanups.
llvm-svn: 39360
Submitted by:
Reviewed by:
carbon.h looking good! Only 1 warning left...no parse errors!
This fixes 3 bugs...
- A couple tricky bugs with type canonicalization. Nested typedef's weren't being
handled properly. For example, the following didn't work:
typdef int __darwin_pid_t;
typedef __darwin_pid_t pid_t;
int getpgid(pid_t);
int getpgid(int);
- The storage class wasn't being preserved. As a result, Sema was complaining
about the following:
extern char *foo;
char *foo;
- various built-ins weren't registered...resulting in spurious warnings.
llvm-svn: 39357
of source code. For example:
$ clang INPUTS/carbon_h.c -arch i386 -arch ppc
prints:
...
/usr/lib/gcc/i686-apple-darwin8/4.0.1/include/mmintrin.h:51:3: note: use of a target-specific builtin function, source is not 'portable'
__builtin_ia32_emms ();
^
because carbon.h pulls in xmmintrin.h, and __builtin_ia32_emms isn't a builtin on ppc.
Though clang now supports target-specific builtins, the full table isn't implemented yet.
llvm-svn: 39328
whose decl objects are lazily created the first time they are referenced.
Builtin functions are described by the clang/AST/Builtins.def file, which
makes it easy to add new ones.
This is missing two important pieces:
1. Support for the rest of the gcc builtins.
2. Support for target-specific builtins (e.g. __builtin_ia32_emms).
Just adding this builtins reduces the number of implicit function definitions
by 6, reducing the # diagnostics from 550 to 544 when parsing carbon.h.
I need to add all the i386-specific ones to eliminate several hundred more.
ugh.
llvm-svn: 39327
translation-unit scope, so we only warn about each implicitly defined
function once. This cuts the number of errors parsing carbon.h from 616 to 550.
llvm-svn: 39325
struct q { int a, a; };
with:
t.c:3:19: error: duplicate member 'a'
struct q { int a, a; };
^
t.c:3:16: error: previous definition is here
struct q { int a, a; };
^
llvm-svn: 39303
This emits these diagnostics:
t.c:4:14: error: redefinition of 'a'
enum foo22 { a, b };
^
t.c:3:5: error: previous definition is here
int a;
^
t.c:8:17: error: redefinition of enumerator 'b'
enum foo23 { c, b };
^
t.c:4:17: error: previous definition is here
enum foo22 { a, b };
^
4 diagnostics generated.
for:
int a;
enum foo22 { a, b };
enum foo23 { c, b };
llvm-svn: 39302
t.c:10:15: warning: 'bonk' may not be nested in a struct due to flexible array member
struct bink bonk;
^
t.c:13:14: error: 'struct bink' may not be used as an array element due to flexible array member
struct bink A[123];
^
for:
struct bink {
struct bink *a;
int X[]; // ok.
};
struct foo {
int A;
struct bink bonk;
};
struct bink A[123];
llvm-svn: 39296
struct bork {
int X[];
};
struct bink {
struct bink a;
int X[]; // ok.
};
to:
t.c:3:7: error: flexible array 'X' not allowed in otherwise empty struct
int X[];
^
t.c:7:15: error: field 'a' has incomplete type
struct bink a;
^
llvm-svn: 39295
like:
struct S { struct S {} X; };
with:
t.c:2:19: error: nested redefinition of 'struct'
struct S { struct S {} X; };
^
t.c:2:1: error: previous definition is here
struct S { struct S {} X; };
^
llvm-svn: 39292
struct blah * P;
union blah *P2;
we now emit:
t.c:2:1: error: redefinition of 'blah' with tag that does not match previous use
union blah *P2;
^
t.c:1:8: error: previous use is here
struct blah * P;
^
llvm-svn: 39275
Detect and emit errors when names are redefined in the same scope, e.g.
test/Parser/argument_redef.c, which now emits:
argument_redef.c:4:22: error: redefinition of 'A'
int foo(int A) { int A; }
^
argument_redef.c:4:13: error: previous definition is here
int foo(int A) { int A; }
^
llvm-svn: 39257
the info. Also, call Actions.ParseParamDeclaratorType instead of
Actions.ParseDeclarator for parameter type lists: we don't want declaration
objects created when parsing a function declarator, we just want type info.
llvm-svn: 39230
parameters: build an array of ParamInfo structures and pass it to the
declarator for safe keeping (it owns the list).
Next step: actually populate the arg array with useful stuff.
llvm-svn: 39229
fundamentally requires having an AST around, so move all sema to the
AST library. This is the first step, later steps will be needed to
clean up libast.
llvm-svn: 39150