Commit Graph

10168 Commits

Author SHA1 Message Date
John McCall 3f4138c5d0 In debugger mode, make ObjC message sends to unknown selectors return
__unknown_anytype, and rewrite such message sends correctly.

I had to bite the bullet and actually add a debugger support mode for this
one, which is a bit unfortunate, but there really isn't anything else
I could imagine doing;  this is clearly just debugger-specific behavior.

llvm-svn: 135051
2011-07-13 17:56:40 +00:00
Fariborz Jahanian c0f6af2103 objc++: Some level of covariance is allowed in ObjC properties.
Make it also available in ObjC++ propeties. // rdar://9740328

llvm-svn: 135001
2011-07-12 22:05:16 +00:00
Peter Collingbourne 77b0e7f296 Implement -MG. Fixes PR9613
llvm-svn: 134996
2011-07-12 19:35:15 +00:00
Fariborz Jahanian 7f4427fc60 Fix a bug where a local variable named 'self' is causing
implicit ivar accesses to go through the 'self' variable
rather than the real 'self' for the method. // rdar://9730771

llvm-svn: 134992
2011-07-12 17:16:56 +00:00
Douglas Gregor 2207ec273a Improve name mangling for instantiation-dependent types that are not
dependent. This covers an odd class of types such as

  int (&)[sizeof(sizeof(T() + T()))];

which involve template parameters but, because of some trick typically
involving a form of expression that is never type-dependent, resolve
down to a non-dependent type. Such types need to be mangled
essentially as they were written in the source code (involving
template parameters), rather than via their canonical type.

In general, instantiation-dependent types should be mangled as
they were written in the source. However, since we can't do that now
without non-trivial refactoring of the AST (see the new FIXME), I've
gone for this partial solution: only use the as-written-in-the-source
mangling for these strange types that are instantiation-dependent but
not dependent. This provides better compatibility with previous
incarnations of Clang and with GCC. In the future, we'd like to get
this right.

Fixes <rdar://problem/9663282>.

llvm-svn: 134984
2011-07-12 15:18:55 +00:00
Douglas Gregor 4a80f9fd98 Fix the desugaring of dependent decltype and typeof(expr) nodes. The
isSugared() and desugar() routines previously provided were never
actually called, since the corresponding types
(DependentTypeOfExprType, DependentDecltypeType) don't have
corresponding type classes. Outside of the current (incomplete) patch
I'm working on, I haven't found a way to trigger this problem.

llvm-svn: 134973
2011-07-12 06:55:29 +00:00
Argyrios Kyrtzidis 9b72b0c7d5 Move OBJC_PR_NumBits out of PropertyAttributeKind enum, to its own NumPropertyAttrsBits.
No functionality change.

llvm-svn: 134965
2011-07-12 04:52:08 +00:00
Douglas Gregor 842806450c Centralize the getCanonicalType() calls in the Itanium C++ mangling
code so that they only occur in a single place. No functionality change.

llvm-svn: 134961
2011-07-12 04:42:08 +00:00
Argyrios Kyrtzidis 52bfc2b668 [ARC] Complain about property without storage attribute when @synthesizing it, not at its declaration.
For this sample:

@interface Foo
@property id x;
@end

we get:

t.m:2:1: error: ARC forbids properties of Objective-C objects with unspecified storage attribute
@property  id x;
^
1 error generated.

The error should be imposed on the implementor of the interface, not the user. If the user uses
a header of a non-ARC library whose source code he does not have, we are basically asking him to
go change the header of the library (bad in general), possible overriding how the property is
implemented if he gets confused and says "Oh I'll just add 'copy' then" (even worse).

Second issue is that we don't emit any error for 'readonly' properties, e.g:

@interface Foo
@property (readonly) id x; // no error  here
@end

@implementation Foo
@synthesize x; // no error here too
@end

We should give an error when the implementor is @synthesizing a property which doesn't have
any storage specifier; this is when the explicit specifier is important, because we are
going to create an ivar and we want its ownership to be explicit.

