Commit Graph

943 Commits

Author SHA1 Message Date
Fariborz Jahanian 6a128ae962 Minor test twik.
llvm-svn: 45208
2007-12-19 19:07:24 +00:00
Fariborz Jahanian a1e3420c49 This patch concludes implementation of dynamic objective-c type qualified by
protocol list.

llvm-svn: 45203
2007-12-19 17:45:58 +00:00
Chris Lattner ea72f449fe Implement C99 6.7.5.3p1
llvm-svn: 45188
2007-12-19 05:31:29 +00:00
Fariborz Jahanian 9f0e310861 Refactoring work. ObjcQualifiedIdType is now derived from 'Type'.
llvm-svn: 45174
2007-12-18 21:33:44 +00:00
Chris Lattner 20aad334c7 Fix the location we emit the "not a constant" error for this:
int foo() {
  typedef int x[foo()];
  static int y = sizeof(x);
}

previously we'd emit it on the typedef, which made not sense at all.

llvm-svn: 45154
2007-12-18 07:15:40 +00:00
Chris Lattner dcb7cc59ae Fix an nice and subtle parser bug reported by Nico Weber.
llvm-svn: 45149
2007-12-18 06:06:23 +00:00
Steve Naroff b74406ba98 Fixe bogus error for variable argument methods. Sema::ObjcGetTypeForMethodDefinition() wasn't preserving the isVariadic boolean. Another fix is to avoid synthsizing the function decl entirely, however this is a separate issue that I don't want to deal with now. Also added a FIXME to Sema::CheckFunctionCall(), which is currently emitting a bogus warning.
llvm-svn: 45146
2007-12-18 03:41:15 +00:00
Steve Naroff 1d2538cb4d Improve how we find private method decls. This involved:
- Changed Sema::ObjcActOnStartOfMethodDef() to register the methods with the global pools.
- Changed Sema::ActOnInstanceMessage() to look in global pools (should be much less error prone).
- Added a test case to message.m (for lookup that was broken).

Misc changes while I was investigating this...

- Changed Sema::ActOnAtEnd() to call AddFactoryMethodToGlobalPool (this looked like a cut/paste error).
- Added a comment and tweaked another where I was using the first person.

llvm-svn: 45142
2007-12-18 01:30:32 +00:00
Fariborz Jahanian 24cb52c9b0 Patch to implemented objective-c's dynamic object pointer qualified with
the protocol list (id<P,...> types).

llvm-svn: 45121
2007-12-17 21:03:50 +00:00
Ted Kremenek 3fbeaea7ee Modified format-string checking to not emit a warning when all of the
following hold:

(1) A vprintf-like function is called that takes the argument list via a
    via_list argument.

(2) The format string is a non-literal that is the parameter value of
    the enclosing function, e.g:
    
    void logmessage(const char *fmt,...) { 
      va_list ap;
      va_start(ap,fmt);
      fprintf(fmt,ap);  // Do not emit a warning.
    }
    
In the future this special case will be enhanced to consult the "format"
attribute attached to a function declaration instead of just allowing a blank
check for all function parameters to be used as format strings to vprintf-like
functions. This will happen when more support for attributes becomes
available.

llvm-svn: 45114
2007-12-17 19:03:13 +00:00
Steve Naroff eaaae467c7 Sema::ActOnMemberReferenceExpr() needs to perform the default conversions.
Bug and test case provided by Carl Lewis.

llvm-svn: 45078
2007-12-16 21:42:28 +00:00
Chris Lattner 3c1334013d Don't do integer promotions of LHS for compound shift assignment. The LHS has to be a modifiable lvalue.
llvm-svn: 44993
2007-12-13 07:28:16 +00:00
Fariborz Jahanian 56637d127f Fixed test to match the new diagnostic text.
llvm-svn: 44966
2007-12-13 00:16:34 +00:00
Fariborz Jahanian 4d1288a67e Concatenation of objc strings.
llvm-svn: 44964
2007-12-12 23:55:49 +00:00
Chris Lattner 6d513f37c9 Unbreak -stats on cocoa.h
llvm-svn: 44919
2007-12-12 06:43:05 +00:00
Chris Lattner b011825453 add run lines.
llvm-svn: 44918
2007-12-12 06:22:14 +00:00
Chris Lattner 47fbe949c4 fix expected errors.
llvm-svn: 44901
2007-12-12 01:15:04 +00:00
Fariborz Jahanian 27c15cca19 Add -pedantic so test passes.
llvm-svn: 44900
2007-12-12 01:06:09 +00:00
Chris Lattner e002fbea56 Add ObjC parser support for concatenated ObjC strings. Note that
this is passed to sema and ignored there, so the second part of the
string will not make it into the AST.  Passing to Fariborz to finish
Sema + AST construction.

