Commit Graph

816 Commits

Author SHA1 Message Date
Chris Lattner 8beb9dee0e Fix a crash on test/Sema/invalid-decl.c
llvm-svn: 43188
2007-10-19 20:10:30 +00:00
Steve Naroff 684dc4107f Fix the previous (short lived:-) FIXME.
I didn't realize that GCC considers this a hard error (I thought it was built-in).

Since it's not, we should simply emit an error.

[dylan:~/llvm/tools/clang] admin% cc -c trivial.m
trivial.m:6: error: cannot find interface declaration for 'NSConstantString'

[administrators-powerbook59:~/llvm/tools/clang] admin% ../../Debug/bin/clang trivial.m 
trivial.m:6:16: error: cannot find interface declaration for 'NSConstantString'
NSString *s = @"123";
               ^
1 diagnostic generated.

llvm-svn: 43157
2007-10-18 23:53:51 +00:00
Fariborz Jahanian e183a8259d Check for Nullness of value built in GetObjcProtoType.
llvm-svn: 43155
2007-10-18 22:59:23 +00:00
Steve Naroff eee59ebb15 Add a FIXME to an assert.
Change a dyn_cast_or_null back to cast (which is more efficient).

llvm-svn: 43152
2007-10-18 22:17:45 +00:00
Fariborz Jahanian c34409c281 Patch to rewrite ivar tables metadata for classes defined.
llvm-svn: 43151
2007-10-18 22:09:03 +00:00
Steve Naroff 1bb21df47f Tweak a recent fix to UsualArithmeticConversions (made by Chris - r43113). The benefit of this tweak is it guarantees the entire routine operates on unqualified types (which I believe is a bit clearer).
llvm-svn: 43142
2007-10-18 18:55:53 +00:00
Steve Naroff a78c464c9e Fix a bug in Sema::CheckConditionalOperands(). When mixing pointers and null pointer constants, we need to promote the null pointer constant (which is an integer) to the pointer type. Test case is self explanatory.
This surfaced yesterday, when compiling test/Sema/cocoa.m on Leopard. Since this has nothing to do with ObjC, it's kind of bizarre this hasn't shown up before. I imagine Cocoa.h on Leopard may have changed recently? 

Thanks to Ted for localizing the bug and giving me a useful AST dump...

llvm-svn: 43114
2007-10-18 05:13:08 +00:00
Chris Lattner fac7ac4130 UsualArithmeticConversions is crashing with an assert
when comparing "float" and "const float".  This "fixes" the
issue, but may not be the right fix.  Steve, please review.

Testcase here: test/Sema/usual-float.c

llvm-svn: 43113
2007-10-18 03:50:33 +00:00
Steve Naroff 8569d77349 Fix the following bug...
unsigned char asso_values[] = { 34 };
int legal2() { 
  return asso_values[0]; 
}

The code that creates the new constant array type was operating on the original type.

As a result, the constant type being generated was "unsigned char [1][]" (which is wrong).

The fix is to operate on the element type - in this case, the correct type is "unsigned char [1]"

I added this case to array-init.c, which clearly didn't catch this bogosity...

llvm-svn: 43112
2007-10-18 03:27:23 +00:00
Fariborz Jahanian a32aaefadc Implementation of AST for @protocol expression.
llvm-svn: 43075
2007-10-17 16:58:11 +00:00
Anders Carlsson f94cd1ffe6 Generate code for static variables that don't have initializers. Also, report an error if a static initializer is not constant.
llvm-svn: 43058
2007-10-17 00:52:43 +00:00
Fariborz Jahanian 6bd1d612ac Fix location processing of @selector: the range should include the @ sign.
llvm-svn: 43051
2007-10-16 23:21:02 +00:00
Steve Naroff 077c83bddb Add Sema::CheckMessageArgumentTypes()...
llvm-svn: 43050
2007-10-16 23:12:48 +00:00
Chris Lattner 37390bed4d Fix location processing of @encode: the range should include the @ sign.
@selector probably gets this wrong also.

llvm-svn: 43048
2007-10-16 22:51:17 +00:00
Chris Lattner a7c19feca2 Add a new Rewriter::getRangeSize method.
Rename SourceRange::Begin()/End() to getBegin()/getEnd() for
consistency with other code.
Start building the rewriter towards handling @encode.

llvm-svn: 43047
2007-10-16 22:36:42 +00:00
Fariborz Jahanian ebac2cb235 Patch to diagnose duplicate method implementations.
llvm-svn: 43046
2007-10-16 21:52:23 +00:00
Steve Naroff d275426449 Remove ObjcMethodDecl::getNumMethodParams/getMethodParamDecl, they aren't used/needed.
Change ObjcMethodDecl::getMethodType to getResultType, to match FunctionDecl.

llvm-svn: 43045
2007-10-16 21:36:54 +00:00
Fariborz Jahanian 4bef462a3e Patch to implement AST generation for objective-c's @selector expression.
llvm-svn: 43038
2007-10-16 20:40:23 +00:00
Steve Naroff 55f52da24c Emit diagnostics for methods not found.
llvm-svn: 43037
2007-10-16 20:39:36 +00:00
Chris Lattner e6dcd505d0 initialization of references should not do default fn/array promotions.
This fixes a bug Anders noticed.

llvm-svn: 43024
2007-10-16 02:55:40 +00:00
Steve Naroff 698495522d Bad cast...need to use dyn_cast_or_null. Also changed Sema::InitBuiltinVaListType (which had the same bug).
llvm-svn: 43023
2007-10-16 00:00:18 +00:00
Steve Naroff f73b784a5e Change the type of ObjCStringLiteral from "struct __builtin_CFString *" to "NSConstantString *".
This makes the typecheck much happier. Without this change, the type checker would have to special case "struct __builtin_CFString *". This change does assume the interface for NSConstantString is declared in the translation unit.

I left ASTContext::getCFConstantStringType() around for now (with a comment that says it is currently unused).

llvm-svn: 43021
2007-10-15 23:35:17 +00:00
Steve Naroff 32e44c0032 Move type compatibility predicates from Type to ASTContext. In addition, the predicates are now instance methods (they were previously static class methods on Type).
This allowed me to fix the following hack from this weekend...

// FIXME: Devise a way to do this without using strcmp.
// Would like to say..."return getAsStructureType() == IdStructType;", but
// we don't have a pointer to ASTContext.
bool Type::isObjcIdType() const {
  if (const RecordType *RT = getAsStructureType())
    return !strcmp(RT->getDecl()->getName(), "objc_object");
  return false;
}

...which is now...

bool isObjcIdType(QualType T) const {
  return T->getAsStructureType() == IdStructType;
}

Side notes:

- I had to remove a convenience function from the TypesCompatibleExpr class.

int typesAreCompatible() const {return Type::typesAreCompatible(Type1,Type2);}

Which required a couple clients get a little more verbose...

-    Result = TCE->typesAreCompatible();
+    Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2());

Overall, I think this change also makes sense for a couple reasons...

1) Since ASTContext vends types, it makes sense for the type compatibility API to be there.
2) This allows the type compatibility predeciates to refer to data not strictly present in the AST (which I have found problematic on several occasions).

llvm-svn: 43009
2007-10-15 20:41:53 +00:00
Anders Carlsson 7e13ab88a2 Add code generation and sema checking for __builtin_va_arg.
llvm-svn: 43006
2007-10-15 20:28:48 +00:00
Fariborz Jahanian d4b3015dd7 Several name lookup conflict detection fixes involving objective-c names.
llvm-svn: 43000
2007-10-15 19:16:57 +00:00
Steve Naroff 66e9f331ba Added ASTContext::setObjcIdType/getObjcIdType(), set by Sema.
Also noticed ASTContext::BuiltinVaListType wasn't being initialized to the null type (so I set it).

llvm-svn: 42983
2007-10-15 14:41:52 +00:00
Anders Carlsson cbfc4b8824 Add support for Pascal strings.
llvm-svn: 42974
2007-10-15 02:50:23 +00:00
Steve Naroff 5d15254496 - Teach ObjcInterfaceDecl::lookupInstance/ClassMethod to look through protocols.
- Start looking up methods in the global method pools (for "id").
- Start integrating interface types into the type system.

