Commit Graph

107 Commits

Author SHA1 Message Date
Alexander Kornienko 20f6fc6220 Inline storage of attributes in AttributedStmt.
llvm-svn: 159925
2012-07-09 10:04:07 +00:00
Benjamin Kramer 4ab984e74b Drop the ASTContext.h include from DeclFriend.h and DeclTemplate.h.
llvm-svn: 159723
2012-07-04 20:19:54 +00:00
Chad Rosier 32503020a4 Etch out the code path for MS-style inline assembly.
llvm-svn: 158325
2012-06-11 20:47:18 +00:00
Argyrios Kyrtzidis b7e4367fef [libclang/AST] Index references of protocols in "@protocol(...)" syntax.
To do that, keep track of the location of the protocol id in the ObjCProtocolExpr
AST node.

rdar://11190837

llvm-svn: 156890
2012-05-16 00:50:02 +00:00
Argyrios Kyrtzidis d8e076972f Store the source range of a CXXOperatorCallExpr in the Expr object instead of
calculating it recursively.

boost::assign::tuple_list_of uses the trick of chaining call operator expressions in order to declare a "list of tuples", e.g:
    std::vector<tuple> v = boost::assign::tuple_list_of(1, "foo")(2, "bar")(3, "qqq");

Due to CXXOperatorCallExpr calculating its source range recursively we would get
significant slowdowns with a large number of chained call operator expressions and the
potential for stack overflow.

rdar://11350116

llvm-svn: 155848
2012-04-30 22:12:22 +00:00
Patrick Beard 0caa39474b Implements boxed expressions for Objective-C. <rdar://problem/10194391>
llvm-svn: 155082
2012-04-19 00:25:12 +00:00
Richard Smith c202b2809a Add an AttributedStmt type to represent a statement with C++11 attributes
attached. Since we do not support any attributes which appertain to a statement
(yet), testing of this is necessarily quite minimal.

Patch by Alexander Kornienko!

llvm-svn: 154723
2012-04-14 00:33:13 +00:00
Richard Smith aa22a8cdcf AtomicExpr: make ASTStmtReader a friend and remove setters. Also fix saving
of an uninitialized Stmt* in serialization of __atomic_init and add a test of
atomics serialization.

llvm-svn: 154448
2012-04-10 22:49:28 +00:00
Argyrios Kyrtzidis ab468b0381 Add info to ObjCPropertyRefExpr to indicate whether the dot syntax property
reference is going to message the setter, the getter, or both.

Having this info on the ObjCPropertyRefExpr node makes it easier for AST
clients (like libclang) to reason about the meaning of the property reference.

[AST/Sema]
-Use 2 bits (with a PointerIntPair) in ObjCPropertyRefExpr to record the above info
-Have ObjCPropertyOpBuilder set the info appropriately.

[libclang]
-When there is an implicit property reference (property syntax using methods)
have clang_getCursorReferenced return a cursor for the method. If the property
reference is going to result in messaging both the getter and the setter choose
to return a cursor for the setter because it is less obvious from source inspection
that the setter is getting called.

The general idea has the seal of approval by John.

rdar://11151621

llvm-svn: 153709
2012-03-30 00:19:18 +00:00
John McCall 113bee0536 Remove BlockDeclRefExpr and introduce a bit on DeclRefExpr to
track whether the referenced declaration comes from an enclosing
local context.  I'm amenable to suggestions about the exact meaning
of this bit.

llvm-svn: 152491
2012-03-10 09:33:50 +00:00
Richard Smith c67fdd4eb9 AST representation for user-defined literals, plus just enough of semantic
analysis to make the AST representation testable. They are represented by a
new UserDefinedLiteral AST node, which is a sugared CallExpr. All semantic
properties, including full CodeGen support, are achieved for free by this
representation.

UserDefinedLiterals can never be dependent, so no custom instantiation
behavior is required. They are mangled as if they were direct calls to the
underlying literal operator. This matches g++'s apparent behavior (but not its
actual mangling, which is broken for literal-operator-ids).

