Commit Graph

650 Commits

Author SHA1 Message Date
Craig Topper 3793291d50 Make expression allocation methods use a 'const' reference to the ASTContext since the underlying operator new only needs a const reference.
llvm-svn: 188636
2013-08-18 10:09:15 +00:00
Eli Friedman 89fe0d5842 Properly track l-paren of a CXXFucntionalCastExpr.
In addition to storing more useful information in the AST, this
fixes a semantic check in template instantiation which checks whether
the l-paren location is valid.

Fixes PR16903.

llvm-svn: 188495
2013-08-15 22:02:56 +00:00
Lubos Lunak 1f490f3aea report unused-value warning also for warn_unused types
llvm-svn: 186793
2013-07-21 13:15:58 +00:00
Eli Friedman 75807f239e Make IgnoreParens() look through ChooseExprs.
This is the same way GenericSelectionExpr works, and it's generally a
more consistent approach.

A large part of this patch is devoted to caching the value of the condition
of a ChooseExpr; it's needed to avoid threading an ASTContext into
IgnoreParens().

Fixes <rdar://problem/14438917>.

llvm-svn: 186738
2013-07-20 00:40:58 +00:00
Jean-Daniel Dupas 06028a5454 Fix another place where clang check objc selector name instead of checking the selector family
Summary: In ARC mode, clang emits a warning if the result of an 'init' method is unused but miss cases where the method does not follows the Cocoa naming convention but is properly declared as an init family method.

CC: cfe-commits, eli.friedman

Differential Revision: http://llvm-reviews.chandlerc.com/D1163

llvm-svn: 186718
2013-07-19 20:25:56 +00:00
Eli Friedman 4c27ac2348 Make Expr::isConstantInitializer match IRGen.
Sema needs to be able to accurately determine what will be
emitted as a constant initializer and what will not, so
we get accurate errors in C and accurate -Wglobal-constructors
warnings in C++.  This makes Expr::isConstantInitializer match
CGExprConstant as closely as possible.

llvm-svn: 186464
2013-07-16 22:40:53 +00:00
Richard Smith 6b6f8aac72 PR16263: Implement current direction of core issue 1376. Binding a reference to
the result of a cast-to-reference-type lifetime-extends the object to which the
reference inside the cast binds.

This requires us to look for subobject adjustments on both the inside and the
outside of the MaterializeTemporaryExpr when looking for a temporary to
lifetime-extend (which we also need for core issue 616, and possibly 1213).

llvm-svn: 184024
2013-06-15 00:30:29 +00:00
Richard Smith 4055de40ab Implement core issue 903: only integer literals with value 0 and prvalues of
type std::nullptr_t are null pointer constants from C++11 onwards.

llvm-svn: 183883
2013-06-13 02:46:14 +00:00
Richard Smith cc1b96d356 PR12086, PR15117
Introduce CXXStdInitializerListExpr node, representing the implicit
construction of a std::initializer_list<T> object from its underlying array.
The AST representation of such an expression goes from an InitListExpr with a
flag set, to a CXXStdInitializerListExpr containing a MaterializeTemporaryExpr
containing an InitListExpr (possibly wrapped in a CXXBindTemporaryExpr).

This more detailed representation has several advantages, the most important of
which is that the new MaterializeTemporaryExpr allows us to directly model
lifetime extension of the underlying temporary array. Using that, this patch
*drastically* simplifies the IR generation of this construct, provides IR
generation support for nested global initializer_list objects, fixes several
bugs where the destructors for the underlying array would accidentally not get
invoked, and provides constant expression evaluation support for
std::initializer_list objects.

llvm-svn: 183872
2013-06-12 22:31:48 +00:00
Richard Smith 2d18790b3a Do not walk through member-accesses on bitfields when looking for the object
which is lifetime-extended by a reference binding. An additional temporary is
created for such a bitfield access (although we have no explicit AST
representation for it).

llvm-svn: 183095
2013-06-03 07:13:35 +00:00
Richard Smith f3fabd2cb5 Fix handling of pointers-to-members and comma expressions when
lifetime-extending temporaries in reference bindings.

llvm-svn: 183089
2013-06-03 00:17:11 +00:00
David Blaikie 7d17010db5 Use only explicit bool conversion operator
The most common (non-buggy) case are where such objects are used as
return expressions in bool-returning functions or as boolean function
arguments. In those cases I've used (& added if necessary) a named
function to provide the equivalent (or sometimes negative, depending on
convenient wording) test.

DiagnosticBuilder kept its implicit conversion operator owing to the
prevalent use of it in return statements.

One bug was found in ExprConstant.cpp involving a comparison of two
PointerUnions (PointerUnion did not previously have an operator==, so
instead both operands were converted to bool & then compared). A test
is included in test/SemaCXX/constant-expression-cxx1y.cpp for the fix
(adding operator== to PointerUnion in LLVM).

llvm-svn: 181869
2013-05-15 07:37:26 +00:00
Dmitri Gribenko 48d6daf856 Allocate memory for the new number of subexpressions. Fixup for r181572
llvm-svn: 181611
2013-05-10 17:30:13 +00:00
Dmitri Gribenko 674eaa2c88 ArrayRef'ize ShuffleVectorExpr::setExprs
But ShuffleVectorExpr should be tail-allocating the storage for expressions.