llvm-svn: 42971
2007-10-14 23:13:51 +00:00
Steve Naroff ca0ecfe048 Add category lookup (removing a couple FIXME's).
Changed ObjcInterfaceDecl::ListCategories->CategoryList.

llvm-svn: 42968
2007-10-14 18:27:41 +00:00
Steve Naroff 5811baf1a0 - Added Sema::AddFactoryMethodToGlobalPool and Sema::AddInstanceMethodToGlobalPool and DenseMaps. This will allow us to efficiently lookup a method from a selector given no type information (for the "id" data type).
- Fixed some funky "}
                    else {" indentation in Sema::ActOnAddMethodsToObjcDecl(). I'd prefer we stay away from this style...it wastes space and isn't any easier to read (from my perspective, at least:-)

- Changed Parser::ParseObjCInterfaceDeclList() to only call Action::ActOnAddMethodsToObjcDecl() when it actually has methods to add (since most interface have methods, this is a very minor cleanup).

llvm-svn: 42957
2007-10-14 00:58:41 +00:00
Anders Carlsson 24ebce6fca Generate code for va_start and va_end.
llvm-svn: 42939
2007-10-12 23:56:29 +00:00
Fariborz Jahanian fd0312ed79 Patch to check for duplicate method decls in protocols.
llvm-svn: 42938
2007-10-12 23:43:31 +00:00
Fariborz Jahanian ecfe4f1453 Check and diagnose that objective-c objects may not be statically allocated.
llvm-svn: 42936
2007-10-12 22:10:42 +00:00
Ted Kremenek 41362cea7b Added notion of '*' specified format width/specifiers when checking
printf format strings.  Added type checking to see if the matching
width/precision argument was of type 'int'.

Thanks to Anders Carlsson for reporting this missing feature.

llvm-svn: 42933
2007-10-12 20:51:52 +00:00
Fariborz Jahanian 02fbb68e85 Fixed typo in comment.
llvm-svn: 42928
2007-10-12 19:53:08 +00:00
Fariborz Jahanian c7afeebb12 Fixed a @compatible_alias bug. In the process, discovered unnecessary 2ndry lookup
ok class names and streamlined this logic to do the lookup once.

llvm-svn: 42926
2007-10-12 19:38:20 +00:00
Steve Naroff b915146a5d Replace one FIXME with another. We handle protocols just fine now. The ObjC decl will only be 0 when we have an error on the ObjC decl. I would prefer we pass in a decl that is marked as invalid. I don't think this is critical to fix now, however I'd like us to be consistent. There are currently many places that don't mark the decl as invalid (which need to be fixed)...
llvm-svn: 42923
2007-10-12 18:49:25 +00:00
Anders Carlsson 431ef632cb Add some more diagnostics for va_start, fix tests so they pass with these new diags.
llvm-svn: 42917
2007-10-12 17:48:41 +00:00
Fariborz Jahanian d52cd41630 Fixed a bug whereby, struct tag name matches a typedef/objc-class name
and hid them.

llvm-svn: 42915
2007-10-12 16:34:10 +00:00
Ted Kremenek 6a6c08c319 Printf argument checking now supports dynamically-passed precision
specifiers.

llvm-svn: 42886
2007-10-12 00:11:27 +00:00
Fariborz Jahanian 49c6425ee6 This patch implementa objective-c's @compatibilty-alias declaration.
llvm-svn: 42883
2007-10-11 23:42:27 +00:00
Anders Carlsson 87c149bf51 Add __builtin_va_start to the list of builtins, make __builtin_va_list available to builtin functions.
llvm-svn: 42857
2007-10-11 01:00:40 +00:00
Fariborz Jahanian 70e8f1024a Patch to create protocol conforming class types.
llvm-svn: 42856
2007-10-11 00:55:41 +00:00
Chris Lattner 9c7a0361c0 Fix 80 col violations.
llvm-svn: 42849
2007-10-10 23:42:28 +00:00
Steve Naroff 783a7a0698 Refinements to Sema::GetObjcIdType()...
- Cache the typedef, not the type (avoids importing AST/Type.h).
- Emit an error if "id" cannot be found.
- Comment the routine and add a FIXME to reconsider how we emulate GCC's new fangled behavior. This isn't a priority for now, since almost no code depends on having "id" built-in.
- Add a test.

llvm-svn: 42845
2007-10-10 23:24:43 +00:00
Steve Naroff 7f549f1897 - Make sure default return/argument types (for methods) default to "id".
- Cache the "id" type in Sema...initialize ObjcIdType and TUScope (oops).
- Fix ActOnInstanceMessage to allow for "id" type receivers...still work to do (next).

llvm-svn: 42842
2007-10-10 21:53:07 +00:00
Anders Carlsson db83d77c78 Emit a warning when the body of an if block is a NullStmt.
llvm-svn: 42840
2007-10-10 20:50:11 +00:00
Steve Naroff 93eb5f1438 Remove Scope argument from ObjC actions that either don't need it or can now use TUScope.
Also improve a recently added comment.

llvm-svn: 42826
2007-10-10 17:32:04 +00:00
Chris Lattner 1f1b0dbc28 Make a significant change to invert the control flow handling
predefined macros.  Previously, these were handled by the driver,
now they are handled by the preprocessor.

Some fallout of this:

1. Instead of preprocessing two buffers (the predefines, then the 
   main source file)  we now start preprocessing the main source 
   file and inject the predefines as a "psuedo #include" from the
   main source file.
2. #1 allows us to nuke the Lexer::IsMainFile flag and simplify
   Preprocessor::isInPrimaryFile.
3. The driver doesn't have to know about standard #defines, the
   preprocessor knows, which is nice for people wanting to define
   their own drivers.
4. This allows us to put normal tokens in the predefine buffer,
   for example a definition for __builtin_va_list that is 
   target-specific, and a typedef for id in objc.

llvm-svn: 42818
2007-10-09 22:10:18 +00:00
Steve Naroff c62adb6d1a Make sure methods with no return type default to "id".
This fixes a crasher in Sema::MatchTwoMethodDeclarations(), identified by selector-overload.m (just added).

Added Action::ActOnTranslationUnitScope() and renamed Action::PopScope to ActOnPopScope.

Added a Translation Unit Scope instance variable to Sema (will be very useful to ObjC-related actions, since ObjC declarations are always file-scoped).

llvm-svn: 42817
2007-10-09 22:01:59 +00:00
Fariborz Jahanian c8e7a93b02 Minor code clean up to make it more readable.
llvm-svn: 42803
2007-10-09 18:22:59 +00:00
Chris Lattner 516ca70f5d Update DeclKind enums to reflect ObjcProtocolDecl's inheritance change.
llvm-svn: 42802
2007-10-09 18:18:24 +00:00
Fariborz Jahanian 06f84f5f84 Remove addition of protocol names to declaration scopes, use a separate
DenseMap to keep track of such declarations and derive ObjcProtocolDecl
directyly from NamedScope.

llvm-svn: 42801
2007-10-09 18:03:53 +00:00
Chris Lattner a55a2cc25c rename some "Parse" actions to "ActOn". Move code around in
ParseFunctionDefinition so that ActOnFunctionDefBody is always
called if ActOnStartOfFunctionDef is called.  This fixes a crash
reported by Nuno Lopes.

llvm-svn: 42793
2007-10-09 17:14:05 +00:00
Fariborz Jahanian cb995d8981 Prevent memory leak by not creating a category object when there is a
fatal error of category's undefined interface.

llvm-svn: 42790
2007-10-09 17:05:22 +00:00
Steve Naroff 71c3c1c715 Convert Selector Maps/Sets to use stronger typing (now that we have DenseMapInfo in IdentifierTable.h).
llvm-svn: 42767
2007-10-08 21:05:34 +00:00
Fariborz Jahanian 4b2113c281 Return NULL on invalid protocol.
llvm-svn: 42754
2007-10-08 16:07:03 +00:00
Chris Lattner ef6b136781 move IdentifierTable.h from liblex to libbasic.
llvm-svn: 42730
2007-10-07 08:58:51 +00:00
Chris Lattner 65cc87ffc2 The identifier shouldn't be added to the scope, the decl should.
This fixes strange assertions that just started triggering.

llvm-svn: 42721
2007-10-07 07:05:08 +00:00
Chris Lattner f7f34d09e4 simplify some Selector interfaces.
llvm-svn: 42715
2007-10-07 01:33:16 +00:00
Chris Lattner ee2d84133c move ImplementationClassInfo out of ASTContext into Sema.
llvm-svn: 42714
2007-10-07 01:13:46 +00:00
Chris Lattner 6a2b09ecd9 switch ObjcCategoryImplDecl over to being a NamedDecl, remove dead ctor argument.
llvm-svn: 42711
2007-10-06 23:12:31 +00:00
Chris Lattner a4016555d2 introduce a new NamedDecl class, switch a couple of things over to using it.
NamedDecl is a Decl that has an IdentifierInfo (for example, ScopedDecl), 
but not ObjcMethodDecl.

Simplify some code in ActOnAddMethodsToObjcDecl, by doing the cast from 
DeclTy to Decl at the start of the method.

llvm-svn: 42710
2007-10-06 22:53:46 +00:00
Chris Lattner ae0ec1d09f simplify the interface to create ObjcClassDecl's.
llvm-svn: 42706
2007-10-06 20:08:36 +00:00
Chris Lattner 11eca782a3 simplify the interface for creating ObjcForwardProtocolDecl
llvm-svn: 42705
2007-10-06 20:05:59 +00:00
Fariborz Jahanian ea7a98d8d6 This is the first patch toward supporting protocol conforming
objective-c types. It also removes use of Scope* parameter in
getObjCProtocolDecl.

llvm-svn: 42649
2007-10-05 21:01:53 +00:00
Chris Lattner dadc762ac5 Implement DenseMapInfo for Selector, allowing use of DenseMap/DenseSet of
Selector's instead of requiring void* to be used.  I converted one use of
DenseSet<void*> over to use DenseSet<Selector> but the others should change
as well.

llvm-svn: 42645
2007-10-05 20:15:24 +00:00
Fariborz Jahanian 458f7114db Patch for 1) Checking for duplicate methods decls in intterface and category.
2) Use of the new DenseSet<t> abstractions instead of DenseMap<t,char>.

llvm-svn: 42641
2007-10-05 18:00:57 +00:00
Fariborz Jahanian 9081457cbf this patch accomodates clattner's comments on expression processing in @try-statement.
llvm-svn: 42611
2007-10-04 20:19:06 +00:00
Fariborz Jahanian 673414067b Fixed tabs in couple of sources.
llvm-svn: 42601
2007-10-04 00:45:27 +00:00
Fariborz Jahanian c9cd8a185d Fixed all my recent test cases to have the RUN command and
fixed consequence of these changes in clang.

llvm-svn: 42600
2007-10-04 00:22:33 +00:00
Steve Naroff 4810c3a1d6 Finish renaming ObjC declaration actions.
Add comments.
Switch to new indentation style for the Action class. Since many actions take many arguments, the new style will...
- make it easier to add/remove arguments without messing up the indentation...
- make it easier to add comments to each argument (see ActOnMethodDeclaration for an example)...
- in general, just makes it easier to see what is being passed.

The rest of Actions will be converted "lazily"...there is no immediate need to hack all the existing methods.

llvm-svn: 42587
2007-10-03 21:00:46 +00:00
Fariborz Jahanian 6cc3803f0b Renamed getCatLoc() to getLocation() to be consistant for such
getter names.

llvm-svn: 42577
2007-10-03 16:23:52 +00:00
Steve Naroff 0c37b0cb5a Rename several ObjC action methods to use the "ActOn" prefix (still a few more to do).
Remove Action::ObjCStartCategoryInterface/ObjCFinishInterface - they are unused.
.

llvm-svn: 42559
2007-10-02 22:39:18 +00:00
Fariborz Jahanian b8d9e088a7 Unified such names as protocol references, instance methods and class methods
and their accessors in a variety of objective-c classes.

llvm-svn: 42555
2007-10-02 22:05:16 +00:00
Steve Naroff d174155204 Remove Action::ActOnImpleIvarVsClassIvars(), it is only called by Sema (not Parser).
Add Sema::CheckImplementationIvars() to replace the previous action.

llvm-svn: 42553
2007-10-02 21:43:37 +00:00
Steve Naroff f5a55c5a9f Rename ObjcInterfaceDecl::getIsForwardDecl() to isForwardDecl().
Rename ObjcProtocolDecl::getIsForwardProtoDecl() to isForwardDecl().
Rename ObjcInterfaceDecl::setIsForwardDecl() to setForwardDecl().
Rename ObjcProtocolDecl::setIsForwardProtoDecl() to setForwardDecl().

Two reasons:

#1: boolean predicates should start with "is".
#2: Since these two sets of methods represent the same concept, they should be named the same (polymorphism is good:-)

llvm-svn: 42545
2007-10-02 20:26:23 +00:00
Fariborz Jahanian adf84f3f3c Previously, I warned those methods not implemented in implementation class/category.
Now, I also warn those class/categories which are incomplete because of this.