User-defined *string* literals are now fully-operational, but the semantic
analysis is quite hacky and needs more work. No other forms of user-defined
literal are created yet, but the AST support for them is present.

This patch committed after midnight because we had already hit the quota for
new kinds of literal yesterday.

llvm-svn: 152211
2012-03-07 08:35:16 +00:00
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 a5acaa3ca8 ASTWriter: Cache some DenseMaps we use repeatedly.
- This reduces our total # of allocations building a PCH for Cocoa.h by almost
   a whopping 50%.
 - A SmallPtrMap would be cleaner, but since we don't have one yet...

llvm-svn: 151697
2012-02-29 02:39:13 +00:00
Benjamin Kramer 169f436870 Serialize InitListExpr's initializesStdInitializerList bit, so it's not left uninitialized.
Found by valgrind.

llvm-svn: 151527
2012-02-27 13:20:39 +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
Sebastian Redl 6047f07e81 Revert "Revert "Make CXXNewExpr contain only a single initialier, and not hold the used constructor itself.""
This reintroduces commit r150682 with a fix for the Bullet benchmark crash.

llvm-svn: 150685
2012-02-16 12:22:20 +00:00
Sebastian Redl c3a3c60040 Revert "Make CXXNewExpr contain only a single initialier, and not hold the used constructor itself."
It leads to a compiler crash in the Bullet benchmark.

This reverts commit r12014.

llvm-svn: 150684
2012-02-16 11:35:52 +00:00
Sebastian Redl 86fab844bb Make CXXNewExpr contain only a single initialier, and not hold the used constructor itself.
Holding the constructor directly makes no sense when list-initialized arrays come into play. The constructor is now held in a CXXConstructExpr, if construction is what is done. The new design can also distinguish properly between list-initialization and direct-initialization, as well as implicit default-initialization constructors and explicit value-initialization constructors. Finally, doing it this way removes redundance from the AST because CXXNewExpr doesn't try to handle both the allocation and the initialization responsibilities.

This breaks the static analysis of new expressions. I've filed PR12014 to track this.

llvm-svn: 150682
2012-02-16 10:58:10 +00:00
Douglas Gregor 99ae806aff Implement AST (de-)serialization for lambda expressions.
llvm-svn: 150491
2012-02-14 17:54:36 +00:00
Douglas Gregor e31e606ff3 Introduce basic ASTs for lambda expressions. This covers:
- Capturing variables by-reference and by-copy within a lambda
  - The representation of lambda captures
  - The creation of the non-static data members in the lambda class
  that store the captured variables
  - The initialization of the non-static data members from the
  captured variables
  - Pretty-printing lambda expressions

There are a number of FIXMEs, both explicit and implied, including:
  - Creating a field for a capture of 'this'
  - Improved diagnostics for initialization failures when capturing
  variables by copy
  - Dealing with temporaries created during said initialization
  - Template instantiation
  - AST (de-)serialization
  - Binding and returning the lambda expression; turning it into a
  proper temporary
  - Lots and lots of semantic constraints
  - Parameter pack captures

llvm-svn: 149977
2012-02-07 10:09:13 +00:00
Abramo Bagnara 7945c981b9 Added source location for the template keyword in AST template-id expressions.
llvm-svn: 149127
2012-01-27 09:46:47 +00:00
Argyrios Kyrtzidis a80f1bf262 Add IsImplicit field in ObjCMessageExpr that is true when the message
was constructed, e.g. for a property access.

This allows the selector identifier locations machinery for ObjCMessageExpr
to function correctly, in that there are not real locations to handle/report for
such a message.

llvm-svn: 148013
2012-01-12 02:34:39 +00:00
Argyrios Kyrtzidis b2b0795c9f [PCH] Make sure that the SourceExpr of a OpaqueValueExpr is always initialized
when deserialized, fixing random crashes in libclang.

Also simplifies how OpaqueValueExprs are [de]serialized.
The reader/writer automatically retains pointer equality of sub-statements (when a
statement node is referenced in multiple nodes), so no need to manually handle it.

llvm-svn: 145752
2011-12-03 03:49:52 +00:00
Argyrios Kyrtzidis 5938650b13 [PCH] When serializing an PseudoObjectExpr or AtomicExpr, the serialization code must be set
otherwise it will crash with asserts on or it will be written as null pointer.