llvm-svn: 181572
2013-05-10 00:43:44 +00:00
John McCall d25db7ed0f Grab-bag of bit-field fixes:
- References to ObjC bit-field ivars are bit-field lvalues;
    fixes rdar://13794269, which got me started down this.
  - Introduce Expr::refersToBitField, switch a couple users to
    it where semantically important, and comment the difference
    between this and the existing API.
  - Discourage Expr::getBitField by making it a bit longer and
    less general-sounding.
  - Lock down on const_casts of bit-field gl-values until we
    hear back from the committee as to whether they're allowed.

llvm-svn: 181252
2013-05-06 21:39:12 +00:00
Richard Smith d9f663b510 C++1y constexpr extensions, round 1: Allow most forms of declaration and
statement in constexpr functions. Everything which doesn't require variable
mutation is also allowed as an extension in C++11. 'void' becomes a literal
type to support constexpr functions which return 'void'.

llvm-svn: 180022
2013-04-22 15:31:51 +00:00
Richard Smith 852c9db72b C++1y: Allow aggregates to have default initializers.
Add a CXXDefaultInitExpr, analogous to CXXDefaultArgExpr, and use it both in
CXXCtorInitializers and in InitListExprs to represent a default initializer.

There's an additional complication here: because the default initializer can
refer to the initialized object via its 'this' pointer, we need to make sure
that 'this' points to the right thing within the evaluation.

llvm-svn: 179958
2013-04-20 22:23:05 +00:00
John McCall 5e77d76c95 Basic support for Microsoft property declarations and
references thereto.

Patch by Tong Shen!

llvm-svn: 179585
2013-04-16 07:28:30 +00:00
Benjamin Kramer 24ebf7c92c Add streamed versions of getQualifiedNameAsString.
Move the cold virtual method getNameForDiagnostic out of line.

llvm-svn: 175966
2013-02-23 13:53:57 +00:00
Jordan Rose a7d03840e6 Excise <cctype> from Clang (except clang-tblgen) in favor of CharInfo.h.
Nearly all of these changes are one-to-one replacements; the few that
aren't have to do with custom identifier validation.

llvm-svn: 174768
2013-02-08 22:30:41 +00:00
Alexander Kornienko 540bacb1b9 Use const visitors in ASTDumper.
http://llvm-reviews.chandlerc.com/D355
Patch by Philip Craig!

llvm-svn: 174171
2013-02-01 12:35:51 +00:00
Dmitri Gribenko d06f7ff6d3 Constify some getters of DesignatedInitExpr
llvm-svn: 173574
2013-01-26 15:15:52 +00:00
Tim Northover 178723a687 Switch to APFloat constructor taking fltSemantics.
This change also makes the serialisation store the required semantics,
fixing an issue where PPC128 was always assumed when re-reading a
128-bit value.

llvm-svn: 173139
2013-01-22 09:46:51 +00:00
Guy Benyei 1b4fb3e08b Implement OpenCL event_t as Clang builtin type, including event_t related OpenCL restrictions (OpenCL 1.2 spec 6.9)
llvm-svn: 172973
2013-01-20 12:31:11 +00:00
Richard Smith 5011a0022a Some builtins do not evaluate their arguments. Teach EvaluatedExprVisitor not
to visit them.

llvm-svn: 172769
2013-01-17 23:46:04 +00:00
Matt Beaumont-Gay 978cca9f49 Suppress all -Wunused-value warnings from macro body expansions.
This is inspired by a number of false positives in real code, including
PR14968. I've added test cases reduced from these false positives to
test/Sema/unused-expr.c, as well as corresponding test cases that pass the
offending expressions as arguments to a no-op macro to ensure that we do warn
there.

This also removes my previous tweak from r166522/r166534, so that we warn on
unused cast expressions in macro arguments.

There were several test cases that were using -Wunused-value to test general
diagnostic emission features; I changed those to use other warnings or warn on
a macro argument expression. I stared at the test case for PR14399 for a while
with Richard Smith and we believe the new test case exercises the same
codepaths as before.

llvm-svn: 172696
2013-01-17 02:06:08 +00:00
Dmitri Gribenko f857950d39 Remove useless 'llvm::' qualifier from names like StringRef and others that are
brought into 'clang' namespace by clang/Basic/LLVM.h

llvm-svn: 172323
2013-01-12 19:30:44 +00:00
Richard Smith 89645bc888 s/CXX0X/CXX11/g, except for __GNU_EXPERIMENTAL_CXX0X__, and update a few nearby 'C++0x' comments.
llvm-svn: 171372
2013-01-02 12:01:23 +00:00
Richard Smith 2bf7fdb723 s/CPlusPlus0x/CPlusPlus11/g
llvm-svn: 171367
2013-01-02 11:42:31 +00:00
Erik Verbruggen 11a2eccc8b Fix for PR12222.
Changed getLocStart() and getLocEnd() to be required for Stmts, and make
getSourceRange() optional. The default implementation for getSourceRange()
is build the range by calling getLocStart() and getLocEnd().