llvm-svn: 42544
2007-10-02 20:06:01 +00:00
Steve Naroff c6814ea670 - Add ObjcInterfaceDecl::lookupInstanceMethod(), lookupClassMethod().
- Add ObjcMessageExpr::getSelector(), getClassName().
- Change Sema::getObjCInterfaceDecl() to simply take an IdentifierInfo (no Scope needed).
- Remove FIXME for printing ObjCMessageExpr's.

llvm-svn: 42543
2007-10-02 20:01:56 +00:00
Fariborz Jahanian 19d765fa6c ObjcCategoryDecl Does not subclass from ScopedDecl any more.
Ted may want to take a look at the change I made at 
FGRecStmtDeclVisitor.h.

llvm-svn: 42535
2007-10-02 17:36:55 +00:00
Fariborz Jahanian 89b8ef92be This patch introduces the ObjcCategoryImplDecl class and does the checking related to
unimplemented methods in category implementation.

llvm-svn: 42531
2007-10-02 16:38:50 +00:00
Steve Naroff 67391b8a54 Move ObjC decls to DeclObjC.h, a new AST header.
Update clients and add to project file.

llvm-svn: 42494
2007-10-01 19:00:59 +00:00
Fariborz Jahanian f26702eb54 Took care of clatter's suggestions, dated.
September 30, 2007 12:36:58 AM PDT and
September 30, 2007 12:50:05 AM PDT

llvm-svn: 42490
2007-10-01 16:53:59 +00:00
Chris Lattner 6c44b9f145 Fix a bug I just introduced.
llvm-svn: 42479
2007-09-30 08:31:00 +00:00
Chris Lattner 4730430bd8 simplify an expression
llvm-svn: 42477
2007-09-30 08:01:04 +00:00
Fariborz Jahanian 0886d252d7 This patch fixes all issues mentioned in clattner's feedback of
September 28, 2007 4:39:24 PM PDT
Please let me know if I missed anything.

llvm-svn: 42473
2007-09-29 18:24:58 +00:00
Fariborz Jahanian ec7b3333e1 Code clean up. Moved couple of static functions to be private members of Sema class.
Avoiding passing a Sema object to these utility functions.

llvm-svn: 42472
2007-09-29 17:14:55 +00:00
Fariborz Jahanian fa0667b547 Patch to remove use of has table for protocol name lookup. This patch mirrors my
previous patch to do the same for class name lookup using a hash table.

llvm-svn: 42471
2007-09-29 17:04:06 +00:00
Fariborz Jahanian 343f7098db Removed use of hash table for class decls and do a name look up directly.
There is still an issue if doing ScopedLookup is an overkill and we can
just access the decl using the identifier.

llvm-svn: 42463
2007-09-29 00:54:24 +00:00
Steve Naroff 8017506d9c Yesterday I discovered that 78% of all selectors in "Cocoa.h" take 0/1 argument.
This motivated implementing a devious clattner inspired solution:-)

