Commit Graph

3830 Commits

Author SHA1 Message Date
Ted Kremenek e65b086e07 Add clang support for new Objective-C literal syntax for NSDictionary, NSArray,
NSNumber, and boolean literals.  This includes both Sema and Codegen support.
Included is also support for new Objective-C container subscripting.

My apologies for the large patch.  It was very difficult to break apart.
The patch introduces changes to the driver as well to cause clang to link
in additional runtime support when needed to support the new language features.

Docs are forthcoming to document the implementation and behavior of these features.

llvm-svn: 152137
2012-03-06 20:05:56 +00:00
Daniel Dunbar 492488271f AST: Move several Type::is...Type() functions to be inline.
- These functions are both (a) very commonly called and (b) excellent
   candidates for CSE in the callers in which they are commonly used.
 - That isHalfType() is hot makes me sad, but it is trivially when inlined (and
   a huge waste of time when not!!!).
 - The extra IsEnumDeclComplete() function is a hack to break the cycle between
   Type.h and Decl.h, I'm not sure of how to do this more cleanly, but am open
   to ideas.

llvm-svn: 152126
2012-03-06 18:20:20 +00:00
Argyrios Kyrtzidis 735f9d4805 Use TinyPtrVector instead of UsuallyTinyPtrVector.
The latter is just a worse version of the former.

llvm-svn: 152096
2012-03-06 03:00:11 +00:00
Daniel Dunbar 6290557872 AST/stats: Don't effectively use an out-of-line function to return a static
bool. Ugh.

llvm-svn: 152062
2012-03-05 21:42:49 +00:00
Peter Collingbourne 15d48ec46f Properly handle non-canonical underlying types in
ASTContext::getUnaryTransformType.  This can happen if, for example,
an enumeration's underlying type is a typedef.

llvm-svn: 152031
2012-03-05 16:02:06 +00:00
James Molloy 7583ccdc1f Fix a bug in the mangler where in 'namespace std { extern "C" {X;} }', X would not be seen to be in ::std::.
Migrate two other places where the same logic is used to use the helper function that already exists.

llvm-svn: 152022
2012-03-05 09:59:43 +00:00
Richard Smith 2e312c8738 constexpr: Remove APValue/CCValue distinction. It is no longer useful given the
resolution of core issue 1454.

llvm-svn: 151991
2012-03-03 22:46:17 +00:00
Eli Friedman 5358a0ab5a Avoid an unnecessary recursive loop between type canonicalization and NNS canonicalization which would (rarely) lead to memory corruption. While I'm here, simplify. Fixes PR12166. Not committing a testcase because it's impossible to reduce it.
llvm-svn: 151967
2012-03-03 04:09:56 +00:00
Argyrios Kyrtzidis 4af2cb3355 [Sema] Fix crash-on-invalid-code issue:
@class I;
@implementation I(cat) // crashes here
@end

rdar://10968158

llvm-svn: 151931
2012-03-02 19:14:29 +00:00
Richard Smith 35ecb36fcd Ensure that we instantiate static reference data members of class templates
early, since their values can be used in constant expressions in C++11. For
odr-use checking, the opposite change is required, since references are
odr-used whether or not they satisfy the requirements for appearing in a
constant expression.

llvm-svn: 151881
2012-03-02 04:14:40 +00:00
Ted Kremenek c1e4dd0e8e Change @import to @__experimental_modules_import. We are not ready to commit to a particular syntax for modules,
and don't have time to push it forward in the near future.

llvm-svn: 151841
2012-03-01 22:07:04 +00:00
Argyrios Kyrtzidis 981a961d03 Move llvm/ADT/SaveAndRestore.h -> llvm/Support/SaveAndRestore.h.
Needs llvm update.

llvm-svn: 151829
2012-03-01 19:45:56 +00:00
Peter Collingbourne cdb9f302d0 StmtProfiler: Add a null check for child statements.
llvm-svn: 151812
2012-03-01 16:34:31 +00:00
Fariborz Jahanian 86c2f5cc70 objective-c: provide fixit hint when atomic property does not
have matching user defined setter/getter and a warning is issued. 
In this case, a fixit note is displayed. // rdar://10267155

llvm-svn: 151766
2012-02-29 22:18:55 +00:00
Eli Friedman 381f431e28 Fix a couple -Wuninitialized warnings from gcc. Reported by David Greene.
llvm-svn: 151754
2012-02-29 20:59:56 +00:00
James Molloy 6f8780bed1 Reapply r151638 and r151641.
The bug that was caught by Apple's internal buildbots was valid and also showed another bug in my implementation.

These are now fixed, with regression tests added to catch them both (not Darwin-specific).

Original log:
====================

Revert r151638 because it causes assertion hit on PCH creation for Cocoa.h

Original log:
---------------------
Correctly track tags and enum members defined in the prototype of a function, and ensure they are properly scoped.

This fixes code such as:

enum e {x, y};
int f(enum {y, x} n) {
 return 0;
}

This finally fixes PR5464 and PR5477.
---------------------

I also reverted r151641 which was enhancement on top of r151638.

====================

llvm-svn: 151712
2012-02-29 10:24:19 +00:00
Argyrios Kyrtzidis 5929ef2ee7 Revert r151638 because it causes assertion hit on PCH creation for Cocoa.h
Original log:
---------------------
Correctly track tags and enum members defined in the prototype of a function, and ensure they are properly scoped.

This fixes code such as:

enum e {x, y};
int f(enum {y, x} n) {
 return 0;
}

This finally fixes PR5464 and PR5477.
---------------------

I also reverted r151641 which was enhancement on top of r151638.

llvm-svn: 151667
2012-02-28 23:39:14 +00:00
James Molloy 051390fffa Correctly track tags and enum members defined in the prototype of a function, and ensure they are properly scoped.
This fixes code such as:

enum e {x, y};
int f(enum {y, x} n) {
  return 0;
}

This finally fixes PR5464 and PR5477.

llvm-svn: 151638
2012-02-28 18:12:11 +00:00
Argyrios Kyrtzidis 465e137558 When evaluating integer expressions include a check for sub-expressions
depth and error if we exceed a max value, to make sure we avoid a stack overflow.

This is a hacky temporary fix. rdar://10913206.

llvm-svn: 151585
2012-02-27 23:18:37 +00:00
Argyrios Kyrtzidis 91d0098dc8 Revert testing code I committed by mistake in r151464.
llvm-svn: 151548
2012-02-27 20:21:34 +00:00
Benjamin Kramer b73f76b642 Reorder members to save padding.
There's more potential here, but these Exprs aren't used that often so I don't feel like doing heroic bit packing right now.

-8 bytes on every class changed (x86_64).

llvm-svn: 151501
2012-02-26 20:37:14 +00:00
Argyrios Kyrtzidis 8d4677ad26 Revert r151460 as it is not enough to address the issue.
Original log:
When evaluating integer expressions handle logical operators outside
VisitBinaryOperator() to reduce stack pressure for source with huge number
of logical operators.

Fixes rdar://10913206.

llvm-svn: 151464
2012-02-25 23:21:37 +00:00
Sebastian Redl aeac3ff82a Richard Smith pointed out that there already is a proposal for init list mangling.
llvm-svn: 151462
2012-02-25 22:59:28 +00:00
Argyrios Kyrtzidis 70f9eb571e When evaluating integer expressions handle logical operators outside
VisitBinaryOperator() to reduce stack pressure for source with huge number
of logical operators.

Fixes rdar://10913206.

llvm-svn: 151460
2012-02-25 21:38:16 +00:00
Sebastian Redl dadc06494d Better mangling for new-expressions. Also, although we can't mangle arbitrary initializer lists yet (we will need this), turn the crash into a controlled error.
llvm-svn: 151455
2012-02-25 20:51:07 +00:00
Ahmed Charles b24b9aa298 ArrayRef'ize various functions in the AST/Parser/Sema.
llvm-svn: 151447
2012-02-25 11:00:22 +00:00
Richard Smith 561fb15801 Teach CXXRecordDecl::hasIrrelevantDestructor to check the base classes and
data members for deleted or user-provided destructors.