Related improvements:
-OBJC_PR_unsafe_unretained turned out to not fit in ObjCPropertyDecl's bitfields, fix it.
-For properties of extension classes don't drop PropertyAttributesAsWritten values.
-Have PropertyAttributesAsWritten actually only reflect what the user wrote

rdar://9756610.

llvm-svn: 134960
2011-07-12 04:30:16 +00:00
Eli Friedman 6290ae476e Add diagnostic for constructs like "va_arg(l, float)" which have undefined behavior. PR10201.
llvm-svn: 134926
2011-07-11 21:45:59 +00:00
Argyrios Kyrtzidis f89cc69eac [arcmt] Move the remapping functions to clang-c/Index.h and change 'arcmt_' prefix to 'clang_'.
llvm-svn: 134916
2011-07-11 20:15:00 +00:00
Fariborz Jahanian 256d39d47d objc-arc: Diagnose when captured variable in block literals
require destruction and there is possibility of that without
construction. Thanks Johnm for review and suggestions offline.
// rdar://9535237.

llvm-svn: 134906
2011-07-11 18:04:54 +00:00
Chandler Carruth d517395248 Apply patch from Richard Trieu to fix PR9548:
When two different types has the same text representation in the same
diagnostic message, print an a.k.a. after the type if the a.k.a. gives extra
information about the type.

class versa_string;

typedef versa_string string;

namespace std {template <typename T> class vector;}

using std::vector;

void f(vector<string> v);

namespace std {
class basic_string;
typedef basic_string string;
template <typename T> class vector {};
void g() {
  vector<string> v;
  f(v);
}
}

Old message:
----------------
test.cc:15:3: error: no matching function for call to 'f'
  f(&v);
  ^
test.cc:7:6: note: candidate function not viable: no known conversion from
      'vector<string>' to 'vector<string>' for 1st argument
void f(vector<string> v);
     ^
1 error generated.

New message:
---------------
test.cc:15:3: error: no matching function for call to 'f'
  f(v);
  ^
test.cc:7:6: note: candidate function not viable: no known conversion from
      'vector<string>' (aka 'std::vector<std::basic_string>') to
      'vector<string>' (aka 'std::vector<versa_string>') for 1st argument
void f(vector<string> v);
     ^
1 error generated.

llvm-svn: 134904
2011-07-11 17:49:21 +00:00
Abramo Bagnara 612f6dc4e9 Added removeBitWidth method.
llvm-svn: 134891
2011-07-11 08:43:20 +00:00
Francois Pichet 4ad2a27065 Change __debugbreak signature to void __debugbreak(void); MSVC compatibility.
llvm-svn: 134869
2011-07-10 14:15:07 +00:00
Argyrios Kyrtzidis 7fbd97f641 [arcmt] Introduce new '-ccc-arcmt-migrate <path>' ARC migration driver option.
This is a new mode of migration, where we avoid modifying the original files but
we emit temporary files instead.

<path> will be used to keep migration process metadata. Currently the temporary files
that are produced are put in the system's temp directory but we can put them
in the <path> if is necessary.

Also introduce new ARC migration functions in libclang whose only purpose,
currently, is to accept <path> and provide pairs of original file/transformed file
to map from the originals to the files after transformations are applied.

Finally introduce the c-arcmt-test utility that exercises the new libclang functions,
update arcmt-test, and add tests for the whole process.

rdar://9735086.

llvm-svn: 134844
2011-07-09 20:00:58 +00:00
Cameron Zwarich ae7bc98710 Add codegen support for the fma/fmal/fmaf builtins.
llvm-svn: 134743
2011-07-08 21:39:34 +00:00
Fariborz Jahanian f2913401fc objc++-arc: more diagnosis of converting a weak-unavailable
object to a __weak object type. // rdar://9732636

llvm-svn: 134706
2011-07-08 17:41:42 +00:00
Chandler Carruth 402bb38823 Keep track of which source locations are part of a macro argument
instantiation and improve diagnostics which are stem from macro
arguments to trace the argument itself back through the layers of macro
expansion.

This requires some tricky handling of the source locations, as the
argument appears to be expanded in the opposite direction from the
surrounding macro. This patch provides helper routines that encapsulate
the logic and explain the reasoning behind how we step through macros
during diagnostic printing.

This fixes the rest of the test cases originially in PR9279, and later
split out into PR10214 and PR10215.

There is still some more work we can do here to improve the macro
backtrace, but those will follow as separate patches.

llvm-svn: 134660
2011-07-07 23:56:36 +00:00
Fariborz Jahanian 7fcce6829d objc++-arc: diagnose assignment/cast of a weak-unavailable
object to a __weak object/type. // rdar://9732636.
One item is yet todo.

llvm-svn: 134655
2011-07-07 23:04:17 +00:00
Jonathan D. Turner f8c3ccdeae Remove BoostCon-specific code from Clang. FWIW, I'm a fan of things like this living in a separate branch.
llvm-svn: 134649
2011-07-07 22:40:15 +00:00
Argyrios Kyrtzidis 61c58f7f43 Move SourceManager::isAt[Start/End]OfMacroInstantiation functions to the Lexer, since they depend on it now.
llvm-svn: 134644
2011-07-07 21:54:45 +00:00
Cameron Zwarich be652e6a24 r134634 causes a failure on MultiSource/Benchmarks/Olden/bh with TEST=nightly,
so roll it out.

llvm-svn: 134638
2011-07-07 21:03:28 +00:00
Nick Lewycky d755e6ac48 A redeclaration of an inline method in C99 mode should trigger emission of that
function. Fixes PR10233!

llvm-svn: 134634
2011-07-07 20:25:10 +00:00
Alexis Hunt efa6776719 Undo r134587 as the bug was actually a deep and hideous one in the
client code.

My bad.

llvm-svn: 134631
2011-07-07 20:14:21 +00:00
Fariborz Jahanian 6f472e803b objc-arc: diagnose assignment/cast of a weak-unavailable
object to a __weak object/type. // rdar://9732636.
This is objc side of things. objc++ side tbd.

llvm-svn: 134624
2011-07-07 18:55:47 +00:00
Douglas Gregor 2132584d36 Introduce a new libclang aPI function,
clang_codeCompleteGetContexts(), that provides the client with
information about the context in which code completion has occurred
and what kinds of entities make sense as completions at that
point. Patch by Connor Wakamo!

llvm-svn: 134615
2011-07-07 16:03:39 +00:00
John McCall 4db5c3c83a In ARC, reclaim all return values of retainable type, not just those
where we have an immediate need of a retained value.

As an exception, don't do this when the call is made as the immediate
operand of a __bridge retain.  This is more in the way of a workaround
than an actual guarantee, so it's acceptable to be brittle here.

rdar://problem/9504800

llvm-svn: 134605
2011-07-07 06:58:02 +00:00
Argyrios Kyrtzidis c44b93d772 [arcmt] Add -ccc-arcmt-check/-ccc-arcmt-modify driver option aliases.
llvm-svn: 134591
2011-07-07 04:00:39 +00:00
Argyrios Kyrtzidis 41fb2d95a3 Make the Preprocessor more memory efficient and improve macro instantiation diagnostics.
When a macro instantiation occurs, reserve a SLocEntry chunk with length the
full length of the macro definition source. Set the spelling location of this chunk
to point to the start of the macro definition and any tokens that are lexed directly
from the macro definition will get a location from this chunk with the appropriate offset.

For any tokens that come from argument expansion, '##' paste operator, etc. have their
instantiation location point at the appropriate place in the instantiated macro definition
(the argument identifier and the '##' token respectively).
This improves macro instantiation diagnostics:

Before:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

After:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:3:20: note: instantiated from:
\#define M(op) (foo op 3);
                ~~~ ^  ~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

The memory savings for a candidate boost library that abuses the preprocessor are:

- 32% less SLocEntries (37M -> 25M)
- 30% reduction in PCH file size (900M -> 635M)
- 50% reduction in memory usage for the SLocEntry table (1.6G -> 800M)

llvm-svn: 134587
2011-07-07 03:40:34 +00:00
Argyrios Kyrtzidis c8f7e213b9 Fix bug in SourceManager::getDecomposedInstantiationLocSlowCase.
It would add up relative (decomposed) offsets like in getDecomposedSpellingLocSlowCase, but while
it makes sense to preserve the offset among lexed spelling locations, it doesn't make
sense to add anything to the offset of the instantiation location. The instantiation
location will be the same regardless of the relative offset in the tokens that were
instantiated.

This bug didn't actually affect anything because, currently, in practice we never create macro
locations with relative offset greater than 0.

llvm-svn: 134586
2011-07-07 03:40:27 +00:00
Alexis Hunt 197ec69ba7 Ensure that we actually visit function parameter declarations with
RecursiveASTVisitor.

This deficiency was discovered while working with the AST matcher
framework and likely impacts other users of RecursiveASTMatcher who
previously weren't seeing these Decls in their visitation.

Patch reviewed by Chandler Carruth.

llvm-svn: 134562
2011-07-06 23:35:33 +00:00
Douglas Gregor 53e191ed94 Properly implement the scope restriction on the NRVO for
throw-expressions, such that we don't consider the NRVO when the
non-volatile automatic object comes from outside the innermost try
scope (C++0x [class.copymove]p13). In C++98/03, our ASTs were
incorrect but it didn't matter because IR generation doesn't actually
apply the NRVO here. In C++0x, however, we were moving from an object
when in fact we should have copied from it. Fixes PR10142 /
<rdar://problem/9714312>.

llvm-svn: 134548
2011-07-06 22:04:06 +00:00
Fariborz Jahanian c6ba959ab1 Some code cleanup of r134522
llvm-svn: 134529
2011-07-06 20:48:48 +00:00
Fariborz Jahanian 1f626d6fd1 objc-arc: Support objc_arc_weak_unavailable on those
classes which are incompatible with weak references.
// rdar://9693477

llvm-svn: 134522
2011-07-06 19:24:05 +00:00
Douglas Gregor 8a60bbe13f Keep track of when "unrecoverable" errors occur, then allow
clang_saveTranslationUnit() to save a PCH file if the only errors it
contains are recoverable errors. Fixes <rdar://problem/9727804>.

llvm-svn: 134503
2011-07-06 17:40:26 +00:00
Douglas Gregor 30c80fa3eb libclang: Allow callers of clang_saveTranslationUnit() to distinguish
between different classes of errors. Addresses most of
<rdar://problem/9660328>.

llvm-svn: 134495
2011-07-06 16:43:36 +00:00
Chandler Carruth b4836ea7a8 Build up statistics about the work done for analysis based warnings.
Special detail is added for uninitialized variable analysis as this has
serious performance problems than need to be tracked.

Computing some of this data is expensive, for example walking the CFG to
determine its size. To avoid doing that unless the stats data is going
to be used, we thread a bit into the Sema object to track whether
detailed stats should be collected or not. This bit is used to avoid
computations whereever the computations are likely to be more expensive
than checking the state of the flag. Thus, counters are in some cases
unconditionally updated, but the more expensive (and less frequent)
aggregation steps are skipped.

With this patch, we're able to see that for 'gcc.c':
*** Analysis Based Warnings Stats:
232 functions analyzed (0 w/o CFGs).
  7151 CFG blocks built.
  30 average CFG blocks per function.
  1167 max CFG blocks per function.