This approach uses a small value "Selector" class to point to an IdentifierInfo for the 0/1 case. For multi-keyword selectors, we instantiate a MultiKeywordSelector object (previously known as SelectorInfo). Now, the incremental cost for selectors is only 24,800 for Cocoa.h! This saves 156,592 bytes, or 86%!! The size reduction is also the result of getting rid of the AST slot, which was not strictly necessary (we will associate a selector with it's method using another table...most likely in Sema).

This change was critical to make now, before we have too many clients.

I still need to add some comments to the Selector class...will likely add later today/tomorrow.

llvm-svn: 42452
2007-09-28 22:22:11 +00:00
Fariborz Jahanian b75db4cc8c Patch to warn on umimplemented methods coming from class's
protocols.

llvm-svn: 42436
2007-09-28 17:40:07 +00:00
Fariborz Jahanian f6546b38b2 Patch for method implementation. It populates ObjcImplementationDecl object with method implementation declarations .
It checks and warns on those methods declared in class interface and not implemented.

llvm-svn: 42412
2007-09-27 18:57:03 +00:00
Chris Lattner cc61bf5e0c Fix some use of uninit variables issues, reported by Anton.
llvm-svn: 42396
2007-09-27 15:15:46 +00:00
Steve Naroff f73590dbb1 Add SelectorInfo (similar in spirit to IdentifierInfo). The key difference is SelectorInfo is not string-oriented, it is a unique aggregate of IdentifierInfo's (using a folding set). SelectorInfo also has a richer API that simplifies the parser/action interface. 3 noteworthy benefits:
#1: It is cleaner. I never "liked" storing keyword selectors (i.e. foo:bar:baz) in the IdentifierTable.

#2: It is more space efficient. Since Cocoa keyword selectors can be quite long, this technique is space saving. For Cocoa.h, pulling the keyword selectors out saves ~180k. The cost of the SelectorInfo data is ~100k. Saves ~80k, or 43%.

#3: It results in many API simplifications. Here are some highlights:

- Removed 3 actions (ActOnKeywordMessage, ActOnUnaryMessage, & one flavor of ObjcBuildMethodDeclaration that was specific to unary messages).
- Removed 3 funky structs from DeclSpec.h (ObjcKeywordMessage, ObjcKeywordDecl, and ObjcKeywordInfo).
- Removed 2 ivars and 2 constructors from ObjCMessageExpr (fyi, this space savings has not been measured).

I am happy with the way it turned out (though it took a bit more hacking than I expected). Given the central role of selectors in ObjC, making sure this is "right" will pay dividends later.

Thanks to Chris for talking this through with me and suggesting this approach. 

llvm-svn: 42395
2007-09-27 14:38:14 +00:00
Fariborz Jahanian 2a4dd316a0 This patch inserts ivars declared in @implementation in its object and verifies
that they conform(in type, name and numbers) to those declared in @interface. 
Test case highlights kind of checking we do here.

llvm-svn: 42360
2007-09-26 18:27:25 +00:00
Fariborz Jahanian e2017c1d1d Patch to make ObjcImplementationDecl derived from TypeDecl and supprt legacy
objective-c code with no @interface declaration.

llvm-svn: 42319
2007-09-25 21:00:20 +00:00
Fariborz Jahanian bfe13c566c This patch introduces a new class to keep track of class implementation info. It also adds more
semantic checks for class and protocol declarations. Test cases are good indications of kind of 
checking being done in this patch.

llvm-svn: 42311
2007-09-25 18:38:09 +00:00
Chris Lattner ec0a6d9be5 Use APFloat for the representation of FP immediates, ask the target
for *which* apfloat to use for a particular type.

llvm-svn: 42234
2007-09-22 18:29:59 +00:00
Fariborz Jahanian 7e5d533098 This patch adds to new things to clang:
1. Handles saving and checking on protocols used in an @interface declaration
2. Checks and saves class's super class.
3. Adds semantic check to category declarations.

llvm-svn: 42218
2007-09-22 00:01:35 +00:00
Chris Lattner 4b2ff02f72 Make case sorting deterministic by not depending on pointer
values.  Patch mostly by Gabor Greif for PR1682.

llvm-svn: 42203
2007-09-21 18:15:22 +00:00
Fariborz Jahanian 876e27dafa This patch instantiates objects for forward protocols and in general handles use of
protocols referenced in @protocol declarations.

llvm-svn: 42191
2007-09-21 15:40:54 +00:00
Fariborz Jahanian 397d8de9ed Handle forward declaration of classes and prevent re-instantiation of
ObjcInterfaceClass Objects.

llvm-svn: 42172
2007-09-20 20:26:44 +00:00
Fariborz Jahanian a8bbc63c1f Match to do some semantic analysis on objective-c class decl.
1. Detect used of undeclared/forward declared super class.
2. Detect duplicate definition of a class.

llvm-svn: 42168
2007-09-20 17:54:07 +00:00
Steve Naroff 2cd263ff71 Remove SelectorTable/SelectorInfo, simply store all selectors in the central IdentifierTable.
Rationale:

We currently have a separate table to unique ObjC selectors. Since I don't need all the instance data in IdentifierInfo, I thought this would save space (and make more sense conceptually).

It turns out the cost of having duplicate entries for unary selectors (i.e. names without colons) outweighs the cost difference between the IdentifierInfo & SelectorInfo structures. Here is the data:

Two tables:

*** Selector/Identifier Stats:
# Selectors/Identifiers: 51635 
Bytes allocated:         1999824

One table:

*** Identifier Table Stats:
# Identifiers:   49500
Bytes allocated: 1990316

llvm-svn: 42139
2007-09-19 16:18:46 +00:00
Steve Naroff 59155be0b2 Remove #include of config.h, it is no longer needed.
llvm-svn: 42126
2007-09-19 03:01:22 +00:00
Steve Naroff 467e619a65 Remove alloca import...
llvm-svn: 42117
2007-09-18 23:56:42 +00:00
Steve Naroff d54978ba8b Progress on message expressions...
- Add ObjcMessageExpr AST node and associated constructors.
- Add SourceLocation's to ActOnKeywordMessage/ActOnUnaryMessage API.
- Instantiate message expressions...
- Replace alloca usage with SmallString.

Next step, installing a correct type, among other tweaks...

llvm-svn: 42116
2007-09-18 23:55:05 +00:00
Fariborz Jahanian 867a7eb5cb Patch for object creation and handling of category declarations.
llvm-svn: 42104
2007-09-18 20:26:58 +00:00
Hartmut Kaiser ae27fdc0f4 alloca.h doesn't exist on Windows.
llvm-svn: 42089
2007-09-18 12:16:59 +00:00
Gabor Greif 56c83140c1 alloca.h is needed on Solaris
llvm-svn: 42088
2007-09-18 11:01:25 +00:00
Fariborz Jahanian 0c74e9d161 Uses more description name for method implementation kind argument.
Moves such argument as the last argument and uses defaul value.

llvm-svn: 42073
2007-09-18 00:25:23 +00:00
Fariborz Jahanian cfacdae9a8 Patch to remove ObjcProtoMethodDecl and use ObjcMethodDecl
instead for @protocol method decls.

llvm-svn: 42070
2007-09-17 22:36:42 +00:00
Fariborz Jahanian 39d641f526 Patch to add objective-c's @protocl type declaration.
llvm-svn: 42060
2007-09-17 21:07:36 +00:00
Steve Naroff f0f2afce5a Finish defining Action API for message expressions.
llvm-svn: 42059
2007-09-17 21:01:15 +00:00
Steve Naroff 486760aee3 - Refactored ObjcKeywordInfo into ObjcKeywordInfo, ObjcKeywordDecl, and ObjcKeywordMessage.
- Removed helper ObjcGetSelectorInfo(), moving the code directly into ObjcBuildMethodDeclaration().
- Many refinements to ParseObjCMessageExpression().
- Add ActOnMessageExpression().

Next step, finish the message actions and (finally) create/instantiate an ObjcMessageExpr AST.

llvm-svn: 42050
2007-09-17 20:25:27 +00:00
Steve Naroff 73d534a2e0 Add support for ObjC keyword selectors.
- Add SelectorInfo/SelectorTable classes, modeled after IdentifierInfo/IdentifierTable.
- Add SelectorTable instance to ASTContext, created lazily through ASTContext::getSelectorInfo().
- Add SelectorInfo slot to ObjcMethodDecl.
- Add helper function to derive a SelectorInfo from ObjcKeywordInfo.

Misc: Got the Decl stats stuff up and running again...it was missing support for ObjC AST's.
llvm-svn: 42023
2007-09-17 14:16:13 +00:00
Chris Lattner 93c7f855e5 remove some obsolete interfaces.
llvm-svn: 42014
2007-09-16 19:47:56 +00:00
Steve Naroff 2f742085f5 Fixes/tweaks that prevent "defaults-i.m" from compiling.
- Allow classnames as the receiver (removing a FIXME from ParseObjCMessageExpression).
- Added a FIXME to ParseObjCMessageExpression()...we need to return a message expr AST node!

llvm-svn: 42001
2007-09-16 16:16:00 +00:00
Steve Naroff 66356bda5d Rename statement actions (from Parse-prefix to ActOn-prefix).
llvm-svn: 42000
2007-09-16 14:56:35 +00:00
Steve Naroff 83895f7888 Rename expression actions (from Parse-prefix to ActOn-prefix).
llvm-svn: 41997
2007-09-16 03:34:24 +00:00
Hartmut Kaiser 0a6b11db24 Updated VC++ build system.
Silenced a couple of VC++ warnings.

llvm-svn: 41994
2007-09-16 00:04:22 +00:00
Chris Lattner 75e0c8cf4c add a new ASTConsumer consumer to simplify stuff in the driver.
Switch -parse-ast over to it.

llvm-svn: 41991
2007-09-15 22:56:56 +00:00
Steve Naroff 30d242c99f Start converting Action methods from Parse-prefix to ActOn-prefix.
The previous naming scheme was confusing, since it resulted in both the Parser and Action modules having methods with the same name. In addition, the Action module never does any parsing...

llvm-svn: 41986
2007-09-15 18:49:24 +00:00
Steve Naroff 2e688fde14 Rename Action::ParseRecordBody() to ProcessFieldDecls(), and add a visibility argument.
Remove Action::ObjcAddVisibilityToIvars(). No need for an extra API when it is trivial to add this info to the previous hook.

In general, I want to start migrating away from having Actions prefixed with "Parse" (which is confusing, since the Action API doesn't do any parsing, per se).

llvm-svn: 41973
2007-09-14 23:09:53 +00:00
Steve Naroff db47ee203a Several improvement to Sema::ParseRecordBody()...
- Adding a safer prologue. The previous prologue would accept a null and therefore assume we had an interface (which was incorrect).
- Fixed FieldDecl's classof method. This allowed me to simplify some unnecessary casting.
- When diagnosing errors, make sure the FieldDecl/EnclosingDecl are marked as invalid. In addition, don't delete the field...rather, add all fields to the enclosing decl. Memory management can/should be done elsewhere. This code was never "upgraded" to the recently added invalid decl strategy.

llvm-svn: 41964
2007-09-14 22:20:54 +00:00
Fariborz Jahanian f3287bf871 Patch to store ivars into interface class object.
llvm-svn: 41961
2007-09-14 21:08:27 +00:00
Fariborz Jahanian aefb23092c Semantic analysis for objective-c ivars.
llvm-svn: 41954
2007-09-14 16:27:55 +00:00
Steve Naroff 1d4b5eaeab Now that the dust has settled on the Decl refactoring, I noticed FieldDecl didn't need NextDeclarator. As a result, I'm removing it.
Removing both slots (NextDeclarator/Next) end up reducing the size of fields/ivars by 40%.

llvm-svn: 41948
2007-09-14 02:20:46 +00:00
Steve Naroff a23cc79654 Move Decl::NextDeclarator (w/ setters/getters) down to ScopedDecl/FieldDecl.
Decl is now svelte:-)

llvm-svn: 41935
2007-09-13 23:52:58 +00:00
Steve Naroff 9def2b15c1 Phase 2 of making the Decl class more lightweight...
Move Identifier/Loc instance variables (and associated getters/setters) down from Decl to ScopedDecl/FieldDecl.

Objc AST's can now inherit from Decl without getting instance variables and types that are C specific. For now, I am keeping NextDeclarator, since I believe it may be useful to ObjC. If not, it can be moved later.

llvm-svn: 41934
2007-09-13 21:41:19 +00:00
Fariborz Jahanian 6812cbb230 Patch for collecting ivars before running action on them.
llvm-svn: 41932
2007-09-13 20:56:13 +00:00
Steve Naroff 9324db12b2 Add "ScopedDecl" AST, used by ValueDecl and TypeDecl.
This allows us to sink the "Next" field, which isn't used by FieldDecl and ObjcIvarDecl.

llvm-svn: 41931
2007-09-13 18:10:37 +00:00
Steve Naroff 437b4d8bda Remove a FIXME. Replace a couple asserts with an appropriate error
diagnostic for illegal initializers.

llvm-svn: 41889
2007-09-12 20:13:48 +00:00
Fariborz Jahanian cfb31fab5e Patch for building method declaration nodes. Also fixed a segfault in cocoa.m due
to use of @property.

llvm-svn: 41880
2007-09-12 18:23:47 +00:00
Steve Naroff 6109140b00 Fix the following bug submitted by Ted Kremenek:
void func() {
int xx = xx; // incorrectly diagnosed 'xx' as an undeclared identifier.
}

This smallish bug resulted in a largish fix. Here are some highlights:

- Needed to make sure ParseDeclarator is called *before* parsing any
initializer. Removed the "Init" argument to ParseDeclarator.
- Added AddInitializerToDecl() to the Action & Sema classes.
In Sema, this hook is responsible for validating the initializer and
installing it into the respective decl.
- Moved several semantic checks from ParseDeclarator() to 
FinalizeDeclaratorGroup(). Previously, this hook was only responsible for 
reversing a list. Now it plays a much larger semantic role. 

All of the above changes ended up simplifying ParseDeclarator(), which
is goodness...

llvm-svn: 41877
2007-09-12 14:07:44 +00:00
Steve Naroff f2fb4ad08e - Add an ObjcIvarDecl AST node (a subclass of FieldDecl).
- Instantiate the node in Sema::ParseField(), based on the type of the TagDecl.
- Add Sema::ObjcAddInstanceVariable(), responsible for adorning/adding the ObjcIvarDecl.

llvm-svn: 41864
2007-09-11 21:17:26 +00:00
Steve Naroff 4292bde14f Fix the following bug submitted by Justin Handville.
int main(int argc, char* argv[])
{
  return 0;
}

After speaking briefly with Chris, we decided this should be a front-end fix.

The fix...have Sema::GetTypeForDeclarator() do the default function/array conversion, as
I outlined in the 9/9 email on this topic.

Since this conversion is done before Sema::ParseParamDeclarator(), I thought I could
remove the conversion from Sema::ParseParamDeclarator(). Unfortunately, this didn't work.
The conversion apparently needs to be done in both places (which doesn't make sense to me).

Will investigate.

llvm-svn: 41811
2007-09-10 22:17:00 +00:00
Steve Naroff acb1e7478f Some small tweaks to the recent Objc support...
llvm-svn: 41803
2007-09-10 20:51:04 +00:00
Fariborz Jahanian 33d037441e Early patch to collect objective-c methods inserts them in
class object.

llvm-svn: 41801
2007-09-10 20:33:04 +00:00
Steve Naroff 09bf815f89 The goal of this commit is to get just enough Sema support to recognize Objective-C classes
as types. That said, the AST nodes ObjcInterfaceDecl, ObjcInterfaceType, and ObjcClassDecl are *very*
preliminary.

The good news is we no longer need -parse-noop (aka MinimalActions) to parse cocoa.m.

llvm-svn: 41752
2007-09-06 21:24:23 +00:00
Ted Kremenek 73c18e0362 Added LabelLoc to GotoStmt to record the source location of the label token
in the actual GotoStmt.

Fixed bug where GotoStmt::getSourceRange incorrectly used the target LabelStmt
to compute its extent.

llvm-svn: 41745
2007-09-06 17:11:52 +00:00
Steve Naroff 67ae443954 Simplified initializer semantic analysis by adding the following 2 methods:
- ArrayType::getBaseType(), and 
- ConstantArrayType::getMaximumElements().

Wanted to do this cleanup before adding structure support, which will add more complexity.

llvm-svn: 41715
2007-09-04 21:13:33 +00:00
Steve Naroff 77b97002e9 Make sure initializer type promotions get propagated.
This fixes a recent regression with Codegen/mandel.c.

llvm-svn: 41696
2007-09-04 14:36:54 +00:00
Chris Lattner 9cf21c5a2c Silence VC++ warnings, patch by Hartmut Kaiser
llvm-svn: 41693
2007-09-04 02:45:27 +00:00
Steve Naroff ac074b4df4 More fun with initializers!
- Fixed many bugs, enhanced test case considerably, added a diagnostic, etc.
- Refactored CheckInitList() into CheckVariableInitList()/CheckConstantInitList().
- Added CheckInitExpr().
- Support for multi-dimensional arrays looking good.

llvm-svn: 41690
2007-09-04 02:20:04 +00:00
Chris Lattner 1463cca1cc Add a method required by the VC++ STL, patch by Hartmut Kaiser!
llvm-svn: 41687
2007-09-03 18:31:57 +00:00
Steve Naroff 7d2c5ed92e Finish getting "array-init.c" to work properly.
Array scalar initialization is now is reasonable shape.

Next step, structure and array of structure initializers.

llvm-svn: 41681
2007-09-03 01:24:23 +00:00
Steve Naroff b03f5940d1 More progress on array initializers.
- Added Expr::isConstantExpr().
- Added type checking for InitListExpr elements.
- Added diagnostic for trying to initialize a variable sized object.

llvm-svn: 41674
2007-09-02 20:30:18 +00:00
Steve Naroff f33527a1aa More semantic analysis of initializers.
Added 2 errors and one warning, updated test case.

llvm-svn: 41672
2007-09-02 15:34:30 +00:00
Steve Naroff 2fea13926f Start implementing semantic analysis for C initializers.
Step 1: Start instantiating InitListExpr's.
Step 2: Call newly added function Sema::CheckInitializer() from Sema::ParseDeclarator().
Step 3: Give InitListExpr's a preliminary type.
Step 4: Start emitting diagnostics for simple assignments.

Note:

As a result of step 1, the CodeGen/mandel.c test asserts "Unimplemented agg expr!", which is expected.

As a result of step 4, the test below now fails. This isn't expected and needs to be investigated (it appears type checking for C++ references is flawed in some way).

******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************
Command: 
 clang -fsyntax-only Sema/cxx-references.cpp
Output:
Sema/cxx-references.cpp:8:12: warning: incompatible pointer types assigning 'int &*' to 'int *'
  int *p = &r;
           ^~
Sema/cxx-references.cpp:10:20: error: incompatible types assigning 'int (int)' to 'int (&)(int)'
  int (&rg)(int) = g;
                   ^
Sema/cxx-references.cpp:13:18: error: incompatible types assigning 'int [3]' to 'int (&)[3]'
  int (&ra)[3] = a;
                 ^
Sema/cxx-references.cpp:16:14: error: incompatible types assigning 'int *' to 'int *&'
  int *& P = Q;
             ^
4 diagnostics generated.
******************** TEST 'Sema/cxx-references.cpp' FAILED! ********************

llvm-svn: 41671
2007-09-02 02:04:30 +00:00
Steve Naroff 42a350a18a Finish converting SwitchStmt AST to source ranges.
Move DumpSourceRange() to DumpStmt().

Now -parse-ast-dump will display source range info for all stmts/exprs.

One day we should implement the source range protocol for Decls.

llvm-svn: 41670
2007-09-01 21:08:38 +00:00
Steve Naroff dc9f36e6c4 Convert more statments over to SourceRanges...
llvm-svn: 41666
2007-08-31 23:49:30 +00:00
Steve Naroff 33f3d05081 Move SourceRange protocol from Expr->Stmt.
Converted many of the statements over. Still a hanful left...

llvm-svn: 41663
2007-08-31 23:28:33 +00:00
Chris Lattner cac27a5478 Fix a bug/missing-feature Ted noticed: the 'unused' warning should not
warn about the last stmt in a stmtexpr, f.e. there should be no warning for:

int maxval_stmt_expr(int x, int y) {
  return ({int _a = x, _b = y; _a > _b ? _a : _b; });
}

llvm-svn: 41655
2007-08-31 21:49:55 +00:00
Chris Lattner 78502cf4c9 diagnose extended uses of offsetof
llvm-svn: 41653
2007-08-31 21:49:13 +00:00
Steve Naroff 096dd942cf Removed Sema::VerifyConstantArrayType(). With the new Array/ConstantArray/VariableArray nodes, this
routine was causing more trouble than it was worth. Anders/Chris noticed that it could return an error code
without emiting a diagnostic (which results in an silent invalid decl, which should *never* happen). In addition,
this routine didn't work well for typedefs and field decls. Lastly, it didn't consider that initializers aren't
in place yet.

Added Type::getAsConstantArrayType(), Type::getAsVariableArrayType(), Type::getAsVariablyModifiedType(),
and Type::isVariablyModifiedType();

Modified Sema::ParseDeclarator() and Sema::ParseField() to use the new predicates. Also added a FIXME for
the initializer omission. Also added a missing test for "static" @ file scope.

llvm-svn: 41647
2007-08-31 17:20:07 +00:00
Anders Carlsson 4692db0e7e Add InitListExpr class.
llvm-svn: 41636
2007-08-31 04:56:16 +00:00
Chris Lattner 57c523f50c add actions for deleting expr/stmt nodes.
llvm-svn: 41635
2007-08-31 04:53:24 +00:00
Steve Naroff 43b8f7fa4f Sema::ParseCastExpr() missing call to UsualUnaryConversions().
The following case now works...

void empty(void * a ) {}

void test()
{
    unsigned char A[4]; 
    empty( (void *) A); 
}

Thanks to Patrick Flannery for finding this...

llvm-svn: 41630
2007-08-31 00:32:44 +00:00
Steve Naroff d57fa94148 Final phase of array cleanup (for now), removing a FIXME from yesterday.
Moved several array constraints checks from Sema::VerifyConstantArrayType() to
Sema::GetTypeForDeclarator(). VerifyConstantArrayType() is now very simple, and
could be removed eventually.

Now, we get the following (correct) messages for BlockVarDecls:-)

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang x.c -pedantic
x.c:4:20: error: size of array has non-integer type 'float'
  int size_not_int[f];
                   ^
x.c:5:21: error: array size is negative
  int negative_size[1-2];
                    ^~~
x.c:6:17: warning: zero size arrays are an extension
  int zero_size[0];
                ^
3 diagnostics generated.

llvm-svn: 41624
2007-08-30 22:35:45 +00:00
Steve Naroff 90dfdd5774 Polish yesterday's Array/ConstantArray/VariableArray rewrite, removing a couple FIXME's.
Refactored Array/VariableArray, moving SizeModifier/IndexTypeQuals back up to Array. These
attributes are not specific to VLA's. Most of them are specific to array parameter types.

llvm-svn: 41616
2007-08-30 18:10:14 +00:00
Chris Lattner 98dbf0a3b8 implement pretty printing of offsetof
llvm-svn: 41615
2007-08-30 17:59:59 +00:00
Chris Lattner f17bd423c2 implement initial sema support for __builtin_offsetof
llvm-svn: 41613
2007-08-30 17:45:32 +00:00
Chris Lattner 55343038f4 Fix 80 col violations.
llvm-svn: 41611
2007-08-30 17:08:17 +00:00
Chris Lattner 270228599d Fix a regression on test/Sema/unused-expr.c by fixing the type predicates
to test for the right type class.

llvm-svn: 41601
2007-08-30 06:10:41 +00:00
Steve Naroff 5c13180a27 Fix the following redefinition errors submitted by Keith Bauer...
[dylan:~/llvm/tools/clang] admin% cat tentative_decls.c 
// incorrectly generates redefinition error
extern int array[3];
int array[3];

// incorrectly generates a redefinition error
extern void nup(int a[3]);
void nup(int a[3]) {}

It turns out that this exposed a fairly major flaw in the type system,
array types were never getting uniqued! This is because all array types
contained an expression, which aren't unique.

To solve this, we now have 2 array types, ConstantArrayType and
VariableArrayType. ConstantArrayType's are unique, VAT's aren't.

This is a fairly extensive set of fundamental changes. Fortunately,
all the tests pass. Nevertheless, there may be some collateral damage:-)
If so, let me know!