llvm-svn: 171067
2012-12-25 14:51:39 +00:00
Argyrios Kyrtzidis 53e3d6d7f0 Don't hit an assertion failure when calculating the __PRETTY_FUNCTION__
of a member function with parenthesized declarator.

Like this test case:

class Foo {
  const char *(baz)() {
    return __PRETTY_FUNCTION__;
  }
};

llvm-svn: 170233
2012-12-14 19:44:11 +00:00
Benjamin Kramer ea70eb30a0 Pull the Attr iteration parts out of Attr.h, so including DeclBase.h doesn't pull in all the generated Attr code.
Required to pull some functions out of line, but this shouldn't have a perf impact.
No functionality change.

llvm-svn: 169092
2012-12-01 15:09:41 +00:00
Abramo Bagnara 8d16bd4d10 Allow to pass from syntactic form of InitListExpr to semantic form (just as viceversa). No functionality change.
llvm-svn: 167591
2012-11-08 18:41:43 +00:00
Abramo Bagnara 9b836fb019 Fixed range of implicit MemberExpr.
llvm-svn: 167581
2012-11-08 13:52:58 +00:00
Rafael Espindola 973aa207e8 Fix an incorrect assert, the LHS can be an LValue.
llvm-svn: 167232
2012-11-01 14:32:20 +00:00
Argyrios Kyrtzidis b26a24cca2 [libclang] Introduce clang_Cursor_getReceiverType which returns the CXType for
the receiver of an ObjC message expression.

rdar://12578643

llvm-svn: 167201
2012-11-01 02:01:34 +00:00
Rafael Espindola 9c006de3d3 Move two helper functions to AST so that sema can use them.
llvm-svn: 166853
2012-10-27 01:03:43 +00:00
Matt Beaumont-Gay 53e767bf6b Address feedback from Eli Friedman on r166522.
In particular, we do want to warn on some unused cast subexpressions within
macros.

llvm-svn: 166534
2012-10-24 01:14:28 +00:00
Matt Beaumont-Gay 493d6d55ba Don't emit -Wunused-value warnings from macro expansions.
llvm-svn: 166522
2012-10-23 23:19:32 +00:00
Matt Beaumont-Gay abf836cffa Fix -Wunused-value to not warn on expressions that have unresolved lookups due
to dependent arguments.

llvm-svn: 166468
2012-10-23 06:15:26 +00:00
David Blaikie 1d202a6bae StringRef-ify Binary/UnaryOperator::getOpcodeStr
llvm-svn: 165383
2012-10-08 01:11:04 +00:00
Anna Zaks 97c7ce3368 Move isObjCSelf into Expr.
llvm-svn: 164966
2012-10-01 20:34:04 +00:00
Eli Friedman bdd5753bda Handle C++ functional casts in a similar way to C-style casts in
unused expression warnings.  <rdar://problem/12359208>.

llvm-svn: 164569
2012-09-24 23:02:26 +00:00
Argyrios Kyrtzidis 617108990d In StringLiteral::setString make sure that we copy the number of
bytes of the buffer and not the size of the string, otherwise we
may overwrite the buffer if there is a mismatch between the size
of the string and the CharByteWidth, and assertions are disabled.

The bug where this could occur was fixed in r163931.
Related to rdar://12069503

llvm-svn: 163939
2012-09-14 21:17:41 +00:00
Richard Smith b15fe3a5e4 PR13811: Add a FunctionParmPackExpr node to handle references to function
parameter packs where the reference is not being expanded but the pack has
been. Previously, Clang would segfault in such cases.

llvm-svn: 163672
2012-09-12 00:56:43 +00:00
Eli Friedman 34866c7719 Change the representation of builtin functions in the AST
(__builtin_* etc.) so that it isn't possible to take their address.
Specifically, introduce a new type to represent a reference to a builtin
function, and a new cast kind to convert it to a function pointer in the
operand of a call.  Fixes PR13195.

llvm-svn: 162962
2012-08-31 00:14:07 +00:00
Benjamin Kramer c215e76f78 Push ArrayRef through the Expr hierarchy.
No functionality change.

llvm-svn: 162552
2012-08-24 11:54:20 +00:00
Eli Friedman cf4ab0891d Fix InitListExpr::isStringLiteralInit so it handles various edge cases correctly. PR13643.
llvm-svn: 162226
2012-08-20 20:55:45 +00:00
Richard Smith ef8bf4368e Factor out computation of whether a typeid's expression is potentially
evaluated into a CXXTypeid member function. No functionality change.

llvm-svn: 161779
2012-08-13 20:08:14 +00:00
David Blaikie f5697e5222 Provide isConst/Volatile on CXXMethodDecl.
This also provides isConst/Volatile/Restrict on FunctionTypes to coalesce
the implementation with other callers (& update those other callers).

Patch contributed by Sam Panzer (panzer@google.com).

llvm-svn: 161647
2012-08-10 00:55:35 +00:00