llvm-svn: 44898
2007-12-12 01:04:12 +00:00
Fariborz Jahanian c98d956778 Implemented type checking for pointer of objects of protocol-qualified types.
Note that incompatible-protocol-qualified-types.m is currently failing. This is
unrelated to this patch and Steve is looking at the general problem of not reporting
incompitible pointer types in return stetement..

llvm-svn: 44897
2007-12-12 01:00:23 +00:00
Fariborz Jahanian 4e56ed5fab Implemented rewriting of protocol-qualified global variable types.
Re-implemented some of rewriting of protocol-qualified function 
argument types to support it in its generality.

llvm-svn: 44886
2007-12-11 22:50:14 +00:00
Fariborz Jahanian 3b5dca2533 For @optional unimplemented methods do not issue the warning.
llvm-svn: 44872
2007-12-11 19:10:26 +00:00
Steve Naroff 3f1223cb06 - Tweak several tests to be compatible with my last commit.
- Add a test to message.m for an unusual case for GCC compat (as suggested by Chris).

llvm-svn: 44842
2007-12-11 03:34:41 +00:00
Steve Naroff 91f78080e3 Add support for initializing char arrays from string literals.
Adapted from a patch by Anders Carlsson.

llvm-svn: 44816
2007-12-10 22:44:33 +00:00
Chris Lattner 4d62f42eba Implement correct semantic analysis of subtractions, implementing
C99 6.5.6.

llvm-svn: 44746
2007-12-09 21:53:25 +00:00
Fariborz Jahanian 8ea0779624 Test case for my last patch for implementation of static protocoled type
used as reciver type of a message expression.

llvm-svn: 44693
2007-12-08 01:00:55 +00:00
Fariborz Jahanian 33c0e815f3 Patch for rewriting of @protocol.
llvm-svn: 44681
2007-12-07 18:47:10 +00:00
Fariborz Jahanian 2bbd03a755 Patch to implement "Protocol" as a built-in type declared as
"@class Protocol;"

llvm-svn: 44670
2007-12-07 00:18:54 +00:00
Fariborz Jahanian 6b644a6e05 test case for my very last patch.
llvm-svn: 44662
2007-12-06 17:43:04 +00:00
Chris Lattner b36a98e9a3 Fix a bug handling typedefs of functions, patch by Nuno Lopes!
llvm-svn: 44661
2007-12-06 17:20:20 +00:00
Fariborz Jahanian d5db92ba97 Changed type-cast of "struct objc_super"'s 2nd initializer to match definition of
"struct objc_super".

llvm-svn: 44616
2007-12-05 17:29:46 +00:00
Steve Naroff 2644aaf537 Recognize CompoundLiteralExpr's as valid lvalue's.
Also updated a FIXME in Sema::CheckInitializer()...

llvm-svn: 44602
2007-12-05 04:00:10 +00:00
Fariborz Jahanian 22c278a216 Test case for my last patch.
llvm-svn: 44581
2007-12-04 21:48:54 +00:00
Fariborz Jahanian d0d2bd5089 Fixed a bug exposed by referencing an ivar field using component reference syntax.
llvm-svn: 44553
2007-12-03 22:25:42 +00:00
Chris Lattner e5a91b4924 Fix an ast-print/ast-dump bug.
llvm-svn: 44550
2007-12-03 21:43:25 +00:00
Bill Wendling db4e34984b Fix for testcase that assigns a dereferenced reference to a pointer. The
standard says that we should adjust the "reference to T" type to "T"
before analysis.