llvm-svn: 41592
2007-08-30 01:06:46 +00:00
Neil Booth 4a1ee0562d Spaces not tabs.
llvm-svn: 41582
2007-08-29 22:13:52 +00:00
Neil Booth ac582c5ecb Ensure we diagnose long long literals in C90 mode.
llvm-svn: 41581
2007-08-29 22:00:19 +00:00
Ted Kremenek 5ccf0d832d Added checking (during parsing) of comparison of floating point values using == or !=.
This is the same functionality gcc provides via --Wfloat-equal.

llvm-svn: 41574
2007-08-29 18:06:12 +00:00
Chris Lattner 3a370bf33f Implement GCC-compatible layout and typing of enum constants and enum decl.
A small bit of codegen work is still pending.

llvm-svn: 41571
2007-08-29 17:31:48 +00:00
Chris Lattner c92bc4ce2f Fix a null dereference Neil ran into
llvm-svn: 41564
2007-08-29 16:03:41 +00:00
Steve Naroff 0b66158248 Implement default argument promotions (for old-style function calls and variable argument lists).
[dylan:~/llvm/tools/clang] admin% cat x.c

int printf(const char *, ...);

int oldschool();

void foo() {
  float f; 
  short i;
  printf("foo %f", 1.0f);

  oldschool(f,i);
}

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang x.c -parse-ast-dump

int printf(char const *, ...);

int oldschool();

void foo()
(CompoundStmt 0x3105f00
  (DeclStmt 0x3105ba0
    0x3105ce0 "float f")
  (DeclStmt 0x3105c90
    0x3105d10 "short i")
  (CallExpr 0x3105df0 'int'
    (ImplicitCastExpr 0x3105dc0 'int (*)(char const *, ...)'
      (DeclRefExpr 0x3105c20 'int (char const *, ...)' Decl='printf' 0x3105bd0))
    (ImplicitCastExpr 0x3105dd0 'char const *'
      (StringLiteral 0x3105d60 'char *' "foo %f"))
    (ImplicitCastExpr 0x3105de0 'double'
      (FloatingLiteral 0x3105d80 'float' 1.000000)))
  (CallExpr 0x3105ed0 'int'
    (ImplicitCastExpr 0x3105ea0 'int (*)()'
      (DeclRefExpr 0x3105e20 'int ()' Decl='oldschool' 0x3105c40))
    (ImplicitCastExpr 0x3105eb0 'double'
      (DeclRefExpr 0x3105e40 'float' Decl='f' 0x3105ce0))
    (ImplicitCastExpr 0x3105ec0 'int'
      (DeclRefExpr 0x3105e60 'short' Decl='i' 0x3105d10))))

llvm-svn: 41558
2007-08-28 23:30:39 +00:00
Steve Naroff f93b6726b1 Finish converting decls over to the new invalid decl API.
Also removed an old FIXME (FIXME: "auto func();" passes through...).

llvm-svn: 41555
2007-08-28 20:14:24 +00:00
Steve Naroff cf871f59bf Move the "invalid decl" idiom up to Decl (where we have some bits to steal:-)
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
2007-08-28 18:45:29 +00:00
Chris Lattner 24b51ff752 Emit a slightly better warning for unused values for unary and binary operators:
t2.c:3:18: warning: expression result unused
     x = ++x, ++y, y+2;
     ~~~~~~~~~~~~^ ~~~

llvm-svn: 41551
2007-08-28 18:40:30 +00:00
Chris Lattner c11005faa1 add a sourcelocation to binary operator to keep track of the location of the operator.
llvm-svn: 41550
2007-08-28 18:36:55 +00:00
Chris Lattner 1c1f932433 Change EnumDecl to store its corresponding integer type
directly in it.  Remove TargetInfo::getEnumPolicy, as there is only
one policy that we support right now.