163 functions analyzed for uninitialiazed variables
  640 variables analyzed.
  3 average variables per function.
  94 max variables per function.
  96409 block visits.
  591 average block visits per function.
  61546 max block visits per function.

And for the reduced testcase in PR10183:
*** Analysis Based Warnings Stats:
98 functions analyzed (0 w/o CFGs).
  8526 CFG blocks built.
  87 average CFG blocks per function.
  7277 max CFG blocks per function.
68 functions analyzed for uninitialiazed variables
  1359 variables analyzed.
  19 average variables per function.
  1196 max variables per function.
  2540494 block visits.
  37360 average block visits per function.
  2536495 max block visits per function.

That last number is the somewhat scary one that indicates the problem in
PR10183.

llvm-svn: 134494
2011-07-06 16:21:37 +00:00
Douglas Gregor 5c70b06feb Teach the static analyzer's interpretation of Cocoa conventions to
obey the objc_method_family attribute when provided. Fixes
<rdar://problem/9726279>.

llvm-svn: 134493
2011-07-06 16:00:34 +00:00
Rafael Espindola ba195cff81 Use attributes from the definition (if available) when
instantiating functions.

Fixes PR10272.

llvm-svn: 134491
2011-07-06 15:46:09 +00:00
John McCall 21878760a4 Fixed enum types can be complete without actually being valid to use
as scope specifiers;  diagnose the attempt, rather than letting it go
to an assert.  The rest of PR10264.

llvm-svn: 134479
2011-07-06 06:57:57 +00:00
Douglas Gregor a98034a25e Improve the Python bindings for libclang in a few ways, from Eli
Bendersky. Specifically: 

* Implemented a new function in libclang: clang_isAttribute

* Fixing TranslationUnit.get_includes to only go through the argument
* buffer when it contains something. This fixed a crash on Windows 

* clang_getFileName returns CXString, not char*. Made appropriate
* fixes in cindex.py - now the relevant tests pass and we can see the
* full locations correctly again (previously there was garbage in
* place of the file name) 
* Exposed clang_getCursorDisplayName to the python bindings

llvm-svn: 134460
2011-07-06 03:00:34 +00:00
John McCall 9de1978f6e Call objc_terminate() instead of abort() when a cleanup throws an
exception in Objective-C;  in Objective-C++ we still use std::terminate().
This is only available in very recent runtimes.

llvm-svn: 134456
2011-07-06 01:22:26 +00:00
John McCall 6dd2417dbe Missing header from last commit; accidental change.
llvm-svn: 134455
2011-07-06 00:38:59 +00:00
John McCall 24fc0decfe Change the driver's logic about Objective-C runtimes: abstract out a
structure to hold inferred information, then propagate each invididual
bit down to -cc1.  Separate the bits of "supports weak" and "has a native
ARC runtime";  make the latter a CodeGenOption.

The tool chain is still driving this decision, because it's the place that
has the required deployment target information on Darwin, but at least it's
better-factored now.

llvm-svn: 134453
2011-07-06 00:26:06 +00:00
Fariborz Jahanian b7a773626f objc-arc: enforce performSelector rules in rejecting retaining selectors
passed to it, and unknown selectors causing potential leak.
// rdar://9659270

llvm-svn: 134449
2011-07-05 22:38:59 +00:00
Dan Gohman fec0ff84dc Add the ObjC ARC optimization passes manually, now that they're not
hardwired into the default pass list.

llvm-svn: 134445
2011-07-05 22:02:36 +00:00
Eli Friedman bb5c9ae425 Remove unused member of Builtin::Info.
llvm-svn: 134443
2011-07-05 21:53:01 +00:00
Douglas Gregor 6b9be0ffb3 Some documentation fixes for the parser, from John Freeman
llvm-svn: 134419
2011-07-05 17:13:11 +00:00
Douglas Gregor 1cb4290b89 StringRef'ize clang::drive::Option::getName(), from Zach Wheeler!
llvm-svn: 134418
2011-07-05 16:56:25 +00:00