llvm-svn: 44530
2007-12-03 07:33:35 +00:00
Chris Lattner 6311b58000 all filevar's have static storage. Previously a global with
extern storage class was returning false from hasStaticStorage.
Ted, please review this.

llvm-svn: 44515
2007-12-02 07:47:49 +00:00
Anders Carlsson e1af1d20ef Support lax vector conversions.
llvm-svn: 44449
2007-11-30 04:21:22 +00:00
Ted Kremenek 2501c8294f Fixed test case to not expect a warning when one should not be emitted.
Removed redundant test case.

llvm-svn: 44426
2007-11-29 01:03:21 +00:00
Ted Kremenek 0865d8a5d0 Added test cases for -Wfloat-equal to test comparisons against literals that can be
represented exactly and inexactly by APFloats. For the former, we do not emit a
warning.

llvm-svn: 44425
2007-11-29 01:00:11 +00:00
Ted Kremenek ab18e6d7fd Added missing "RUN:" to comment for test case file. This fixed a bug where the test
case testing the frontend's support of statement expressions was not being
executed.

llvm-svn: 44409
2007-11-28 19:05:11 +00:00
Chris Lattner db2a6ef881 Fix a bug checking for 'int foo(void)' that didn't look through typedefs of void.
Bug pointed out by Michael Zolda, thanks!

llvm-svn: 44408
2007-11-28 18:51:29 +00:00
Anders Carlsson 299f2fc648 Add more intrinsics. We can now correctly parse both Carbon.h and Cocoa.h without having to do -arch ppc.
llvm-svn: 44392
2007-11-28 05:19:59 +00:00
Chris Lattner da22eeca44 add several cases that Expr::hasStaticStorage missed, pointed out by Oliver Hunt
llvm-svn: 44376
2007-11-27 21:35:27 +00:00
Steve Naroff 0ee0b0ab8c Move the null pointer constant check from Sema::CheckSingleInitializer/ActOnCallExpr/CheckMessageArgumentTypes/ActOnReturnStmt to Sema::CheckSingleAssignmentConstraints. This makes sure all null pointer assignments are considered compatible.
Thanks to Seo Sanghyeon for the bug, follow-through, and patch!

llvm-svn: 44366
2007-11-27 17:58:44 +00:00
Anders Carlsson de71adff60 Report errors for invalid casts from/to vectors.
llvm-svn: 44350
2007-11-27 05:51:55 +00:00
Ted Kremenek 6eefb85ef5 Fixed #include of objc/objc.h so that it works on case-sensitive filesystems.
llvm-svn: 44337
2007-11-26 22:49:09 +00:00
Fariborz Jahanian a883d6ed89 Patch to fix a regression caused by recent rewrite changes.
A potential API bug in ReplaceText pending (A FIXME is added).

llvm-svn: 44333
2007-11-26 19:52:57 +00:00
Bill Wendling 8da1db4f34 The checking for the delimiters of expected error/warning messages was
looking only for { and } instead of {{ and }}. Changed it to check for
this explicitly.

llvm-svn: 44326
2007-11-26 08:26:20 +00:00
Anders Carlsson 290aa8560b Check that the clobber registers are valid.
llvm-svn: 44311
2007-11-25 00:25:21 +00:00
Ted Kremenek 33407b3338 Moved dead-stores test cast to a new test suite subdirectory: Analysis.
llvm-svn: 44305
2007-11-24 19:49:35 +00:00
Anders Carlsson 80a5ea3552 Check asm input and output expressions.
llvm-svn: 44289
2007-11-23 19:43:50 +00:00
Chris Lattner 5c3f1541a7 Improve function decl merging, patch by Oliver Hunt!
llvm-svn: 44253
2007-11-20 19:04:50 +00:00
Ted Kremenek 9e823c745d Added another test case for the Dead Stores checker that tests that
block-level expressions are evaluated the same as regular expressions. Test
case provided by Nuno Lopes.

llvm-svn: 44247
2007-11-20 03:03:00 +00:00
Ted Kremenek eb8471bfa1 Added test case for dead stores checker (live variables analysis) that tests
for correct propagation/update of liveness information within subexpressions
of Block-Level expressions.  Test case provided by Nuno Lopes.

llvm-svn: 44225
2007-11-19 06:38:23 +00:00
Ted Kremenek 094079c0dc Added test case for dead-stores checker. Test case provided by Nuno Lopes.
llvm-svn: 44221
2007-11-18 20:06:35 +00:00
Chris Lattner 48d52848d7 Tighten up address-of checking, implementing test/Sema/expr-address-of.c.
This fixes a bug reported by Seo Sanghyeon.

This was meant to be committed yesterday, but the commit failed.  doh.

llvm-svn: 44190
2007-11-16 17:46:48 +00:00
Chris Lattner 07b201d9c0 implement test/Sema/typedef-prototype.c, allowing code
to declare a function with a typedef:

typedef int unary_int_func(int arg);
unary_int_func add_one;

This patch contributed by Seo Sanghyeon!

llvm-svn: 44100
2007-11-14 06:34:38 +00:00
Fariborz Jahanian bc92fd7542 Type encoding for structs.
llvm-svn: 44087
2007-11-13 23:21:38 +00:00
Fariborz Jahanian 989e03989b Fixed a rewrite of metadata bug when category implementation has no matching interface.
llvm-svn: 44072
2007-11-13 22:09:49 +00:00
Ted Kremenek 794d8a6cde Updated test case to flag about comparisons against constants. We may
invert this case (i.e., not flag a warning) in the future.

llvm-svn: 44059
2007-11-13 19:18:22 +00:00
Ted Kremenek b83f182b59 Modified -Wfloat-equal logic to suppress warnings where floating point values
are compared against builtins such as __builtin_inf.

llvm-svn: 44058
2007-11-13 19:17:00 +00:00
Ted Kremenek 2272f72723 Added -Wfloat-equal option to the driver. This makes warnings about
floating point comparisons using == or != an opt-in rather than a default
warning.

Updated test case to use -Wfloat-equal.

llvm-svn: 44053
2007-11-13 18:37:02 +00:00
Chris Lattner 2f72c427cf improve handling of address of global when checking for
constants and initializers.  Patch by Sanghyeon Seo, thanks!

llvm-svn: 44049
2007-11-13 18:05:45 +00:00
Fariborz Jahanian 21f54eeacf Patch to do statically typed ivar references.
llvm-svn: 44028
2007-11-12 22:29:28 +00:00
Steve Naroff cac26f4f5f This is the last 5% of the solution to teaching Sema::ActOnInstanceMessage() about private methods (r43989).
While the diff is large, the idea is very simple. When we parse method definitions (in an @implementation), we need to add them incrementally (rather than wait until the @end).

Other details...

- Renamed Sema::ActOnAddMethodsToObjcDecl() to Sema::ActOnAtEnd(). The methods are now optional arguments.
- Removed Parser::AllImplMethods (a nice cleanup).
- Added location info to ObjcImplementationDecl (since we will need it very soon:-)
- Modified message.m test to no longer allow the bogus diagnostic.

llvm-svn: 43995
2007-11-11 17:19:15 +00:00
Steve Naroff 5f9ae64f6e Make sure Sema::CheckIncrementDecrementOperand() removes typedefs when doing it's analysis.
Thanks to Seo Sanghyeon for his excellent (first) bug fix!

llvm-svn: 43994
2007-11-11 14:15:57 +00:00
Steve Naroff 22e078e013 Teach Sema::ActOnInstanceMessage() about private methods. That is, methods declared in an implementation (but not listed in the interface).
This commit is only 95% of the bug fix. The last piece to this puzzle is to add the method decls to the implementation incrementally (as we encounter them). At the moment, the methods aren't added until we see an @end (which is too late).

I will complete this later...

llvm-svn: 43989
2007-11-11 00:10:47 +00:00
Fariborz Jahanian 16e3123071 pretty priting for method definitions.
llvm-svn: 43986
2007-11-10 20:59:13 +00:00
Steve Naroff 257b4a2467 Fix a basic bug (having to do with typedefs) in Sema::UsualArithmeticConversions().
This resuled in the following crash below.

Also modified the usual-float.c test case to capture this case.

[steve-naroffs-imac:clang/test/Sema] snaroff% ../../../../Debug/bin/clang usual-float.c
Assertion failed: (0 && "Sema::UsualArithmeticConversions(): illegal float comparison"), function UsualArithmeticConversions, file SemaExpr.cpp, line 960.
0   clang                               0x001ef9b9 _ZN40_GLOBAL__N_Signals.cpp_00000000_4E6DAF8315PrintStackTraceEv + 45
1   clang                               0x001efd5f _ZN40_GLOBAL__N_Signals.cpp_00000000_4E6DAF8313SignalHandlerEi + 323
2   libSystem.B.dylib                   0x90c6297b _sigtramp + 43
3   ???                                 0xffffffff 0x0 + 4294967295
4   libSystem.B.dylib                   0x90cdb782 raise + 26
5   libSystem.B.dylib                   0x90cead3f abort + 73
6   libSystem.B.dylib                   0x90cdc923 __assert_rtn + 101
7   clang                               0x00077316 _ZN5clang4Sema26UsualArithmeticConversionsERPNS_4ExprES3_b + 1004
8   clang                               0x000803cf _ZN5clang4Sema27CheckMultiplyDivideOperandsERPNS_4ExprES3_NS_14SourceLocationEb + 181
9   clang                               0x0007a8e8 _ZN5clang4Sema10ActOnBinOpENS_14SourceLocationENS_3tok9TokenKindEPvS4_ + 472
10  clang                               0x000cf058 _ZN5clang6Parser26ParseRHSOfBinaryExpressionENS_6Action12ActionResultILj0EEEj + 1286
11  clang                               0x000cf2de _ZN5clang6Parser25ParseAssignmentExpressionEv + 86

llvm-svn: 43985
2007-11-10 19:45:54 +00:00
Fariborz Jahanian b5605179c4 Added class context to method declarations. Provide "interface *" type
to 'self' method of instance methods.

llvm-svn: 43957
2007-11-09 19:52:12 +00:00
Fariborz Jahanian 19d4dbd217 Insert invisble arguments to method definition header.
llvm-svn: 43948
2007-11-09 17:18:29 +00:00
Chris Lattner 45d561ad99 improve decl merging logic to be more correct with
functions.  Patch contributed by Nuno Lopes, thanks!

llvm-svn: 43757
2007-11-06 06:07:26 +00:00
Chris Lattner 3209725c68 Add better validation for array types when merging decls. Patch
contributed by Oliver Hunt, thanks!

llvm-svn: 43750
2007-11-06 04:28:31 +00:00
Fariborz Jahanian ac73ff8868 Remaining work to collect objective-c's type qualifiers and use them to encode
method types.

llvm-svn: 43617
2007-11-01 17:18:37 +00:00
Chris Lattner c3ebf29ef6 Implement test/Sema/init.c by treating functions as constants.
llvm-svn: 43599
2007-11-01 02:45:17 +00:00
Fariborz Jahanian 95b6076c77 Fixed problem with rewriting stand-alone @implementation (with no matching @interface).
A new test case added.

llvm-svn: 43568
2007-10-31 18:48:14 +00:00
Fariborz Jahanian 4d5b2baa1c Fixed tests.
llvm-svn: 43513
2007-10-30 20:41:57 +00:00
Fariborz Jahanian 18d7b30241 Revisited my last patch to be able to do encoding of ivar types with 'id'.
llvm-svn: 43507
2007-10-30 18:27:03 +00:00
Fariborz Jahanian 509d8d6fc6 Added type encoding for 'id' type.
llvm-svn: 43504
2007-10-30 17:06:23 +00:00
Ted Kremenek 5d18ce750a Added to test case for "self-comparison check" uses of relation operators: x < x and x > x
should emit warnings.

llvm-svn: 43451
2007-10-29 17:02:56 +00:00
Ted Kremenek e451eae8d7 For non-floating point types, added check for expressions of the form
"x == x" and "x != x".  We emit a warning for these since they always evaluate
to a constant value and often indicate a logical error.

