summaryrefslogtreecommitdiffstats
path: root/clang/Sema/SemaDecl.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Implement capturing of enum values and chaining of enums together.Chris Lattner2007-06-111-17/+46
| | | | llvm-svn: 39644
* Bug #:Steve Naroff2007-06-111-2/+75
| | | | | | | | | | | | | | | | | | | | | | | | | Submitted by: Reviewed by: Implement semantic analysis for vector_size attribute! We now produce the following diagnostics... [administrators-powerbook59:~/llvm/tools/clang] admin% ../../Debug/bin/clang vector.c vector.c:2:29: error: attribute requires precisely 1 argument typedef int __attribute__(( vector_size )) tVecp; ^ vector.c:7:32: error: attribute requires precisely 1 argument extern int foo __attribute__(( vector_size )); ^ vector.c:8:34: error: attribute requires precisely 1 argument extern float bar __attribute__(( vector_size(16,18) )); ^ vector.c:11:34: error: vector_size requires integer constant (attribute ignored) extern char foo2 __attribute__(( vector_size(16.2) )); ^ ~~~~ vector.c:21:47: error: invalid vector type 'struct s' struct s { int a; } structVar __attribute__(( vector_size(16) )); llvm-svn: 39643
* GCC accepts code like this as an extension:Chris Lattner2007-06-101-1/+1
| | | | | | | | static int seminal(from, to) { } llvm-svn: 39642
* fix a crash parsing spassChris Lattner2007-06-091-1/+1
| | | | llvm-svn: 39637
* add another exampleChris Lattner2007-06-091-0/+3
| | | | llvm-svn: 39634
* Bug #:Steve Naroff2007-06-091-15/+1
| | | | | | | | | | 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
* Finally break down and chain together decls that are defined with common ↵Chris Lattner2007-06-091-19/+47
| | | | | | | | | | | declspecs, 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
* Rename Sema::isConstantArrayType -> VerifyConstantArrayType. Make sure toChris Lattner2007-06-051-22/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* fix two checks that should be integer-constant-exprs not just c-e's.Chris Lattner2007-06-051-1/+1
| | | | llvm-svn: 39583
* Submitted by: Bill WendlingBill Wendling2007-06-021-1/+2
| | | | | | | - Added C99 reference to why "auto" and "register" cannot be used as a storage class specifier for file scoped variable declarations. llvm-svn: 39557
* Modify Expr::isConstantExpr and friends take a pointer to a SourceLoc insteadChris Lattner2007-06-021-2/+2
| | | | | | of one by reference, making it optional. llvm-svn: 39552
* Bug #:Steve Naroff2007-06-011-5/+6
| | | | | | | | | | 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
* Bug #:Steve Naroff2007-06-011-0/+14
| | | | | | | | | | | | | | | 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
* implement full sema support for the GCC address-of-label extension.Chris Lattner2007-05-281-2/+1
| | | | llvm-svn: 39510
* Change GotoStmt's to have a pointer to the LabelStmt instead of a pointer toChris Lattner2007-05-281-0/+24
| | | | | | | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-05-231-1/+1
| | | | | | | | | | | 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
* Bug #:Steve Naroff2007-05-181-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Remove the Sema::Diag helper that takes a type. Convert clients to useChris Lattner2007-05-161-5/+9
| | | | | | the version that takes a string. llvm-svn: 39450
* Bug #:Steve Naroff2007-05-081-1/+47
| | | | | | | | | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-05-071-2/+6
| | | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-04-051-7/+7
| | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-04-051-1/+2
| | | | | | | | | | | | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-04-031-17/+31
| | | | | | | | | | | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-04-021-6/+8
| | | | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-04-011-10/+27
| | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-04-011-7/+18
| | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-03-261-1/+1
| | | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-03-211-4/+11
| | | | | | | | | | | | | 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
* Bug #:Steve Naroff2007-03-161-11/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* switch to using iterators instead of stringmap visitors.Chris Lattner2007-02-111-0/+1
| | | | llvm-svn: 39336
* Add support for target-specific builtins, including detecting nonportabilityChris Lattner2007-01-291-1/+1
| | | | | | | | | | | | | | | | | 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
* Add support for target-independent builtin functions (like __builtin_abs),Chris Lattner2007-01-281-5/+57
| | | | | | | | | | | | | | | | | | 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
* make LookupScopedDecl a method instead of a static functionChris Lattner2007-01-281-11/+14
| | | | llvm-svn: 39326
* When injecting a definition for implicitly defined functions, do so atChris Lattner2007-01-281-4/+8
| | | | | | | 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
* Start doing trivial merging of function prototypes. If we have a functionChris Lattner2007-01-271-2/+6
| | | | | | | proto, then a function body, and they have the same type, don't emit an error. This reduces #errors from 654->616 llvm-svn: 39324
* Add some better diagnostics for things like:Chris Lattner2007-01-271-3/+33
| | | | | | | int foo; int foo(); llvm-svn: 39323
* Refactor conflict handling code, no functionality change.Chris Lattner2007-01-271-19/+71
| | | | llvm-svn: 39322
* Fix test/Parser/argument_qualified.cChris Lattner2007-01-271-1/+3
| | | | llvm-svn: 39316
* adjust to change in SmallSet interfaceChris Lattner2007-01-271-2/+1
| | | | llvm-svn: 39313
* rename some classes, no functionality changes.Chris Lattner2007-01-261-1/+1
| | | | llvm-svn: 39307
* Don't crash if GetTypeForDeclarator can't grok a type.Chris Lattner2007-01-251-9/+16
| | | | llvm-svn: 39304
* Reject:Chris Lattner2007-01-251-1/+20
| | | | | | | | | | | | | | | 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
* Register enumconstantdecls in their appropriate scope and check for conflicts.Chris Lattner2007-01-251-1/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Create EnumConstantDecl objects for each enum value, and fill them intoChris Lattner2007-01-251-4/+27
| | | | | | | the EnumDecl when the enum type is complete. This allows us to detect redefinitions of enums. llvm-svn: 39300
* Add EnumDecl, warn about forward references to enums:Chris Lattner2007-01-251-4/+6
| | | | | | | | t.c:2:6: warning: ISO C forbids forward references to 'enum' types enum foo22* X; ^ llvm-svn: 39299
* Save the member list of a struct/union in the RecordDecl for the struct.Chris Lattner2007-01-251-7/+9
| | | | llvm-svn: 39297
* Enforce the rest of C99 6.7.2.1p2, emitting diagnostics like:Chris Lattner2007-01-251-10/+48
| | | | | | | | | | | | | | | | | | | | | | | | 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
* Compile:Chris Lattner2007-01-241-6/+25
| | | | | | | | | | | | | | | | | | | | | 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
* Enforce C99 6.7.2.1p2:Chris Lattner2007-01-241-2/+24
| | | | | | | | t.c:5:8: error: field 'foo' declared as a function void foo(); ^ llvm-svn: 39294
* create field decl objects for the members of a struct/union. Diagnose codeChris Lattner2007-01-231-7/+55
| | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud