Commit Graph

2323 Commits

Author SHA1 Message Date
Eli Friedman 42d2a3add6 Attempt to fix PR3709: when converting from an integer to a pointer,
first extend the integer to the correct width.

llvm-svn: 66009
2009-03-04 04:02:35 +00:00
Ted Kremenek d69e29e8c4 This test now passes using RegionStore.
llvm-svn: 65988
2009-03-04 00:23:28 +00:00
Steve Naroff 013813dd5d Change a warning to an error...
llvm-svn: 65978
2009-03-03 23:13:51 +00:00
Fariborz Jahanian 9a8e759b4f Implement an important missing warning when a selector
is searched for in the global pool. It already uncovered 
a clang bug in message selection.

llvm-svn: 65974
2009-03-03 22:19:15 +00:00
Steve Naroff c03f6b91b1 Fix <rdar://problem/5982579> [clang on xcode] (using arch=x86_64): synthesized property 'sdkPath' must either be named the same as a compatible ivar or must explicitly name an ivar.
llvm-svn: 65973
2009-03-03 22:09:41 +00:00
Steve Naroff 27ed6f6766 Fix <rdar://problem/6252237> [sema] qualified id should be disallowed in @catch statements.
llvm-svn: 65969
2009-03-03 21:16:54 +00:00
Steve Naroff 39d6fba0d6 Fix <rdar://problem/6632061> [sema] non object types should not be allowed in @catch statements.
llvm-svn: 65968
2009-03-03 20:59:06 +00:00
Fariborz Jahanian eab5ecd8e0 Fixed an ir-gen bug in syntheszing a getter function
with property type which does not match its ivar and
in -fobjc-gc-only mode!

llvm-svn: 65955
2009-03-03 18:49:40 +00:00
Steve Naroff b0e25c1ceb Remove old/incorrect warnings.
llvm-svn: 65950
2009-03-03 15:49:23 +00:00
Steve Naroff 3e1181e2e9 Fix <rdar://problem/6497242> Inherited overridden protocol declared objects don't work.
Change Sema::DiagnosePropertyMismatch() to check for type compatibility (rather than type equivalence, which is too strict).

llvm-svn: 65949
2009-03-03 15:43:24 +00:00
Steve Naroff 157599fe1c Fix <rdar://problem/6497608> clang does not catch ivar type mismatches in @implementation.
llvm-svn: 65948
2009-03-03 14:49:36 +00:00
Eli Friedman 4735374e39 PR3691: Add support for complex modes. I also tossed in support for XF
while I was at it.  There are still a lot of diagnostics missing from 
this code, and it isn't completely correct for anything other than x86, but 
it should work correctly on x86 for valid cases.

llvm-svn: 65935
2009-03-03 06:41:03 +00:00
Eli Friedman 78350edafb Fix for PR3687: use the memory representation for booleans when a
sub-type describes a memory location, like the pointee type of a pointer
or the element type of an array.

llvm-svn: 65925
2009-03-03 04:48:01 +00:00
Douglas Gregor 463421deb1 Implement the basics of implicit instantiation of class templates, in
response to attempts to diagnose an "incomplete" type. This will force
us to use DiagnoseIncompleteType more regularly (rather than looking at
isIncompleteType), but that's also a good thing.

Implicit instantiation is still very simplistic, and will create a new
definition for the class template specialization (as it should) but it
only actually instantiates the base classes and attaches
those. Actually instantiating class members will follow. 

Also, instantiate the types of non-type template parameters before
checking them,  allowing, e.g., 

  template<typename T, T Value> struct Constant; 
 
to work properly.

llvm-svn: 65924
2009-03-03 04:44:36 +00:00
Fariborz Jahanian a458c4ff65 Check of ivar access access control.
llvm-svn: 65912
2009-03-03 01:21:12 +00:00
Steve Naroff f3833d70be Fix <rdar://problem/6635908> crash on invalid
llvm-svn: 65909
2009-03-03 00:45:38 +00:00
Zhongxing Xu 6765d449ed Add test case for pointer arithmetic.
llvm-svn: 65907
2009-03-03 00:28:42 +00:00
Chris Lattner 5a9a892e48 fix PR#
llvm-svn: 65906
2009-03-03 00:00:26 +00:00
Fariborz Jahanian bf8e842b67 Diagnose a variety of access of ivars when they conflict with
local or global variables in instance/class methods.

llvm-svn: 65879
2009-03-02 21:55:29 +00:00
Chris Lattner e29509a6e1 fix PR2639
llvm-svn: 65869
2009-03-02 20:58:48 +00:00
Fariborz Jahanian 33afd771b4 Check for duplicate declaration of method of a class
in its extension.

llvm-svn: 65854
2009-03-02 19:05:07 +00:00
Daniel Dunbar e2e704752c Attempt to make test more robust (fails for users who put LLVM in
/path/with/store/in/it").

llvm-svn: 65852
2009-03-02 18:50:36 +00:00
Daniel Dunbar 51adf5824e Rename lib/Driver (etc) to lib/Frontend in prep for the *actual*
driver taking lib/Driver.

llvm-svn: 65811
2009-03-02 06:16:29 +00:00
Mike Stump 0e425b8200 Push checking down, also, give the user a hit as to which part of the
block literal is causing the problem, instead of the vague reference
to the entire block literal.

llvm-svn: 65798
2009-03-02 03:04:42 +00:00
Douglas Gregor 5a80bd1504 Rework the way we find locally-scoped external declarations when we
need them to evaluate redeclarations or call a function that hasn't
already been declared. We now keep a DenseMap of these locally-scoped
declarations so that they are not visible but can be quickly found,
e.g., when we're looking for previous declarations or before we go
ahead and implicitly declare a function that's being called. Fixes
PR3672.

llvm-svn: 65792
2009-03-02 00:19:53 +00:00
Steve Naroff 8676e08730 Fix <rdar://problem/6248764> parser rejects: bad receiver type 'CFStringRef'.
Downgrade an error to a warning (for GCC compatibility).

llvm-svn: 65779
2009-03-01 17:14:31 +00:00
Douglas Gregor 5741efbba0 Fix PR3509 by providing correct starting locations for initializer lists
llvm-svn: 65777
2009-03-01 17:12:46 +00:00
Steve Naroff 114aecb26b Fix <rdar://problem/6619539> incompatible pointer types sending 'XCElementSpacer *', expected 'XCElement *' (not handling protocol signatures correctly?).
- Reworked ASTContext::canAssignObjCInterfaces().
- Added ObjCProtocolDecl::lookupProtocolNamed().

llvm-svn: 65773
2009-03-01 16:12:44 +00:00
Chris Lattner d3fd8fb3ac testcase for mike's fix for PR3612
llvm-svn: 65757
2009-03-01 03:26:22 +00:00
Daniel Dunbar 53f12b11dc This test requires blocks.
llvm-svn: 65754
2009-03-01 02:20:08 +00:00
Anders Carlsson 961763e35a Emit errors about unsupported blocks features.
llvm-svn: 65751
2009-03-01 01:45:25 +00:00
Anders Carlsson ed5e69fe50 Do some blocks cleanup and simplification. Fix a crash, and add a test case.
llvm-svn: 65746
2009-03-01 01:09:12 +00:00
Chris Lattner e87da66562 adjust to changes in the mainline llvm .ll printer.
llvm-svn: 65745
2009-03-01 00:59:19 +00:00
Chris Lattner 9ef10f4638 "This patch uses the new ObjCImplDecl class to merge Sema::ImplMethodsVsClassMethods and Sema::ImplCategoryMethodsVsIntfMethods methods.
And now, when clang check a class implementation to find unimplemented methods, it also checks all methods from the class extensions (unnamed categories).

There is also a test case to check this warning.

This patch contains also a minor update for ObjCImplDecl . getNameAsCString and getNameAsString now returns an empty string instead of crashing for unnamed categories."

Patch by Jean-Daniel Dupas!

llvm-svn: 65744
2009-03-01 00:56:52 +00:00
Anders Carlsson 6c885805cd Fix invalid VLAs/VMs in Sema::ActOnVariableDeclarator, so that the variable will have the right type by the time the initializer is checked. This ensures that code like
int a[(int)(1.0 / 1.0) = { 1 } will work.

Eli, please review.
 

llvm-svn: 65725
2009-02-28 21:56:50 +00:00
Fariborz Jahanian bac73acc24 Obscure code gen bug related to sending
message to 'super' in a class method declared in
cateogy (darwin specific).

llvm-svn: 65709
2009-02-28 20:07:56 +00:00
Chris Lattner 309e48695b Fix a crash in test/Parser/control-scope.c that testrunner didn't
notice because it was a negative test with a fix suggested by
Jean-Daniel Dupas.  Convert the test from a negative to a positive
test to catch stuff like this.

llvm-svn: 65708
2009-02-28 19:37:57 +00:00
Chris Lattner 3ef668c27a after going around in circles a few times, finally cave and emit structure
copies with memcpy instead of memmove.  This matches what GCC does and if it
causes a problem with a particular libc we can always fix it with a target
hook.

llvm-svn: 65699
2009-02-28 18:18:58 +00:00
Steve Naroff d123bd05ca Fix <rdar://problem/6451399> problems with labels and blocks.
- Move the 'LabelMap' from Sema to Scope. To avoid layering problems, the second element is now a 'StmtTy *', which makes the LabelMap a bit more verbose to deal with.
- Add 'ActiveScope' to Sema. Managed by ActOnStartOfFunctionDef(), ObjCActOnStartOfMethodDef(), ActOnBlockStmtExpr().
- Changed ActOnLabelStmt(), ActOnGotoStmt(), ActOnAddrLabel(), and ActOnFinishFunctionBody() to use the new ActiveScope.
- Added FIXME to workaround in ActOnFinishFunctionBody() (for dealing with C++ nested functions).  

llvm-svn: 65694
2009-02-28 16:48:43 +00:00
Eli Friedman cba899ff7b Check a few more kinds of declarations that make a scope.
llvm-svn: 65680
2009-02-28 06:22:14 +00:00
Eli Friedman f69d09bae5 Start of checking for gotos which jump to an illegal destination.
As far as I know, this catches all cases of jumping into the scope of a 
variable with a variably modified type (excluding statement 
expressions) in C.  This is missing some stuff we probably want to check
(other kinds of variably modified declarations, statement expressions, 
indirect gotos/addresses of labels in a scope, ObjC @try/@finally, cleanup 
attribute), the diagnostics aren't very good, and it's not particularly 
efficient, but it's a decent start.

This patch is a slightly modified version of the patch I attached to
PR3259, and it fixes that bug.  I was sort of planning on improving 
it, but I think it's okay as-is, especially since it looks like CodeGen 
doesn't have any use for this sort of data structure.  The only 
significant change I can think of from the version I attached to PR3259 
is that this version skips running the checking code when a function 
doesn't contain any labels.

This patch doesn't cover case statements, which also need similar 
checking; I'm not sure how we should deal with that. Extending the goto 
checking to also check case statements wouldn't be too hard; it's just a 
matter of keeping track of the scope of the closest switch and checking that
the scope of every case is the same as the scope of the switch.  That said, 
it would likely be a performance hit to run this check on every 
function (it's an extra pass over the entire function), so we probably want
some other solution.

llvm-svn: 65678
2009-02-28 05:41:13 +00:00
Eli Friedman a1c7b6c5f6 Fix obvious shortcoming in the implementations of Evaluate for
integer __real__ and __imag__.  Not sure how I missed this.

llvm-svn: 65677
2009-02-28 03:59:05 +00:00
Douglas Gregor 6eaaf30968 Template instantiation for function types
llvm-svn: 65668
2009-02-28 01:04:19 +00:00
Douglas Gregor 17c0d7bacf Implement template instantiation for pointer, reference, and (some)
array types. Semantic checking for the construction of these types has
been factored out of GetTypeForDeclarator and into separate
subroutines (BuildPointerType, BuildReferenceType,
BuildArrayType). We'll be doing the same thing for all other types
(and declarations and expressions).

As part of this, moved the type-instantiation functions into a class
in an anonymous namespace. 

llvm-svn: 65663
2009-02-28 00:25:32 +00:00
Fariborz Jahanian f5c1c923e8 Diagnose gc attribute mismatch of property and its ivar.
llvm-svn: 65656
2009-02-27 22:38:11 +00:00
Douglas Gregor fe1e11092e Implement the basic approach for instantiating types, with a lot of FIXME'd
stubs for those types we don't yet know how to instantiate (everything
that isn't a template parameter!).

We now instantiate default arguments for template type parameters when
needed. This will be our testbed while I fill out the remaining
type-instantiation logic.

llvm-svn: 65649
2009-02-27 19:31:52 +00:00
Chris Lattner 7b0ec8a9df upgrade various 'implicit int' warnings from an ext-warn to warning when not
in C89 mode.  This makes it enabled by default instead of only enabled with
-pedantic.  Clang defaults to c99 mode, so people will see this more often
than with GCC, but they can always use -std=c89 if they really want c89.

llvm-svn: 65647
2009-02-27 18:53:28 +00:00
Ted Kremenek 9723bcf60f When checking printf-arguments for functions with '__attribute__ ((format (printf, X, Y)))'
set HasVAListArg to true when 'Y' is 0 (i.e., ignore the data arguments).

This fixes <rdar://problem/6623513>.

llvm-svn: 65642
2009-02-27 17:58:43 +00:00
Chris Lattner 7094c15d7e change a diagnostic message from something pedantically correct but
useless to something more vague but hopefully more clear.
rdar://6624173

llvm-svn: 65639
2009-02-27 17:15:01 +00:00
Daniel Dunbar 13454cfcb0 Oops, Ted beat me to it. I'll just play angry god and remove his version!
llvm-svn: 65638
2009-02-27 17:10:38 +00:00
Daniel Dunbar 8d42281150 Add coverage of "member of anonymous union redeclares ..." diagnostic.
llvm-svn: 65637
2009-02-27 17:07:01 +00:00
Ted Kremenek dd34e06eeb Add test case for PR 3675.
llvm-svn: 65635
2009-02-27 16:48:08 +00:00
Eli Friedman 988a16b9b8 Change the AST generated for offsetof a bit so that it looks like a
normal expression, and change Evaluate and IRGen to evaluate it like a 
normal expression.  This simplifies the code significantly, and fixes 
PR3396.

llvm-svn: 65622
2009-02-27 06:44:11 +00:00
Eli Friedman 8d03f59479 Some additional ICE tests.
llvm-svn: 65614
2009-02-27 04:46:32 +00:00
Chris Lattner 09e592ea33 rename test
llvm-svn: 65587
2009-02-26 23:36:18 +00:00
Chris Lattner 7ec0bb6bc0 ok, not as broken as I thought, just confusing. This allows
initialization of wchar_t arrays with wide strings, and generalizes
wchar_size.c to work on all targets.

llvm-svn: 65586
2009-02-26 23:36:02 +00:00
Fariborz Jahanian 7285cf57a3 Do not issue bogus error on __weak/__strong ivar access.
llvm-svn: 65583
2009-02-26 23:05:51 +00:00
Chris Lattner d42c29f9a2 fix some sema problems with wide strings and hook up basic codegen for them.
llvm-svn: 65582
2009-02-26 23:01:51 +00:00
Douglas Gregor 87f95b0a6a Introduce code modification hints into the diagnostics system. When we
know how to recover from an error, we can attach a hint to the
diagnostic that states how to modify the code, which can be one of:

  - Insert some new code (a text string) at a particular source
    location
  - Remove the code within a given range
  - Replace the code within a given range with some new code (a text
    string)

Right now, we use these hints to annotate diagnostic information. For
example, if one uses the '>>' in a template argument in C++98, as in
this code:

  template<int I> class B { };
  B<1000 >> 2> *b1;

we'll warn that the behavior will change in C++0x. The fix is to
insert parenthese, so we use code insertion annotations to illustrate
where the parentheses go:

test.cpp:10:10: warning: use of right-shift operator ('>>') in template
argument will require parentheses in C++0x
  B<1000 >> 2> *b1;
         ^
    (        )


Use of these annotations is partially implemented for HTML
diagnostics, but it's not (yet) producing valid HTML, which may be
related to PR2386, so it has been #if 0'd out.

In this future, we could consider hooking this mechanism up to the
rewriter to actually try to fix these problems during compilation (or,
after a compilation whose only errors have fixes). For now, however, I
suggest that we use these code modification hints whenever we can, so
that we get better diagnostics now and will have better coverage when
we find better ways to use this information.

This also fixes PR3410 by placing the complaint about missing tokens
just after the previous token (rather than at the location of the next
token).

llvm-svn: 65570
2009-02-26 21:00:50 +00:00
Steve Naroff de68001e76 Fix <rdar://problem/6574319> clang issues error on 'readonly' property with a defaul setter attribute.
Needed to make isPropertyReadonly() non-const (for this fix to compile). I imagine there's a way to retain the const-ness, however I have more important fish to fry.

llvm-svn: 65562
2009-02-26 19:11:32 +00:00
Mike Stump 92000e54ac Add end of line at end.
llvm-svn: 65557
2009-02-26 19:00:14 +00:00
Steve Naroff 42ab0dd1ee Fix <rdar://problem/6614945> method not found.
This was a fairly recent regression.

llvm-svn: 65547
2009-02-26 18:16:19 +00:00
Anders Carlsson 43e8a2b36e Add test for enum types
llvm-svn: 65540
2009-02-26 17:38:19 +00:00
Steve Naroff b162f170da Fix http://llvm.org/bugs/show_bug.cgi?id=3544.
The code for looking up local/private method in Sema::ActOnInstanceMessage() was not handling categories properly. Sema::ActOnClassMessage() didn't have this bug.
Created a helper with the correct logic and changed both methods to use it.

llvm-svn: 65532
2009-02-26 15:55:06 +00:00
Sebastian Redl 8d2ccae28b Make more AST nodes and semantic checkers dependent-expression-aware.
llvm-svn: 65529
2009-02-26 14:39:58 +00:00
Steve Naroff 8ec2784f58 Fix ObjCInterfaceDecl::lookupInstanceMethod()/lookupClassMethod() to search in inherited protocols.
Also changed ObjCInterfaceDecl::lookupClassMethod() to look through a categories protocols.

Test/patch submitted by Jean-Daniel Dupas (thanks!).

llvm-svn: 65526
2009-02-26 11:32:02 +00:00
Eli Friedman adf40d4bef Fix for PR3663/3669: use TryToFixInvalidVariablyModifiedType for
variable declarations where applicable.  Also, a few fixes to 
TryToFixInvalidVariablyModifiedType for issues that this exposed.

llvm-svn: 65500
2009-02-26 03:58:54 +00:00
Douglas Gregor 8d0921617e Use RecordFirst/RecordLast range checks in DeclContext
llvm-svn: 65489
2009-02-26 00:02:51 +00:00
Douglas Gregor d54dfb8718 Implementing parsing of template-ids as class-names, so that we can
derive from a class template specialization, e.g.,

  class B : public A<int> { };

llvm-svn: 65488
2009-02-25 23:52:28 +00:00
Douglas Gregor cbb45d0c65 Cope with use of the token '>>' inside a template argument list, e.g.,
vector<vector<double>> Matrix;

In C++98/03, this token always means "right shift". However, if we're in
a context where we know that it can't mean "right shift", provide a
friendly reminder to put a space between the two >'s and then treat it
as two >'s as part of recovery.

In C++0x, this token is always broken into two '>' tokens.

llvm-svn: 65484
2009-02-25 23:02:36 +00:00
Ted Kremenek dc3f50fbd9 Add experimental logic in GRExprEngine::EvalEagerlyAssume() to handle
expressions of the form: 'short x = (y != 10);' While we handle 'int x = (y !=
10)' lazily, the cast to another integer type currently loses the symbolic
constraint. Eager evaluation of the constraint causes the paths to bifurcate and
eagerly evaluate 'y != 10' to a constant of 1 or 0. This should address
<rdar://problem/6619921> until we have a better (more lazy approach) for
handling promotions/truncations of symbolic integer values.

llvm-svn: 65480
2009-02-25 22:32:02 +00:00
Douglas Gregor 1e249f8641 Improve location information on "reused" class template specialization
decls. Test and document the semantic location of class template
specialization definitions that occur within a scope enclosing the
scope of the class template.

llvm-svn: 65478
2009-02-25 22:18:32 +00:00
Douglas Gregor f47b911f6e Perform additional semantic checking of class template
specializations. In particular:

  - Make sure class template specializations have a "template<>"
    header, and complain if they don't.
  - Make sure class template specializations are declared/defined
    within a valid context. (e.g., you can't declare a specialization
    std::vector<MyType> in the global namespace).

llvm-svn: 65476
2009-02-25 22:02:03 +00:00
Daniel Dunbar 4208835eec Temporarily disable clearing of insert point (to indicate unreachable
code) when calling noreturn functions; general expression emission
isn't ready to do the right thing in all cases.

llvm-svn: 65473
2009-02-25 20:59:29 +00:00
Daniel Dunbar 1cdbc5404b Allow constant initializers to reference their defining decl.
- PR3662.

llvm-svn: 65472
2009-02-25 20:08:33 +00:00
Douglas Gregor 441f24118a Include the appropriate header for malloc
llvm-svn: 65471
2009-02-25 19:48:02 +00:00
Douglas Gregor 7f74112756 Implement parsing of nested-name-specifiers that involve template-ids, e.g.,
std::vector<int>::allocator_type

When we parse a template-id that names a type, it will become either a
template-id annotation (which is a parsed representation of a
template-id that has not yet been through semantic analysis) or a
typename annotation (where semantic analysis has resolved the
template-id to an actual type), depending on the context. We only
produce a type in contexts where we know that we only need type
information, e.g., in a type specifier. Otherwise, we create a
template-id annotation that can later be "upgraded" by transforming it
into a typename annotation when the parser needs a type. This occurs,
for example, when we've parsed "std::vector<int>" above and then see
the '::' after it. However, it means that when writing something like
this:

  template<> class Outer::Inner<int> { ... };

We have two tokens to represent Outer::Inner<int>: one token for the
nested name specifier Outer::, and one template-id annotation token
for Inner<int>, which will be passed to semantic analysis to define
the class template specialization.

Most of the churn in the template tests in this patch come from an
improvement in our error recovery from ill-formed template-ids.

llvm-svn: 65467
2009-02-25 19:37:18 +00:00
Anders Carlsson f2f2e7f6a1 Use CheckAssignmentConstraints for checking the cleanup attr function. Fixes PR3656.
llvm-svn: 65461
2009-02-25 17:19:08 +00:00
Douglas Gregor 739ef0c183 C99 DR #316 implies that the function parameter types that are known
only from a function definition (that does not have a prototype) are
only used to determine the compatible with other declarations of that
same function. In particular, when referencing the function we pretend
as if it does not have a prototype. Implement this behavior, which
fixes PR3626.

llvm-svn: 65460
2009-02-25 16:33:18 +00:00
Daniel Dunbar a1047857f7 Remove a FIXME; I was mistaken in believing gcc rejected this.
llvm-svn: 65420
2009-02-25 00:22:25 +00:00
Chris Lattner d8b741c85f handle @encode interactions with array initializers.
llvm-svn: 65401
2009-02-24 23:10:27 +00:00
Chris Lattner 0cb7803341 move some initialization checking code from SemaDecl.cpp
to SemaInit.cpp, no functionality change.

llvm-svn: 65394
2009-02-24 22:27:37 +00:00
Chris Lattner d7e7b8e411 first wave of fixes for @encode sema support. This is part of PR3648.
The big difference here is that (like string literal) @encode has 
array type, not pointer type.

llvm-svn: 65391
2009-02-24 22:18:39 +00:00
Douglas Gregor eddf4333fd When we're declaring an object or function with linkage, teach name
lookup to skip over names without linkage. This finishes
<rdar://problem/6127293>.

llvm-svn: 65386
2009-02-24 20:03:32 +00:00
Douglas Gregor 5d68a20949 Extend the implicit declaration and checking against out-of-scope
external declarations to also support external variable
declarations. Unified the code for these two cases into two new
subroutines.

Note that we fail to diagnose cases like the one Neil pointed
out, where a visible non-external declaration hides an external
declaration by the same name. That will require some reshuffling of
name lookup.

llvm-svn: 65385
2009-02-24 19:23:27 +00:00
Daniel Dunbar d4ecca135a Fix IRgen of constant expressions referring to external/static
variables.
 - PR3657.

llvm-svn: 65381
2009-02-24 18:41:57 +00:00
Chris Lattner 59da739613 Fix PR3635 by handling ## magically
llvm-svn: 65374
2009-02-24 05:29:33 +00:00
Douglas Gregor de681d43eb In C, when we see a function declaration within a local scope, export
that declaration to global scope so that it can be found from other
scopes. This allows us to diagnose redeclaration errors for external
declarations across scopes. We also warn when name lookup finds such
an out-of-scope declaration. This is part of <rdar://problem/6127293>;
we'll also need to do the same thing for variables.

llvm-svn: 65373
2009-02-24 04:26:15 +00:00
Ted Kremenek cce27f5502 Fix <rdar://problem/6611677>: Add basic transfer function support in the static
analyzer for array subscript expressions involving bases that are vectors. This
solution is probably a hack: it gets the lvalue of the vector instead of an
rvalue like all other types. This should be reviewed (big FIXME in
GRExprEngine).

llvm-svn: 65366
2009-02-24 02:23:11 +00:00
Daniel Dunbar 94ceb61574 Fix two @synchronized bugs found by inspection: the expression to sychronize on should only be evaluated once, and it is evaluated outside the cleanup scope.
Also, lift SyncEnter and SyncExit up in nervous anticipation of x86-64
zero cost EH.

llvm-svn: 65362
2009-02-24 01:43:46 +00:00
Douglas Gregor e62c0a45dd Improve merging of function declarations. Specifically:
- When we are declaring a function in local scope, we can merge with
    a visible declaration from an outer scope if that declaration
    refers to an entity with linkage. This behavior now works in C++
    and properly ignores entities without linkage.
  - Diagnose the use of "static" on a function declaration in local
    scope.
  - Diagnose the declaration of a static function after a non-static
    declaration of the same function.
  - Propagate the storage specifier to a function declaration from a
    prior declaration (PR3425)
  - Don't name-mangle "main"

llvm-svn: 65360
2009-02-24 01:23:02 +00:00
Chris Lattner d13b8b55ca fix rdar://6611778, a redefinition of an interface was causing an
assertion when the ivars and method list was reset into the existing
interface.  To fix this, mark decls as invalid when they are redefined,
and don't insert ivars/methods into invalid decls.

llvm-svn: 65340
2009-02-23 22:00:08 +00:00
Steve Naroff a94e52c687 - Generate error for protocol qualifiers on 'Class'.
- Generate error for protocol qualifiers on non-ObjC types.

llvm-svn: 65333
2009-02-23 18:53:24 +00:00
Steve Naroff 91362dd011 Revert http://llvm.org/viewvc/llvm-project?view=rev&revision=65244.
Remove support for "Class<P>". Will be making this an error.

llvm-svn: 65332
2009-02-23 18:36:16 +00:00
Eli Friedman 3ae5911042 A few small improvements to Evaluate for stuff I noted in FIXMEs.
llvm-svn: 65305
2009-02-23 04:23:56 +00:00
Ted Kremenek e73f282213 retain/release checker: For now don't track the retain count of NSWindow objects (opt for false negatives).
llvm-svn: 65304
2009-02-23 02:51:29 +00:00
Ted Kremenek e6d2b40bcc More retain/release naming convention tests.
llvm-svn: 65303
2009-02-23 02:50:20 +00:00
Ted Kremenek 5fa0d070a5 Add test case for PR 2599.
llvm-svn: 65299
2009-02-23 01:29:25 +00:00
Steve Naroff c4173fa704 Contains the following (related to problems found while investigting <rdar://problem/6497631> Message lookup is sometimes different than gcc's).
- Implement instance/class overloading in ObjCContainerDecl (removing a FIXME). This involved hacking NamedDecl::declarationReplaces(), which took awhile to figure out (didn't realize replace was the default).
- Changed Sema::ActOnInstanceMessage() to remove redundant warnings when dealing with protocols. For now, I've omitted the "protocol" term in the diagnostic. It simplifies the code flow and wan't always 100% accurate (e.g. "Foo<Prot>" looks in the class interface, not just the protocol).
- Changed several test cases to jive with the above changes.

llvm-svn: 65292
2009-02-22 19:35:57 +00:00
Mike Stump 624497c29a Cleanp code with some recent suggestions.
llvm-svn: 65285
2009-02-22 13:27:11 +00:00
Eli Friedman fd85266342 Fix test to be legal on 64-bit systems.
llvm-svn: 65270
2009-02-22 07:40:57 +00:00
Eli Friedman 7bfab36877 Throw the switch to exclusively use Evaluate (along with the small
helper isConstantInitializer) to check whether an initializer is 
constant.  This passes tests, but it's possible that it'll cause 
regressions with real-world code.

Future work:
1. The diagnostics obtained this way are lower quality at the moment; 
some work both here and in Evaluate is needed for accurate diagnostics.
2. We probably need some extra code when we're in -pedantic mode so we 
can strictly enforce the rules in C99 6.6p7.
3. Dead code cleanup (this should wait until after 2, because we might 
want to re-use some of the code).

llvm-svn: 65265
2009-02-22 06:45:27 +00:00
Eli Friedman 3f8c01a110 Fix for PR3433: map __alignof__ to preferred alignment. (This was
partially done in r65258.)

llvm-svn: 65260
2009-02-22 03:31:23 +00:00
Eli Friedman 19a546c15b Improvements to ASTContext::getDeclAlignInBytes; fixes the testcase in
PR3254 and part of PR3433.

The isICE changes are necessary to keep the computed results 
consistent with Evaluate.

llvm-svn: 65258
2009-02-22 02:56:25 +00:00
Anders Carlsson b8482c5d5d Match gcc and always perform array/function conversion for asm input exprs. Fixes PR3641.
llvm-svn: 65256
2009-02-22 02:11:23 +00:00
Anders Carlsson d05f44b5ca Correctly encode incomplete and variable length arrays. Fixes PR3639.
llvm-svn: 65255
2009-02-22 01:38:57 +00:00
Eli Friedman 2194bb78ec Sanity fix for PR3642: if we're treating a diagnostic as an error, it's
required to actually be an error for correctness.  The attached testcase 
now gives an error instead of mysteriously crashing.

Now, it's possible we actually want to support the given usage, but I 
haven't looked at the relevant code closely.

llvm-svn: 65253
2009-02-22 00:20:44 +00:00
Daniel Dunbar 9cbbd99c4b Force arch for these test cases.
llvm-svn: 65252
2009-02-21 23:45:41 +00:00
Steve Naroff 670e72ddc7 Add support for GCC ObjC extension "Class<protocol>". Sigh.
Found while researching <rdar://problem/6497631> Message lookup is sometimes different than gcc's.

Will never be seen in user code. Needed to pass dejagnu testsuite.

llvm-svn: 65244
2009-02-21 20:17:11 +00:00
Steve Naroff cd8d572283 Warn about bogus protocol qualifiers.
llvm-svn: 65241
2009-02-21 19:50:43 +00:00
Fariborz Jahanian 0c9404e0a7 Warn on use of __weak attribute on local
variable (objc2 gc specific).

llvm-svn: 65240
2009-02-21 19:44:02 +00:00
Fariborz Jahanian ccfd554024 Fixed an ICE in meta-data generation of __weak/__strong ivars.
llvm-svn: 65235
2009-02-21 18:23:24 +00:00
Daniel Dunbar 79e042a8b5 Evaluation of unary deref could call integer evaluator on non-integral
expr; hilarity ensued.
 - PR3640.

llvm-svn: 65234
2009-02-21 18:14:20 +00:00
Steve Naroff da88fb9c73 Add test case to record a couple inconsistencies with GCC (found in <rdar://problem/6561076> [clang on Xcode] warning: cannot find protocol definition for 'OzzyP').
Removing the "cannot find protocol" warning is trivial if necessary (but I don't think it's the right thing to do).

llvm-svn: 65232
2009-02-21 17:03:43 +00:00
Steve Naroff 7a7814c32b This fixes <rdar://problem/6497650> More type mismatches issues with clang.
Move two key ObjC typechecks from Sema::CheckPointerTypesForAssignment() to ASTContext::mergeTypes().

This allows us to take advantage of the recursion in ASTContext::mergeTypes(), removing some bogus warnings.

This test case I've added includes an example where we still warn (and GCC doesn't). Need to talk with folks and decide what to do. At this point, the major bogosities should be fixed.

llvm-svn: 65231
2009-02-21 16:18:07 +00:00
Ted Kremenek 8a73c71486 Improved naming convention heuristics in the retain/release checker to better
handle method names that contain 'new', 'copy', etc., but those words might be
the substring of larger words such as 'newsgroup' and 'photocopy' that do not
indicate the allocation of objects. This should address the issues discussed in
<rdar://problem/6552389>.

llvm-svn: 65224
2009-02-21 05:13:43 +00:00
Daniel Dunbar 3c81dabd76 Emit extern_weak when needed.
- PR3629.

llvm-svn: 65203
2009-02-21 00:24:10 +00:00
Daniel Dunbar 0c4eda5923 We must always mangle attribute overloadable functions; even if in a
system header.
 - Prevents a codegen crash when anything used anything in tgmath! :)

llvm-svn: 65200
2009-02-20 23:09:27 +00:00
Steve Naroff 326064168a Fix <rdar://problem/6500554> missing objc error message.
llvm-svn: 65198
2009-02-20 22:59:16 +00:00
Anders Carlsson c4c6031859 Always try to fold array sizes, and warn if we could fold something that isn't an ICE. This makes us compatible with GCC.
llvm-svn: 65140
2009-02-20 18:53:20 +00:00
Daniel Dunbar ce39954d5d Handle constant int -> ptr casts of lvalue results.
- PR3463 (again).

llvm-svn: 65133
2009-02-20 18:22:23 +00:00
Daniel Dunbar cdbb5e336d Set call attribute for direct calls (i.e. noreturn).
- Remove an unused variant of EmitCallExpr overload.

llvm-svn: 65130
2009-02-20 18:06:48 +00:00
Steve Naroff 17b2f5d728 Fix <rdar://problem/6586239> bitfield constraints not enforced (for ObjC)
llvm-svn: 65128
2009-02-20 17:57:11 +00:00
Daniel Dunbar e4be42c17f Add some stdlib builtins
llvm-svn: 65115
2009-02-20 06:36:40 +00:00
Eli Friedman 7157825d44 Use -verify for consistency.
llvm-svn: 65106
2009-02-20 02:03:47 +00:00
Eli Friedman 0b8337c30b Add support for * (unary dereference) operator to ExprConstant.
llvm-svn: 65105
2009-02-20 01:57:15 +00:00
Eli Friedman ce98257691 Suppress constant initializer checking when the declaration isn't valid.
This prevents emitting diagnostics which are almost certainly useless.

(Note that the test is checking that we emit only one diagnostic.)

llvm-svn: 65101
2009-02-20 01:34:21 +00:00
Ted Kremenek a26ad40e41 Add test case for <rdar://problem/6562655>.
llvm-svn: 65085
2009-02-20 00:10:09 +00:00
Chris Lattner 810d330cd3 Fix a long standard problem with clang retaining "too much" sugar
information about types.  We often print diagnostics where we say 
"foo_t" is bad, but the user doesn't know how foo_t is declared 
(because it is a typedef).  Fix this by expanding sugar when present
in a diagnostic (and not one of a few special cases, like vectors).

Before:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' and 'typeof(F)')
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                             ^

After:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                             ^

llvm-svn: 65081
2009-02-19 23:45:49 +00:00
Daniel Dunbar 1c8560d93e Extend Evaluate() to fold (int) <pointer type>.
- PR3463, PR3398, <rdar://problem/6553401> crash on relocatable
   symbol addresses as constants in static locals.

 - There are many more scenarious we could handle (like arithmetic on
   such an int) but this is the main use case.

llvm-svn: 65074
2009-02-19 22:24:01 +00:00
Daniel Dunbar 96f8677e11 Arguments to unordered comparison builtins may need implicit casts.
- <rdar://problem/6094103> sema fails to promote type arguments to __builtin_isgreater (and friends)

llvm-svn: 65059
2009-02-19 19:28:43 +00:00
Anders Carlsson f96954ca30 Add irgen support for the noinline attribute.
llvm-svn: 65056
2009-02-19 19:22:11 +00:00
Anders Carlsson 880971241b Add sema support for the noinline attribute.
llvm-svn: 65055
2009-02-19 19:16:48 +00:00
Ted Kremenek bea465aefb Update test case to include a leak that occurs at the place of allocation.
llvm-svn: 65048
2009-02-19 18:20:28 +00:00
Zhongxing Xu e6e76aa571 fix test case
llvm-svn: 65037
2009-02-19 08:45:23 +00:00
Zhongxing Xu 5b9223fcf2 add test case.
llvm-svn: 65036
2009-02-19 08:42:43 +00:00
Daniel Dunbar f0acf7bd4c Don't emit K&R unprototyped function definitions as varargs.
- <rdar://problem/6584606> clang/x86-64 - too many reg saves

llvm-svn: 65032
2009-02-19 07:15:39 +00:00
Anders Carlsson 0756c97dae Emit the correct diagnostics when we constant fold an array size to a negative value.
llvm-svn: 65023
2009-02-19 06:30:50 +00:00
Anders Carlsson 0bbcfa6bb9 Make sure to check the value of the constant expression, as suggested by Daniel.
llvm-svn: 65021
2009-02-19 06:19:15 +00:00
Daniel Dunbar b2f4cdb233 Emission of global variable initialializer was broken in rare
situation where a tentative decl was emitted *after* the actual
initialization. This occurs in some rare situations with static decls.
 - PR3613.

 - I'm not particularly happy with this fix, but I don't see a simpler
   or more elegant solution yet.

llvm-svn: 65018
2009-02-19 05:36:41 +00:00
Anders Carlsson ef56fbaa39 Handle the GNU void* and function pointer arithmetic extensions for constant expressions as well.
llvm-svn: 65013
2009-02-19 04:55:58 +00:00
Ted Kremenek e571c4eeb7 Add test case for 'nil receiver returns undefined struct value' check.
llvm-svn: 65004
2009-02-19 04:07:38 +00:00
Douglas Gregor 0f3dd9a86b Provide a proper source location when building an implicit dereference. Fixes PR3600
llvm-svn: 64993
2009-02-19 00:52:42 +00:00
Douglas Gregor 120951391c Make error-message check platform-agnostic
llvm-svn: 64985
2009-02-19 00:03:13 +00:00
Douglas Gregor 1cba5fe1d1 Downgrade the "excess elements in initializer" errors to warnings *in
C*. They're required errors in C++.

llvm-svn: 64964
2009-02-18 22:23:55 +00:00
Ted Kremenek 443e040d06 Add a few more GC-only test cases for the retain/release checker.
llvm-svn: 64960
2009-02-18 22:11:23 +00:00
Douglas Gregor 222e5e4ad2 Return true on errors, return true on errors, return true on errors
llvm-svn: 64957
2009-02-18 22:00:45 +00:00
Douglas Gregor 171c45ab0c Downgrade complaints about calling unavailable functions to a warning
(as GCC does), except when we've performed overload resolution and
found an unavailable function: in this case, we actually error.

Merge the checking of unavailable functions with the checking for
deprecated functions. This unifies a bit of code, and makes sure that
we're checking for unavailable functions in the right places. Also,
this check can cause an error. We may, eventually, want an option to
make "unavailable" warnings into errors.

Implement much of the logic needed for C++0x deleted functions, which
are effectively the same as "unavailable" functions (but always cause
an error when referenced). However, we don't have the syntax to
specify deleted functions yet :)

llvm-svn: 64955
2009-02-18 21:56:37 +00:00
Daniel Dunbar aac5bf19a5 __attribute__((aligned)) was being ignored!
This knocks out another 8 gcc/compat/i386 & x86_64 failures.

llvm-svn: 64947
2009-02-18 20:06:09 +00:00
Chris Lattner f638b97fe0 use the full spelling of a string literal token so that trigraphs
and escaped newlines don't throw off the offset computation.

On this testcase:
  printf("abc\
def"
         "%*d", (unsigned) 1, 1);

Before:
t.m:5:5: warning: field width should have type 'int', but argument has type 'unsigned int'
def"
    ^

after:
t.m:6:12: warning: field width should have type 'int', but argument has type 'unsigned int'
         "%*d", (unsigned) 1, 1);
           ^    ~~~~~~~~~~~~

llvm-svn: 64930
2009-02-18 18:34:12 +00:00