Added test case for this check.

llvm-svn: 43450
2007-10-29 16:58:49 +00:00
Ted Kremenek d4ecc6da67 For checking for floating point comparison using == or !=, we now suppress
errors for cases such as "x == x".

Added test case to test this feature.

llvm-svn: 43447
2007-10-29 16:40:01 +00:00
Chris Lattner 5c5808a9a3 improve error recovery handling broken 'then' or 'else' stmts in
if statements.  This implements Sema/if-empty-body.c:f3, silencing
a bogus secondary warning.  It also improve the location info for
the nullstmts created for recovery purposes.

llvm-svn: 43440
2007-10-29 05:08:52 +00:00
Chris Lattner 3bc4d20862 casting to void is ok for structs (C99 6.5.4p2), this fixes
one bogus error on PR1750.

llvm-svn: 43436
2007-10-29 04:26:44 +00:00
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 648e029a3d Include a simple test case for the previous commit...
llvm-svn: 43158
2007-10-19 00:05:15 +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
Steve Naroff a3f1336e39 rename test file for builtin "id"...
llvm-svn: 43082
2007-10-17 18:39:04 +00:00
Steve Naroff 0f7a2d2dd1 Predefine all the ObjC goodies from <objc/objc.h>. Removed all the ObjC goodies from the respective test files. Moving forward, it will be very nice to assume these builtin!
llvm-svn: 43077
2007-10-17 17:53:50 +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
Steve Naroff 077c83bddb Add Sema::CheckMessageArgumentTypes()...
llvm-svn: 43050
2007-10-16 23:12:48 +00:00
Fariborz Jahanian ebac2cb235 Patch to diagnose duplicate method implementations.
llvm-svn: 43046
2007-10-16 21:52:23 +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
Fariborz Jahanian d4b3015dd7 Several name lookup conflict detection fixes involving objective-c names.
llvm-svn: 43000
2007-10-15 19:16:57 +00:00
Anders Carlsson b30f47a869 Fix a warning
llvm-svn: 42973
2007-10-15 02:50:04 +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 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
Steve Naroff b213da2a70 Temporary fix to test case. This area is currently under construction...test case will be changing again soon.
llvm-svn: 42914
2007-10-12 16:15:17 +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
Fariborz Jahanian 70e8f1024a Patch to create protocol conforming class types.
llvm-svn: 42856
2007-10-11 00:55:41 +00:00
Chris Lattner 5e4c75f4ef rename -parse-ast-print to -ast-print
rename -parse-ast-dump to -ast-dump
remove -parse-ast, which is redundant with -fsyntax-only

llvm-svn: 42852
2007-10-11 00:18: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 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 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
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 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
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
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
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 e6d9ca5443 objc messages have side effects, return true from hasLocalSideEffect,
fixing:

VoidMethod.m:14:5: warning: expression result unused
    [Greeter hello];
    ^~~~~~~~~~~~~~~

llvm-svn: 42380
2007-09-26 22:06:30 +00:00
Ted Kremenek 0883fd5817 Removed option "-parse-ast-check" from clang driver. This is now implemented
using "-parse-ast -verify".

Updated all test cases (using a sed script) that invoked -parse-ast-check to
now use -parse-ast -verify.

Fixed a bug where using "-verify" instead of "-parse-ast-check" would not
correctly create the DiagClient needed to accumulate diagnostics.

llvm-svn: 42365
2007-09-26 20:14:22 +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
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
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
Fariborz Jahanian 39d641f526 Patch to add objective-c's @protocl type declaration.
llvm-svn: 42060
2007-09-17 21:07:36 +00:00
Fariborz Jahanian aefb23092c Semantic analysis for objective-c ivars.
llvm-svn: 41954
2007-09-14 16:27:55 +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
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
Chris Lattner 73ab7fa9c6 disable this for now.
llvm-svn: 41701
2007-09-04 16:49:09 +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
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
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
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
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
Chris Lattner 8718fcf35e a new testcase
llvm-svn: 41614
2007-08-30 17:51:09 +00:00
Chris Lattner fec2519b4b -C mode doesn't return comments on "#" lines, so the diag checker doesn't pick them up.
Test this the hard way.