llvm-svn: 144626
2011-11-15 06:20:27 +00:00
John McCall 28fc70910f There's no good reason to track temporaries in ExprWithCleanups,
but it is sometimes useful to track blocks.  Do so.  Also
optimize the storage of these expressions.

llvm-svn: 144263
2011-11-10 05:35:25 +00:00
John McCall fe96e0b6be Change the AST representation of operations on Objective-C
property references to use a new PseudoObjectExpr
expression which pairs a syntactic form of the expression
with a set of semantic expressions implementing it.
This should significantly reduce the complexity required
elsewhere in the compiler to deal with these kinds of
expressions (e.g. IR generation's special l-value kind,
the static analyzer's Message abstraction), at the lower
cost of specifically dealing with the odd AST structure
of these expressions.  It should also greatly simplify
efforts to implement similar language features in the
future, most notably Managed C++'s properties and indexed
properties.

Most of the effort here is in dealing with the various
clients of the AST.  I've gone ahead and simplified the
ObjC rewriter's use of properties;  other clients, like
IR-gen and the static analyzer, have all the old
complexity *and* all the new complexity, at least
temporarily.  Many thanks to Ted for writing and advising
on the necessary changes to the static analyzer.

I've xfailed a small diagnostics regression in the static
analyzer at Ted's request.

llvm-svn: 143867
2011-11-06 09:01:30 +00:00
Eli Friedman fcec630a57 Fix the representation of wide strings in the AST and IR so that it uses the native representation of integers for the elements. This fixes a bunch of nastiness involving
treating wide strings as a series of bytes.

Patch by Seth Cantrell.

llvm-svn: 143417
2011-11-01 02:23:42 +00:00
Douglas Gregor deb4a2be67 Implement support for dependent Microsoft __if_exists/__if_not_exists
statements. As noted in the documentation for the AST node, the
semantics of __if_exists/__if_not_exists are somewhat different from
the way Visual C++ implements them, because our parsed-template
representation can't accommodate VC++ semantics without serious
contortions. Hopefully this implementation is "good enough".

llvm-svn: 142901
2011-10-25 01:33:02 +00:00
Argyrios Kyrtzidis 6a59897d50 [PCH] When serializing Stmts, keep track of when sub statements are referenced again and
in such a case just write out a reference of a previously serialized Stmt, instead
of serializing it all over again.

This saves memory + space + [de]serializing time, and avoids blowing up memory
with pathological cases. rdar://10293911

llvm-svn: 142696
2011-10-21 23:02:28 +00:00
Eli Friedman df14b3a837 Initial implementation of __atomic_* (everything except __atomic_is_lock_free).
llvm-svn: 141632
2011-10-11 02:20:01 +00:00
Abramo Bagnara 635ed24e1d Added a flag to identify resolved overloaded function references.
llvm-svn: 141171
2011-10-05 07:56:41 +00:00
Argyrios Kyrtzidis a6011e25a1 Allow getting all source locations of selector identifiers in a ObjCMessageExpr.
Instead of always storing all source locations for the selector identifiers
we check whether all the identifiers are in a "standard" position; "standard" position is

  -Immediately before the arguments: [foo first:1 second:2]
  -With a space between the arguments: [foo first: 1 second: 2]
  -For nullary selectors, immediately before ']': [foo release]

In such cases we infer the locations instead of storing them.

llvm-svn: 140987
2011-10-03 06:36:51 +00:00
David Blaikie 83d382b1ca Switch assert(0/false) llvm_unreachable.
llvm-svn: 140367
2011-09-23 05:06:16 +00:00
Argyrios Kyrtzidis de6aa08013 Rename ExplicitTemplateArgumentList -> ASTTemplateArgumentListInfo, no functionality change.
llvm-svn: 140330
2011-09-22 20:07:03 +00:00
Argyrios Kyrtzidis 43ea78b48d Don't try keeping a 'LeadingEmptyMacroLoc' in NullStmt. This fails
in the face of buffering C++/ObjC method bodies.

llvm-svn: 138972
2011-09-01 21:53:45 +00:00
Douglas Gregor fb65e592e0 Add support for C++0x unicode string and character literals, from Craig Topper!
llvm-svn: 136210
2011-07-27 05:40:30 +00:00
Chris Lattner 0e62c1cc0b remove unneeded llvm:: namespace qualifiers on some core types now that LLVM.h imports
them into the clang namespace.

llvm-svn: 135852
2011-07-23 10:55:15 +00:00
John McCall fa19404c27 Add serialization support for SubstNonTypeTemplateParmExpr.
Also add the missing serialization support for SEHTryStmt,
SEHFinallyStmt, and SEHExceptStmt, and fix and finish the
serialization support for AsTypeExpr.  In addition, change
the code so that it will no longer link if a Stmt subclass
is missing serialization support.

llvm-svn: 135258
2011-07-15 07:00:14 +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
Douglas Gregor 678d76c026 Introduce the notion of instantiation dependence into Clang's AST. A
type/expression/template argument/etc. is instantiation-dependent if
it somehow involves a template parameter, even if it doesn't meet the
requirements for the more common kinds of dependence (dependent type,
type-dependent expression, value-dependent expression).

When we see an instantiation-dependent type, we know we always need to
perform substitution into that instantiation-dependent type. This
keeps us from short-circuiting evaluation in places where we
shouldn't, and lets us properly implement C++0x [temp.type]p2.

In theory, this would also allow us to properly mangle
instantiation-dependent-but-not-dependent decltype types per the
Itanium C++ ABI, but we aren't quite there because we still mangle
based on the canonical type in cases like, e.g.,

  template<unsigned> struct A { };
  template<typename T>
    void f(A<sizeof(sizeof(decltype(T() + T())))>) { }
  template void f<int>(A<sizeof(sizeof(int))>);

and therefore get the wrong answer.

llvm-svn: 134225
2011-07-01 01:22:09 +00:00
Douglas Gregor fe31481f68 Introduce a new AST node describing reference binding to temporaries.
MaterializeTemporaryExpr captures a reference binding to a temporary
value, making explicit that the temporary value (a prvalue) needs to
be materialized into memory so that its address can be used. The
intended AST invariant here is that a reference will always bind to a
glvalue, and MaterializeTemporaryExpr will be used to convert prvalues
into glvalues for that binding to happen. For example, given

  const int& r = 1.0;

The initializer of "r" will be a MaterializeTemporaryExpr whose
subexpression is an implicit conversion from the double literal "1.0"
to an integer value. 

IR generation benefits most from this new node, since it was
previously guessing (badly) when to materialize temporaries for the
purposes of reference binding. There are likely more refactoring and
cleanups we could perform there, but the introduction of
MaterializeTemporaryExpr fixes PR9565, a case where IR generation
would effectively bind a const reference directly to a bitfield in a
struct. Addresses <rdar://problem/9552231>.

llvm-svn: 133521
2011-06-21 17:03:29 +00:00
John McCall 31168b077c Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.

llvm-svn: 133103
2011-06-15 23:02:42 +00:00
Tanya Lattner 55808c1026 Add support for builtin astype:
__builtin_astype(): Used to reinterpreted as another data type of the same size using for both scalar and vector data types.
Added test case.

llvm-svn: 132612
2011-06-04 00:47:47 +00:00
Douglas Gregor 03412ba003 Introduce additional abbreviations into the AST writer for
DeclRefExprs, IntegerLiterals, and others, reducing Cocoa PCH size by
~1% and C++ header size by ~2.5%. From Jonathan Turner!

llvm-svn: 132528
2011-06-03 02:27:19 +00:00
Chandler Carruth 8d26bb0899 Add an optional field attached to a DeclRefExpr which points back to the
Decl actually found via name lookup & overload resolution when that Decl
is different from the ValueDecl which is actually referenced by the
expression.

This can be used by AST consumers to correctly attribute references to
the spelling location of a using declaration, and otherwise gain insight
into the name resolution performed by Clang.

The public interface to DRE is kept as narrow as possible: we provide
a getFoundDecl() which always returns a NamedDecl, either the ValueDecl
referenced or the new, more precise NamedDecl if present. This way AST
clients can code against getFoundDecl without know when exactly the AST
has a split representation.

For an example of the data this provides consider:
% cat x.cc
namespace N1 {
  struct S {};
  void f(const S&);
}
void test(N1::S s) {
  f(s);
  using N1::f;
  f(s);
}

% ./bin/clang -fsyntax-only -Xclang -ast-dump x.cc
[...]
void test(N1::S s) (CompoundStmt 0x5b02010 <x.cc:5:20, line:9:1>
  (CallExpr 0x5b01df0 <line:6:3, col:6> 'void'
    (ImplicitCastExpr 0x5b01dd8 <col:3> 'void (*)(const struct N1::S &)' <FunctionToPointerDecay>
      (DeclRefExpr 0x5b01d80 <col:3> 'void (const struct N1::S &)' lvalue Function 0x5b01a20 'f' 'void (const struct N1::S &)'))
    (ImplicitCastExpr 0x5b01e20 <col:5> 'const struct N1::S' lvalue <NoOp>
      (DeclRefExpr 0x5b01d58 <col:5> 'N1::S':'struct N1::S' lvalue ParmVar 0x5b01b60 's' 'N1::S':'struct N1::S')))
  (DeclStmt 0x5b01ee0 <line:7:3, col:14>
    0x5b01e40 "UsingN1::;")
  (CallExpr 0x5b01fc8 <line:8:3, col:6> 'void'
    (ImplicitCastExpr 0x5b01fb0 <col:3> 'void (*)(const struct N1::S &)' <FunctionToPointerDecay>
      (DeclRefExpr 0x5b01f80 <col:3> 'void (const struct N1::S &)' lvalue Function 0x5b01a20 'f' 'void (const struct N1::S &)' (UsingShadow 0x5b01ea0 'f')))
    (ImplicitCastExpr 0x5b01ff8 <col:5> 'const struct N1::S' lvalue <NoOp>
      (DeclRefExpr 0x5b01f58 <col:5> 'N1::S':'struct N1::S' lvalue ParmVar 0x5b01b60 's' 'N1::S':'struct N1::S'))))

Now we can tell that the second call is 'using' (no pun intended) the using
declaration, and *which* using declaration it sees. Without this, we can
mistake calls that go through using declarations for ADL calls, and have no way
to attribute names looked up with using declarations to the appropriate
UsingDecl.

llvm-svn: 130670
2011-05-01 23:48:14 +00:00
John Wiegley 6242b6a688 Implementation of Embarcadero array type traits
Patch authored by John Wiegley.

These are array type traits used for parsing code that employs certain
features of the Embarcadero C++ compiler: __array_rank(T) and
__array_extent(T, Dim).

llvm-svn: 130351
2011-04-28 00:16:57 +00:00
Argyrios Kyrtzidis f7620e4d49 If a null statement was preceded by an empty macro keep its instantiation source location
in NullStmt.

llvm-svn: 130289
2011-04-27 05:04:02 +00:00
John Wiegley f9f6584e95 t/clang/expr-traits
Patch authored by David Abrahams.

These two expression traits (__is_lvalue_expr, __is_rvalue_expr) are used for
parsing code that employs certain features of the Embarcadero C++ compiler.

llvm-svn: 130122
2011-04-25 06:54:41 +00:00
Argyrios Kyrtzidis bbcefa7d50 For
double data[20000000] = { [19999999] = 1 };

Don't serialize the filler multiple times.

llvm-svn: 129983
2011-04-22 05:29:30 +00:00
Argyrios Kyrtzidis b2ed28ea4b For
double data[20000000] = {0};

we would blow out the memory by creating 20M Exprs to fill out the initializer.

To fix this, if the initializer list initializes an array with more elements than
there are initializers in the list, have InitListExpr store a single 'ArrayFiller' expression
that specifies an expression to be used for value initialization of the rest of the elements.

Fixes rdar://9275920.

llvm-svn: 129896
2011-04-21 00:27:41 +00:00