llvm-svn: 41548
2007-08-28 18:24:31 +00:00
Ted Kremenek e07a8cd7ff Fixed return-of-stack-address checker to correctly handle stack/global
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
2007-08-28 17:02:55 +00:00
Chris Lattner 35da3e29dd extwarn about VLAs in C89 mode.
llvm-svn: 41545
2007-08-28 16:54:00 +00:00
Chris Lattner 8ed218afb9 c++'0x has long long also.
llvm-svn: 41544
2007-08-28 16:41:29 +00:00
Chris Lattner f2c338b7d1 warn about long long when in c89 mode.
llvm-svn: 41543
2007-08-28 16:40:32 +00:00
Chris Lattner c4f6d0c5cf fix 80 col violation
llvm-svn: 41533
2007-08-28 06:17:15 +00:00
Chris Lattner b8a501ccf1 compute the required destination type for an enum, emitting various warnings.
TODO: update the types of the constants and the enum.
llvm-svn: 41532
2007-08-28 06:15:15 +00:00
Chris Lattner bf478cbef2 add a diagnostic:
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
2007-08-28 05:27:00 +00:00
Chris Lattner 67933c0aae move a todo
llvm-svn: 41528
2007-08-28 05:10:31 +00:00
Chris Lattner 39f920f35b now that all the infrastructure is in place, enforce C99 6.8.5p3.
Note the FIXME: we need some way to mark a decl erroneous :)

llvm-svn: 41524
2007-08-28 05:03:08 +00:00
Chris Lattner 773c0596b8 If the condition of a for statement is promoted, make sure the
implicit cast gets linked back into the AST.

llvm-svn: 41523
2007-08-28 04:55:47 +00:00
Steve Naroff 7e6f7c25bf Implement more thoughful error recovery when dealing with bogus declarator types.
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
2007-08-28 03:03:08 +00:00
Steve Naroff a042db2b80 Some minor aesthetic changes to the control flow.
llvm-svn: 41517
2007-08-27 21:43:43 +00:00
Steve Naroff e31313d792 Fix remaining bugs with complex/float promotions.
llvm-svn: 41515
2007-08-27 21:32:55 +00:00
Chris Lattner 0515e4b26a Fix a few enum-related fixme's
llvm-svn: 41513
2007-08-27 21:16:18 +00:00
Chris Lattner f283a37179 better error recovery for non-i-c-e enum constants.
llvm-svn: 41499
2007-08-27 17:37:24 +00:00
Ted Kremenek d11e460810 Updated checker for "return of address of stack variable" to look for
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
2007-08-27 16:39:17 +00:00
Steve Naroff 7af82d462a Replaced ASTContext::maxFloatingType() with ASTContext::compareFloatingType().
Changed Sema::UsualArithmeticConversions to use the new API.

This fixes the following case...

_Complex double X;
double y;

void foo() {
  X = X + y;
}

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang complex.c -parse-ast-dump
Read top-level variable decl: 'X'
Read top-level variable decl: 'y'

void foo()
(CompoundStmt 0x2605cc0
  (BinaryOperator 0x2605ca0 '_Complex double' '='
    (DeclRefExpr 0x2605c10 '_Complex double' Decl='X' 0x2605ab0)
    (BinaryOperator 0x2605c80 '_Complex double' '+'
      (DeclRefExpr 0x2605c30 '_Complex double' Decl='X' 0x2605ab0)
      (ImplicitCastExpr 0x2605c70 '_Complex double'
        (DeclRefExpr 0x2605c50 'double' Decl='y' 0x2605ae0)))))

llvm-svn: 41483
2007-08-27 15:30:22 +00:00
Chris Lattner d864daf5c6 extwarn about decls intermixed with code in c89 mode.
llvm-svn: 41477
2007-08-27 04:29:41 +00:00
Steve Naroff 808eb8fe88 Add Type::getAsBuiltinType() and Type::builtinTypesAreCompatible().
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
2007-08-27 04:08:11 +00:00
Steve Naroff 9091ef703c Replaced ASTContext::maxComplexType() with ASTContext::getFloatingTypeOfSizeWithinDomain().
Changed Sema::UsualArithmeticConversions to correctly implement complex/float conversions, 
using maxFloatingType() with getFloatingTypeOfSizeWithinDomain().

llvm-svn: 41474
2007-08-27 01:27:54 +00:00
Chris Lattner dfaf9f8c2f implement a fixme: __extension__ marker on decls in compound stmts.
llvm-svn: 41473
2007-08-27 01:01:57 +00:00
Chris Lattner 0c6aad373f Fix %p format checking, patch by Keith Bauer.
llvm-svn: 41454
2007-08-26 17:39:38 +00:00
Chris Lattner 0d850bfed8 For warnings like this:
t.c:3:9: warning: invalid conversion '%B'
printf("%B\a\n", p);
~~~~~~  ^

Don't beep the console or print the newline.

llvm-svn: 41453
2007-08-26 17:38:22 +00:00
Chris Lattner 9decfbabd3 Fix a bug reported by Keith Bauer
llvm-svn: 41452
2007-08-26 17:32:59 +00:00
Steve Naroff 5f90ca9904 Fix bogus warnings (noticed by Chris) with array-constraints.c.
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
2007-08-26 14:38:38 +00:00
Chris Lattner 1a76a3c970 Break the assumption that any sort of scope (e.g. a loop scope) can
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
2007-08-26 06:24:45 +00:00
Chris Lattner e267f5d2f7 require that operands to __real/__imag are complex or arithmetic. This
fixes GCC PR33193

llvm-svn: 41428
2007-08-26 05:39:26 +00:00
Chris Lattner b677a9398a Make parse-ast-print print the storage class and inline
specifier of functions.

llvm-svn: 41416
2007-08-26 04:02:13 +00:00
Chris Lattner 1c20a170c0 add a new ImaginaryLiteral AST node that is used to
represent imaginary literals:

float _Complex A;
void foo() {
  A = 1.0iF;
}

generates:

  (BinaryOperator 0x2305ec0 '_Complex float' '='
    (DeclRefExpr 0x2305e60 '_Complex float' Decl='A' 0x2305cf0)
    (ImaginaryLiteral 0x2305f40 '_Complex float'
      (FloatingLiteral 0x2305ea0 'float' 1.000000))))

llvm-svn: 41413
2007-08-26 03:42:43 +00:00
Chris Lattner ed045421a8 1.0 is double, 1.0F is a float.
llvm-svn: 41412
2007-08-26 03:29:23 +00:00
Chris Lattner b620c34bb0 merge checkrelational and checkequality into CheckCompareOperands,
to merge duplicate code.

llvm-svn: 41410
2007-08-26 01:18:55 +00:00
Chris Lattner 1895e58c84 Cases like this:
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
2007-08-26 01:10:14 +00:00
Steve Naroff 46c72915f4 Surpress the UsualUnaryConversions for compound assignment operators. This change
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
2007-08-25 19:54:59 +00:00
Steve Naroff aac9415bfb Give CXXBoolLiteralExpr a type (all expressions need a valid type).
This fixes the following:

******************** TEST 'Parser/cxx-bool.cpp' FAILED! ********************
Command:
clang -fsyntax-only Parser/cxx-bool.cpp
Output:
SemaExpr.cpp:731: failed assertion `!t.isNull() && "DefaultFunctionArrayConversion - missing type"'
Output/cxx-bool.cpp.out.script: line 1: 22697 Abort trap              clang -fsyntax-only Parser/cxx-bool.cpp

llvm-svn: 41401
2007-08-25 14:02:58 +00:00
Chris Lattner e33fbdb898 Fix the test/Sema/format-strings.c regression. This code should be refactored.
llvm-svn: 41398
2007-08-25 05:36:18 +00:00
Chris Lattner 9449fd7bc3 Fix the regression on test/Sema/cfstring.c
llvm-svn: 41396
2007-08-25 05:30:33 +00:00
Steve Naroff 0c1c7ed5e6 This modest change insures ImplicitCastExpr's get generated for all "assignments",
while includes init decls, assignment exprs, call exprs, and return statements.

Here are a few examples with the correct AST's...

[dylan:~/llvm/tools/clang] admin% cat impcomp.c

_Complex double X;
void test2(int c) {
  X = 5;
}
void foo() {
  int i;
  double d = i;
  double _Complex a = 5;

  test2(a);
  a = 5;
  d = i;
}


[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang impcomp.c -parse-ast-dump
Read top-level variable decl: 'X'

void test2(int c)
(CompoundStmt 0x2605ce0
  (BinaryOperator 0x2605cc0 '_Complex double' '='
    (DeclRefExpr 0x2605c70 '_Complex double' Decl='X' 0x2605af0)
    (ImplicitCastExpr 0x2605cb0 '_Complex double'
      (IntegerLiteral 0x2605c90 'int' 5))))


void foo()
(CompoundStmt 0x2606030
  (DeclStmt 0x2605bd0
    0x2605d90 "int i")
  (DeclStmt 0x2605e20
    0x2605de0 "double d =
      (ImplicitCastExpr 0x2605e10 'double'
        (DeclRefExpr 0x2605dc0 'int' Decl='i' 0x2605d90))")
  (DeclStmt 0x2605e90
    0x2605e50 "_Complex double a =
      (ImplicitCastExpr 0x2605e80 '_Complex double'
        (IntegerLiteral 0x2605e30 'int' 5))")
  (CallExpr 0x2605f20 'void'
    (ImplicitCastExpr 0x2605f00 'void (*)(int)'
      (DeclRefExpr 0x2605ea0 'void (int)' Decl='test2' 0x2605c00))
    (ImplicitCastExpr 0x2605f10 'int'
      (DeclRefExpr 0x2605ec0 '_Complex double' Decl='a' 0x2605e50)))
  (BinaryOperator 0x2605fa0 '_Complex double' '='
    (DeclRefExpr 0x2605f50 '_Complex double' Decl='a' 0x2605e50)
    (ImplicitCastExpr 0x2605f90 '_Complex double'
      (IntegerLiteral 0x2605f70 'int' 5)))
  (BinaryOperator 0x2606010 'double' '='
    (DeclRefExpr 0x2605fc0 'double' Decl='d' 0x2605de0)
    (ImplicitCastExpr 0x2606000 'double'
      (DeclRefExpr 0x2605fe0 'int' Decl='i' 0x2605d90))))

llvm-svn: 41379
2007-08-24 22:33:52 +00:00
Chris Lattner 74ed76bb0e remove a dead argument
llvm-svn: 41377
2007-08-24 21:41:10 +00:00
Chris Lattner 30b5dd0b79 Implement sema support for __real/__imag nodes.
llvm-svn: 41375
2007-08-24 21:16:53 +00:00
Steve Naroff be4c4d14c3 Surpress ImplicitCastExprs for compound assignment expressions. For compound assignments,
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
2007-08-24 19:07:16 +00:00
Steve Naroff 9d13917cff Make sure we get extension diagnostics for GCC's complex extensions.
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
2007-08-24 17:20:07 +00:00
Chris Lattner 247ef955bc in the truncation case, make sure to propagate the sign correctly, this
fixes an assertion on:
void f (int z) { switch (z) { case ~0ULL: case -1: return; } }

testcase from Neil.

llvm-svn: 41343
2007-08-23 22:08:35 +00:00
Steve Naroff 8ddb23a6c5 Support '~' for complex conjugation. This is a GCC extension.
This following now compiles without error...

_Complex unsigned X, Y;
_Complex double x, y;
void test2(int c) {
  X = ~Y;
  x = ~y;
}

llvm-svn: 41341
2007-08-23 22:06:40 +00:00
Chris Lattner 7b939cf606 fix a bug where we would type 0ULL as unsigned instead of unsigned long long
llvm-svn: 41340
2007-08-23 21:58:08 +00:00
Steve Naroff 9e1e551c01 Remove a FIXME, allowing ++/-- on Complex types (a GCC extension).
Now, the following test case succeeds...

_Complex double x, y;
void test2(int c) {
  ++x;
}

llvm-svn: 41335
2007-08-23 21:37:33 +00:00
Chris Lattner 67998451c7 finish off switch case overlap checking, adding support for
verifying case ranges.

llvm-svn: 41331
2007-08-23 18:29:20 +00:00
Chris Lattner f81460f99c detect and diagnose empty case ranges:
switch.c:16:8: warning: empty case range specified
  case 100 ... 99: ;  // expected-warning {{empty case range}}
       ^~~~~~~~~~

llvm-svn: 41328
2007-08-23 17:48:14 +00:00
Chris Lattner fcb920d32b fix a segfault in cases where there are no cases.
llvm-svn: 41317
2007-08-23 14:29:07 +00:00
Chris Lattner 10cb5e520f report duplicate case values. TODO: report duplicate/overlapping ranges.
llvm-svn: 41315
2007-08-23 06:23:56 +00:00
Chris Lattner fc1c44ac7d start checking case values of switch stmts more closely. Emit overflow
warnings when converting case values to the expression type.

llvm-svn: 41313
2007-08-23 05:46:52 +00:00
Anders Carlsson c5a81ebb1f Parse @encode expressions.
llvm-svn: 41273
2007-08-22 15:14:15 +00:00
Anders Carlsson 76f4a902d7 Implement parsing and code generation of Objective-C string literals.
llvm-svn: 41238
2007-08-21 17:43:55 +00:00
Chris Lattner 755a5a9933 add sema support for complex integer types
llvm-svn: 41232
2007-08-21 17:02:28 +00:00
Ted Kremenek c81614d5d1 Modified ArraySubscriptExpr to have accessors getLHS and getRHS in addition
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
2007-08-20 16:18:38 +00:00
Ted Kremenek cff94fa201 Added extra semantic checking to do basic detection of
"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
2007-08-17 16:46:58 +00:00
Anders Carlsson a3a9c43837 Return true in case of error, which is what other functions do.
llvm-svn: 41140
2007-08-17 15:44:17 +00:00
Anders Carlsson 98f0790fab Add initial support for constant CFStrings.
llvm-svn: 41136
2007-08-17 05:31:46 +00:00
Steve Naroff cdee44c12a Fixed Sema::CheckEqualityOperands() and Sema::CheckRelationalOperands() to deal more
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
2007-08-16 21:48:38 +00:00
Ted Kremenek c48affb81f Removed dead variable "hadError" in ParseReturnStmt.
llvm-svn: 41079
2007-08-14 18:14:14 +00:00
Ted Kremenek e68f1aad65 Added support for additional format string checking for the printf
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
2007-08-14 17:39:48 +00:00
Ted Kremenek 56c864e3fd Added "id_idx" parameter to CheckPrintfArguments. This will be used
by CheckPrintfArguments to determine if a given printf function
accepts a va_arg argument.

llvm-svn: 41008
2007-08-10 21:21:05 +00:00
Ted Kremenek cfc9419dd4 Moved id_asprintf before id_vsnprintf in the enum used for indexing
KnownFunctionIDs.  This allows us to test for a printf-like function
that accepts a va_arg argument using a range comparison.

llvm-svn: 41006
2007-08-10 21:13:51 +00:00
Chris Lattner b87b1b36ee initial support for checking format strings, patch by Ted Kremenek:
"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
2007-08-10 20:18:51 +00:00
Steve Naroff 47fea35e48 Make sure the arithmetic conversion are done for relation and equality operators.
This fixes the following...

eypedef short S;
int test(S X, long long Y) {
  return X < Y;
}

Before...

(CompoundStmt 0x2905d00
  (ReturnStmt 0x2905cf0
    (BinaryOperator 0x2905cd0 'int' '<'
      (ImplicitCastExpr 0x2905cc0 'int'
        (DeclRefExpr 0x2905c80 'S':'short' Decl='X' 0x2905c20))
      (DeclRefExpr 0x2905ca0 'long long' Decl='Y' 0x2905c50))))

After...

(CompoundStmt 0x2b05c30
  (ReturnStmt 0x2b05c20
    (BinaryOperator 0x2b05c00 'int' '<'
      (ImplicitCastExpr 0x2b05bf0 'long long'
        (DeclRefExpr 0x2b05bb0 'S':'short' Decl='X' 0x2b05b50))
      (DeclRefExpr 0x2b05bd0 'long long' Decl='Y' 0x2b05b80))))

llvm-svn: 40999
2007-08-10 18:26:40 +00:00
Steve Naroff 773df5cf30 Move the function/array conversion for ParmVarDecl's from Sema::ParseIdentifierExpr()
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
2007-08-07 22:44:21 +00:00
Steve Naroff 04e8bc8e35 Remove a space from "typeof" printing. It was causing the following error...
[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
2007-08-05 03:24:45 +00:00
Steve Naroff 8a4cf97aa9 Make sure the good old "function/array conversion" is done to function parameters.
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
2007-08-05 02:16:31 +00:00
Steve Naroff 0104731e62 Restrict vector component access (using "." and "[]") to variables.
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
2007-08-03 22:40:33 +00:00
Steve Naroff 9efdabc565 Implement __builtin_choose_expr.
llvm-svn: 40794
2007-08-03 21:21:27 +00:00
Chris Lattner d268a7a268 Rename AddrLabel and OCUVectorComponent -> AddrLabelExpr and OCUVectorElementExpr respectively. This is for consistency with other expr nodes end with *Expr.
llvm-svn: 40785
2007-08-03 17:31:20 +00:00
Chris Lattner 7e152dbb1f rename some helpers, have them return the idx of the field being accessed.
llvm-svn: 40764
2007-08-02 22:33:49 +00:00
Steve Naroff 788d864d6c - Finish hooking up support for __builtin_types_compatible_p().
- Fix type printing code for recently added TypeOfExpr/TypeOfType.

llvm-svn: 40700
2007-08-01 23:45:51 +00:00
Steve Naroff 7886467b35 Add AST/Sema support for __builtin_types_compatible_p (a GNU extension).
Todo...still need to call the action from the parser...

llvm-svn: 40693
2007-08-01 22:05:33 +00:00
Steve Naroff 236becbbc3 Two typeof() related changes...
- Changed the name of ASTContext::getTypeOfType(Expr*)->getTypeOfExpr().
- Remove FIXME for TypeOfExpr::getAsStringInternal(). This will work fine for printing the AST. It isn't ideal
for error diagnostics (since it's more natural to display the expressions type). 

One "random" (or at least delayed:-) change...

- Changed all "ext_typecheck_*" diagnostics from EXTENSION->WARNING. Reason: Since -pedantic is now
off (by default), these diagnostics were never being emitted (which is bad). With this change, clang will
emit the warning all the time. The only downside (wrt GCC compatibility) is -pedantic-errors will not turn
this diagnostics into errors (a "feature" of making tagging them with EXTENSION). When/if this becomes
an issue, we can revisit.

llvm-svn: 40676
2007-08-01 17:20:42 +00:00
Chris Lattner 0fd893e643 remove more explicit accesses to the canonical type pointer.
llvm-svn: 40653
2007-07-31 21:33:24 +00:00
Chris Lattner e5a6cbd457 simplify some type checking code, don't explicitly access
canonical types.

llvm-svn: 40652
2007-07-31 21:27:01 +00:00
Chris Lattner 4197796f65 split the rest of the type predicates into pure predicates:
there is now an isXXXType and a getAsXXXType

llvm-svn: 40646
2007-07-31 19:29:30 +00:00
Chris Lattner cd1d086b5a rename isReferenceType to follow the new scheme.
llvm-svn: 40640
2007-07-31 16:56:34 +00:00
Chris Lattner c996b176e8 make isPointerType() a pure predicate, rename the
existing one to getAsPointerType()

llvm-svn: 40639
2007-07-31 16:53:04 +00:00
Steve Naroff ad373bdcfe Add parsing and AST support for GNU "typeof".
Many small changes to lot's of files.
Still some FIXME's, however the basic support is in place.

llvm-svn: 40631
2007-07-31 12:34:36 +00:00
Chris Lattner fedeaa3045 Don't use canonical type for sema here. In
void func() {
typedef int foo;
foo *Y;
**Y; // error
}

we now get:
indirection requires pointer operand ('foo' invalid)
instead of:
indirection requires pointer operand ('int' invalid)

llvm-svn: 40597
2007-07-30 18:53:26 +00:00
Steve Naroff 0d595ca0bb Finish up semantic analysis for vector components.
llvm-svn: 40584
2007-07-30 03:29:09 +00:00
Steve Naroff ddf5a1d7a6 Implement pretty diagnostics when doing on-the-fly vector sizing (for vector component access).
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
2007-07-29 16:33:31 +00:00
Steve Naroff f7a5da17d9 Added a new expression, OCUVectorComponent.
llvm-svn: 40577
2007-07-28 23:10:27 +00:00
Steve Naroff f8fd09e22b Implement syntax/semantic analysis for OCU Vector Components.
Next step, AST support...

llvm-svn: 40568
2007-07-27 22:15:19 +00:00
Steve Naroff 49ab97761b Fix the following bogus diagnostic...reported by Jeroen.
#include <stdio.h>

int
main(void) {
        int test = 0;

        printf("Type is %s\n", (test >= 1 ? "short" : "char"));

        return (0);
}

It comes up with a diagnostic that's misleading upon first read.

t.c:7:36: error: incompatible operand types ('char *' and 'char *')
        printf("Type is %s\n", (test >= 1 ? "short" : "char"));
                                          ^ ~~~~~~~   ~~~~~~
1 diagnostic generated.

llvm-svn: 40526
2007-07-26 14:35:56 +00:00
Steve Naroff 185616f293 Various improvements to Sema::ParseMemberReferenceExpr().
- Added source range support to Diag's.
- Used the new type predicate API to remove dealing with the canonical
type explicitly.
- Added Type::isRecordType().
- Removed some casts.
- Removed a const qualifier from RecordType::getDecl(). 

llvm-svn: 40508
2007-07-26 03:11:44 +00:00
Steve Naroff b8af1c2bf6 - Fix commit in Parser.h (patch by Kevin Andre).
- Add comment and minor cleanup to yesterday's fix to ParseCallExpr().

llvm-svn: 40492
2007-07-25 20:45:33 +00:00
Chris Lattner 02c0439a44 Fix a couple of bugs, add some new cool stuff.
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
2007-07-25 00:24:17 +00:00
Steve Naroff 44fd8ff400 Fix Sema::ParseCallExpr()...it wasn't doing the default array/function promotions on it's argument types.
This resulted in the following errors when compiling promote_types_in_proto.c test...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang test/Parser/promote_types_in_proto.c 
test/Parser/promote_types_in_proto.c:7:24: error: incompatible types passing 'char *[]' to function expecting 'char *const []'
        arrayPromotion(argv);
        ~~~~~~~~~~~~~~ ^~~~
test/Parser/promote_types_in_proto.c:8:27: error: incompatible types passing 'void (char *const [])' to function expecting 'void (char *const [])'
        functionPromotion(arrayPromotion);
        ~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~
2 diagnostics generated.

When fixing this, noticed that both ParseCallExpr() and ParseReturnStmt() were prematurely comparing types for
equivalence. This is incorrect (since the expr. promotions haven't been done yet). To fix this, I moved the
check "down" to Sema::CheckAssignmentConstraints().

I also converted Type::isArrayType() to the modern API (since I needed it). Still more Type predicates to 
convert.

llvm-svn: 40475
2007-07-24 21:46:40 +00:00
Chris Lattner 366727fca1 implement ast building and trivial semantic analysis of stmt exprs.
This implements test/Sema/stmt_exprs.c

llvm-svn: 40465
2007-07-24 16:58:17 +00:00
Chris Lattner 54f4d2bd57 correctly verify that default and case are in a switchstmt,
this fixes test/Sema/switch.c.

llvm-svn: 40438
2007-07-23 17:05:23 +00:00
Anders Carlsson 51873c22d8 Refactor switch analysis to make it possible to detect duplicate case values
llvm-svn: 40388
2007-07-22 07:07:56 +00:00
Chris Lattner e386fab8ac recover from void argument types more nicely.
llvm-svn: 40169
2007-07-21 05:30:18 +00:00
Chris Lattner 26a1b3c6f7 better wording for an error, suggested by Neil.
llvm-svn: 40163
2007-07-21 05:26:43 +00:00
Anders Carlsson 625bfc8716 Implement code generation for __func__, __FUNCTION__ and __PRETTY_FUNCTION__
llvm-svn: 40162
2007-07-21 05:21:51 +00:00
Chris Lattner 5abb82c353 improve and simplify error recovery for calls, fix a crash when diagnosing
invalid arguments.

llvm-svn: 40161
2007-07-21 05:18:12 +00:00
Chris Lattner bb0ab46fd8 fix a warning on some compilers
llvm-svn: 40139
2007-07-21 04:57:45 +00:00
Chris Lattner a6f5ab5425 Fix off-by-one error when emitting diagnostics. Also, make diagnostic
a bit nicer for people who pass lots of extra arguments to calls by 
selecting them all instead of just the first one:

arg-duplicate.c:13:13: error: too many arguments to function
  f3 (1, 1, 2, 3, 4);   // expected-error {{too many arguments to function}}
            ^~~~~~~

This implements test/Sema/arg-duplicate.c, thanks to Neil for pointing
out this crash.

llvm-svn: 40136
2007-07-21 03:09:58 +00:00
Chris Lattner 38dbdb2c9c move some casts up to the entry of the function for clarity.
llvm-svn: 40135
2007-07-21 03:03:59 +00:00
Chris Lattner 3940737edf Two fixes:
1) fix a crash on test/Sema/default.c by making
   sure that the switch scope is non-null.
2) if there is an error sema'ing a default or case stmt,
   make sure to return the substmt up, so that the error
   recovery code has more acurate info to continue with.

llvm-svn: 40134
2007-07-21 03:00:26 +00:00
Chris Lattner 146762e7a4 At one point there were going to be lexer and parser tokens.
Since that point is now long gone, we should rename LexerToken to
Token, as it is the only kind of token we have.

llvm-svn: 40105
2007-07-20 16:59:19 +00:00
Steve Naroff 57eb2c5f58 Finish fixing crasher with compound literals.
We still need to do sematic analysis (and implement initializers), however this 
should complete the parsing & ast building for compound literals.

llvm-svn: 40067
2007-07-19 21:32:11 +00:00
Steve Naroff fbd098332c Work towards fixing crasher with compound literals...
Before this commit, we crashed in ParseBinOp...

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang -parse-ast-check compound_literal.c
SemaExpr.cpp:1298: failed assertion `(rhs != 0) && "ParseBinOp(): missing right expression"'