llvm-svn: 41605
2007-08-30 06:38:49 +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
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 35da3e29dd extwarn about VLAs in C89 mode.
llvm-svn: 41545
2007-08-28 16:54:00 +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 613cef84b4 new testcase
llvm-svn: 41541
2007-08-28 16:20:14 +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 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 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
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 e026ebd6fe steve's recent changes fixed this bogus warning.
llvm-svn: 41432
2007-08-26 06:48:28 +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
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
Chris Lattner c4e7a66036 Test that cocoa parses with -parse-noop. In the future
(when ready) this test should change to test -fsyntax-only.

llvm-svn: 41307
2007-08-23 01:08:54 +00:00
Chris Lattner 91b9a4c8c3 we now correctly emit:
unused-expr.c:8:6: warning: comparison of distinct pointer types ('int volatile *' and 'int *')
  VP == P;
  ~~ ^  ~

llvm-svn: 41210
2007-08-21 01:19:46 +00:00
Ted Kremenek 9fcbb10e86 Added test cases for the return-stack-address checker to test support
for the following C++ casts: static_cast, reinterpret_cast, and const_cast.

llvm-svn: 41181
2007-08-20 16:28:05 +00:00
Ted Kremenek cb173fc7d0 Added extra test case to check proper handling of archaic array indexing: 4[A]
llvm-svn: 41147
2007-08-17 22:17:23 +00:00
Anders Carlsson 98f0790fab Add initial support for constant CFStrings.
llvm-svn: 41136
2007-08-17 05:31:46 +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
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
Chris Lattner 374b06a080 the sse intrinsics are missing, leading to errors.
llvm-svn: 40800
2007-08-04 00:19:10 +00:00
Chris Lattner 30709dc432 oops, this is the real fix.
llvm-svn: 40766
2007-08-02 22:41:43 +00:00
Chris Lattner 7aa350019a update test
llvm-svn: 40765
2007-08-02 22:36:03 +00:00
Chris Lattner 181b01bcfd make sure we don't lose the ability to parse carbon.h
llvm-svn: 40759
2007-08-02 21:40:29 +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
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 fd5e05f5ce testcase from neil
llvm-svn: 40173
2007-07-21 05:32:22 +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 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 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
Chris Lattner 5b2f6970c1 I forgot to check this in earlier
llvm-svn: 39958
2007-07-17 04:58:06 +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
Chris Lattner 51aff8bd7c Remove an extraneous QualType from CastExpr, it's type is always
the result type of the expr node.

Implement isIntegerConstantExpr for ImplicitCastExpr nodes the same
was as for CastExpr nodes.

Implement proper sign/zero extension as well as truncation and noop
conversion in the i-c-e evaluator.  This allows us to correctly
handle i-c-e's like these:

char array[1024/(sizeof (long))];
int x['\xBb' == (char) 187 ? 1: -1];

this implements test/Sema/i-c-e2.c

llvm-svn: 39888
2007-07-15 23:54:50 +00:00
Chris Lattner 35ed92817a Unspecified type specs default to int. This fixes a crash
on test/Sema/implicit-int.c

llvm-svn: 39833
2007-07-13 21:02:29 +00:00
Chris Lattner effb7a350f new testcase that crashes the cfe due to implicit conversion fun
llvm-svn: 39826
2007-07-13 20:11:01 +00:00
Chris Lattner c4c8e2546b New testcase for unused expression analysis
llvm-svn: 39683
2007-06-27 05:58:33 +00:00
Chris Lattner 43312241ea new testcase
llvm-svn: 39609
2007-06-08 17:58:14 +00:00
Chris Lattner c81f079d7e move void argument checking from the parser to the semantic analysis stage.
This allows us to handle typedefs of void correctly.  This implements
clang/test/Sema/void_arg.c

llvm-svn: 39236
2006-12-03 02:43:54 +00:00
Chris Lattner eda517e456 new testcase
llvm-svn: 39195
2006-11-20 07:03:41 +00:00