Now it's computed in advance, serialize it, and in passing fix all the other
record DefinitionData flags whose serialization was missing.

llvm-svn: 151441
2012-02-25 07:33:38 +00:00
Richard Smith 6365c9138e When checking whether a reference to a variable is an ICE, look at the type of
the declaration, not at the type of the DeclRefExpr, since within a lambda the
DeclRefExpr can be more const than the declaration is.

llvm-svn: 151399
2012-02-24 22:12:32 +00:00
Nick Lewycky 4ed840421d Revert r151357. That unreachable is reachable...
llvm-svn: 151359
2012-02-24 09:07:53 +00:00
Nick Lewycky e51b944fd7 Silence gcc warnings pointing out that CharByteWidth could be used
uninitialized. While there, restyle this function! No functionality change.

llvm-svn: 151357
2012-02-24 08:58:14 +00:00
Douglas Gregor 093d4be550 Remove some trivial uses of hasTrivialCopyConstructor() and
hasTrivialMoveConstructor().

llvm-svn: 151354
2012-02-24 07:55:51 +00:00
Douglas Gregor 29c42f2a25 Implement a new type trait __is_trivially_constructible(T, Args...)
that provides the behavior of the C++11 library trait
std::is_trivially_constructible<T, Args...>, which can't be
implemented purely as a library.

Since __is_trivially_constructible can have zero or more arguments, I
needed to add Yet Another Type Trait Expression Class, this one
handling arbitrary arguments. The next step will be to migrate
UnaryTypeTrait and BinaryTypeTrait over to this new, more general
TypeTrait class.

Fixes the Clang side of <rdar://problem/10895483> / PR12038.

llvm-svn: 151352
2012-02-24 07:38:34 +00:00
Benjamin Kramer c232b77556 Actually remove the duplicated elements from the vector.
llvm-svn: 151270
2012-02-23 18:35:56 +00:00
Benjamin Kramer 91c6b6a933 Unique CXXBasePath decls with the SmallVector/pod_sort/std::unique idiom instead of employing a wasteful std::set.
llvm-svn: 151255
2012-02-23 15:18:31 +00:00
Douglas Gregor 6427a5ef01 Seriously, are injected-class-names that hard?
llvm-svn: 151241
2012-02-23 07:44:18 +00:00
Douglas Gregor 1be329d838 Provide the __is_trivially_assignable type trait, which provides
compiler support for the std::is_trivially_assignable library type
trait.

llvm-svn: 151240
2012-02-23 07:33:15 +00:00
Rafael Espindola 8093fdfab1 Two fixes to how we compute visibility:
* Handle some situations where we should never make a decl more visible,
  even when merging in an explicit visibility.

* Handle attributes in members of classes that are explicitly specialized.

Thanks Nico for the report and testing, Eric for the initial review, and dgregor
for the awesome test27 :-)

llvm-svn: 151236
2012-02-23 04:17:32 +00:00
Bill Wendling 8eb771d4ca More ArrayRef-ification of methods.
llvm-svn: 151152
2012-02-22 09:51:33 +00:00
Douglas Gregor ed90df3800 Generate an AST for the conversion from a lambda closure type to a
block pointer that returns a block literal which captures (by copy)
the lambda closure itself. Some aspects of the block literal are left
unspecified, namely the capture variable (which doesn't actually
exist) and the body (which will be filled in by IRgen because it can't
be written as an AST).

Because we're switching to this model, this patch also eliminates
tracking the copy-initialization expression for the block capture of
the conversion function, since that information is now embedded in the
synthesized block literal. -1 side tables FTW.