With this commit, we still crash in the newly added action ParseCompoundLiteral (which is progress:-)

[dylan:~/llvm/tools/clang] admin% ../../Debug/bin/clang -parse-ast-check compound_literal.c
SemaExpr.cpp:478: failed assertion `(Op != 0) && "ParseCompoundLiteral(): missing expression"'

The crash go away once the actions return AST nodes. I will do this in a separate commit.

llvm-svn: 40032
2007-07-19 01:06:55 +00:00
Chris Lattner 5fbd7e0264 Fix a crasher that Neil reported: Sema::GetTypeForDeclarator should never
return a null type.  If there is an error parsing the type, pick a new type
for error recovery purposes.

llvm-svn: 40029
2007-07-19 00:42:40 +00:00
Steve Naroff 91fcddb5cc First round of extended vector support. Here is an overview...
- 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
2007-07-18 18:00:27 +00:00
Chris Lattner bd27073f2a Cast to void is valid, patch by Benoit Boissinot
llvm-svn: 40003
2007-07-18 16:00:06 +00:00
Chris Lattner 46eeb22fec Add initial switch stmt support, patch by Anders Carlsson!
llvm-svn: 39989
2007-07-18 02:28:47 +00:00
Bill Wendling 89ba70eba6 Use the correct method for getting the ReferenceType from a QualType.
llvm-svn: 39960
2007-07-17 05:09:22 +00:00
Bill Wendling 354fb2678d Change dyn_cast for reference types to be more like pointers and not need the canonical type. Also fix so that we're not expecting a return value from a void function
llvm-svn: 39954
2007-07-17 04:16:47 +00:00
Bill Wendling dfc810717e Fix references:
According to the spec (C++ 5p6[expr]), we need to adjust "T&" to
    "T" before further analysis. We do this via the "implicit cast"
    thingy.

llvm-svn: 39953
2007-07-17 03:52:31 +00:00
Steve Naroff dbd9e89334 Convert UsualArithmeticConversions to return "void". Now that we synthesize ImplicitCastExpr's,
there is no compelling need to return the converted type. If both expression type's are arithmetic, then
both types will always be the same. If they aren't (for pointer/int types, say), then the
types will be different. The client is responsible for distinguishing...

llvm-svn: 39947
2007-07-17 00:58:39 +00:00
Steve Naroff 1a2cf6b3b3 Implement semantic analysis for the cast operator.
llvm-svn: 39943
2007-07-16 23:25:18 +00:00
Steve Naroff 94a5acac9b Remove the 2 QualType references to method UsualArithmeticConversions. Last week, I added these
to quickly fix a regression. Avoiding them entirely is a much cleaner solution. Clients of 
UsualArithmeticConversions should simply call getType() on the expression to get the
converted type. In practice, only a small number of routines care about this.

llvm-svn: 39934
2007-07-16 22:23:01 +00:00
Steve Naroff 3109001c19 Change DefaultFunctionArrayConversions and UsualUnaryConversions to return void. The caller
needs to query the expression for the type. Since both these functions guarantee the expression 
contains a valid type, removed old/vacuous asserts (from code calling both of these routines).

llvm-svn: 39930
2007-07-16 21:54:35 +00:00
Chris Lattner daaa9f207c Fix a GCC warning:
SemaExpr.cpp:561: warning: dereferencing type-punned pointer will break strict-aliasing rules

Patch by Benoit Boissinot!

llvm-svn: 39928
2007-07-16 21:39:03 +00:00
Chris Lattner aee0cfd486 Now that isPointerType can return a pointer type, avoid stripping off typedef
information in the common case.  On this invalid code:

typedef float float4 __attribute__((vector_size(16)));
typedef int int4 __attribute__((vector_size(16)));
void test(float4 a, int4 *result, int i) {
    result[i] = a;
}

we now generate:
  t.c:5:15: error: incompatible types assigning 'float4' to 'int4'
instead of:
  t.c:5:15: error: incompatible types assigning 'float4' to 'int  __attribute__((vector_size(16)))'

This implements test/Sema/typedef-retain.c

llvm-svn: 39892
2007-07-16 00:23:25 +00:00
Chris Lattner 36d572b9ea Use the return value of isPointerType and isVectorType to significantly simplify
ParseArraySubscriptExpr.  Notably, the new code doesn't have to think about 
canonical types at all.

llvm-svn: 39891
2007-07-16 00:14:47 +00:00
Chris Lattner 5981db49a2 rename variables to be more consistent. Always use LHS/RHS intead of T1/T2 sometimes.
llvm-svn: 39889
2007-07-15 23:59:53 +00:00
Chris Lattner 0e9d6226ca Refactor code so that isIntegerConstantExpr has an ASTContext available.
llvm-svn: 39884
2007-07-15 23:26:56 +00:00
Steve Naroff 81569d2044 This is the final step/commit for implementing exlicit implicit casts. Unlike the
previous two checkins, which involved lot's of tedious refactoring, this checkin is nice and clean:-)

- Hacked UsualUnaryConversions, UsualArithmeticConversions, and DefaultFunctionArrayConversion
to create the AST node (using a helper function promoteExprToType).
- Added a setType method to Expr.
- Changed Expr::isIntegerConstantExpr to allow for the new node.

llvm-svn: 39866
2007-07-15 02:02:06 +00:00
Chris Lattner 4481b428db A significant refactoring of the type size stuff to also
compute type alignment.  This info is needed for struct layout.

llvm-svn: 39850
2007-07-14 01:29:45 +00:00
Steve Naroff b8ea4fb8db More changes related to implementing ImplicitCastExpr.
- 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
2007-07-13 23:32:42 +00:00