llvm-svn: 151131
2012-02-22 05:02:47 +00:00
Eli Friedman ebea9aff0d Fix a crash in the diangostic code in EvalConstant. PR12043.
llvm-svn: 151100
2012-02-21 22:41:33 +00:00
Douglas Gregor 680e9e018d Improve our handling of lambda expressions that occur within default
arguments. There are two aspects to this:

  - Make sure that when marking the declarations referenced in a
  default argument, we don't try to mark local variables, both because
  it's a waste of time and because the semantics are wrong: we're not
  in a place where we could capture these variables again even if it
  did make sense.
  - When a lambda expression occurs in a default argument of a
  function template, make sure that the corresponding closure type is
  considered dependent, so that it will get properly instantiated. The
  second bit is a bit of a hack; to fix it properly, we may have to
  rearchitect our handling of default arguments, parsing them only
  after creating the function definition. However, I'd like to
  separate that work from the lambdas work.

llvm-svn: 151076
2012-02-21 19:11:17 +00:00
Douglas Gregor 6f88e5e0d7 Implement non-internal linkage for lambda closure types that need a
stable mangling, since these lambdas can end up in multiple
translation units. Sema is responsible for deciding when this is the
case, because it's already responsible for choosing the mangling
number.

llvm-svn: 151029
2012-02-21 04:17:39 +00:00
Douglas Gregor 926410d2db Implement name mangling for lambda expressions that occur within the
initializers of data members (both static and non-static).

llvm-svn: 151017
2012-02-21 02:22:07 +00:00
Douglas Gregor 7fcbd902b4 Implement name mangling for lambda expressions that occur within the
default arguments of function parameters. This simple-sounding task is
complicated greatly by two issues:

  (1) Default arguments aren't actually a real context, so we need to
  maintain extra state within lambda expressions to track when a
  lambda was actually in a default argument.
  (2) At the time that we parse a default argument, the FunctionDecl
  doesn't exist yet, so lambda closure types end up in the enclosing
  context. It's not clear that we ever want to change that, so instead
  we introduce the notion of the "effective" context of a declaration
  for the purposes of name mangling.

llvm-svn: 151011
2012-02-21 00:37:24 +00:00
Fariborz Jahanian a7765fea90 modern objc translator. Finish off first cut of the
modern meta-data translation by commenting out private ivar
declarations in user source. Also, added several tests.

llvm-svn: 150985
2012-02-20 20:09:20 +00:00
Douglas Gregor 6379854457 Basic support for name mangling of C++11 lambda expressions. Because
name mangling in the Itanium C++ ABI for lambda expressions is so
dependent on context, we encode the number used to encode each lambda
as part of the lambda closure type, and maintain this value within
Sema.

Note that there are a several pieces still missing:
  - We still get the linkage of lambda expressions wrong
  - We aren't properly numbering or mangling lambda expressions that
  occur in default function arguments or in data member initializers.
  - We aren't (de-)serializing the lambda numbering tables

llvm-svn: 150982
2012-02-20 19:44:39 +00:00
Benjamin Kramer 2325b24c73 ObjCMessageExpr: Don't leave SelLocsKind uninitialized when the send is implicit.
Fixes PR11929. Found by valgrind.

llvm-svn: 150943
2012-02-20 00:20:48 +00:00
Sebastian Redl e6c32e6293 Refuse to compile global std::initializer_lists instead of doing completely the wrong thing.
llvm-svn: 150928
2012-02-19 14:53:49 +00:00
Ahmed Charles 289896d2f3 Remove dead code.
llvm-svn: 150919
2012-02-19 11:57:29 +00:00
Richard Smith 66c9699ac3 Implement constant expression support for __real__ and __imag__ on lvalue
complex numbers. Treat complex numbers as arrays of the corresponding component
type, in order to make std::complex behave properly if implemented in terms of
_Complex T.

Apparently libstdc++'s std::complex is implemented this way, and we were
rejecting a member like this:

  constexpr double real() { return __real__ val; }

because it was marked constexpr but unable to produce a constant expression.

llvm-svn: 150895
2012-02-18 22:04:06 +00:00