Commit Graph

568 Commits

Author SHA1 Message Date
Eli Friedman 0718591771 Adjust clang for change to APFloat::toString.
I changed the diagnostic printing code because it's probably better
to cut off a digit from DBL_MAX than to print something like
1.300000001 when the user wrote 1.3.

llvm-svn: 189625
2013-08-29 23:44:43 +00:00
Craig Topper a31a882f87 Constify more uses of ASTContext&. No functional change.
llvm-svn: 188991
2013-08-22 07:09:37 +00:00
Richard Smith 49ca8aab58 PR16755: When initializing or modifying a bitfield member in a constant
expression, truncate the stored value to the size of the bitfield.

llvm-svn: 187782
2013-08-06 07:09:20 +00:00
Richard Smith 08d6a2cc7a C++1y: track object lifetime during constexpr evaluation, and don't allow
objects to be used once their lifetimes end. This completes the C++1y
constexpr extensions.

llvm-svn: 187025
2013-07-24 07:11:57 +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
Richard Smith 6cbd65d84d Add a __builtin_addressof that performs the same functionality as the built-in
& operator (ignoring any overloaded operator& for the type). The purpose of
this builtin is for use in std::addressof, to allow it to be made constexpr;
the existing implementation technique (reinterpret_cast to some reference type,
take address, reinterpert_cast back) does not permit this because
reinterpret_cast between reference types is not permitted in a constant
expression in C++11 onwards.

llvm-svn: 186053
2013-07-11 02:27:57 +00:00
Richard Smith 51f0317e52 PR16377: Allow evaluation of statement expressions in constant evaluation,
why not. Apparently GCC supports this.

llvm-svn: 184396
2013-06-20 03:00:05 +00:00
Richard Smith 1a90f5956d PR14503: Don't assert if a constexpr constructor temploid instantiates to a
constructor that does not initialize all members, and that constructor is used
to initialize a global.

llvm-svn: 184211
2013-06-18 17:51:51 +00:00
Richard Smith a509f2fdfa Emit initializers for static-storage-duration temporaries as constants where
possible.

llvm-svn: 183967
2013-06-14 03:07:01 +00:00
Richard Smith ab341c62b3 More for PR12457: fix handling of __builtin_isinf_sign and test.
llvm-svn: 183890
2013-06-13 06:31:13 +00:00
Richard Smith 8889a3d3b5 Towards PR12457: constant expression evaluation support for __builtin_parity{,l,ll}, __builtin_ffs{,l,ll}, and __builtin_fpclassify.
llvm-svn: 183889
2013-06-13 06:26:32 +00:00
Richard Smith 80b3c8e32f Fix part of PR12457. Patch by Justin Bogner!
llvm-svn: 183886
2013-06-13 05:04:16 +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 ea4ad5d841 When a static storage duration temporary appears in a constant expression, it
must be initialized by a constant expression (not just a core constant
expression), because we're going to emit it as a global. Core issue for this is
pending.

llvm-svn: 183388
2013-06-06 08:19:16 +00:00
Richard Smith e6c0144208 Model temporary lifetime-extension explicitly in the AST. Use this model to
handle temporaries which have been lifetime-extended to static storage duration
within constant expressions. This correctly handles nested lifetime extension
(through reference members of aggregates in aggregate initializers) but
non-constant-expression emission hasn't yet been updated to do the same.

llvm-svn: 183283
2013-06-05 00:46:14 +00:00
Richard Smith 844010455d Refactor constant expression evaluation to associate the complete object of a
materialized temporary with the corresponding MaterializeTemporaryExpr. This is
groundwork for providing C++11's guaranteed static initialization for global
references bound to lifetime-extended temporaries (if the initialization is a
constant expression).

In passing, fix a couple of bugs where some evaluation failures didn't trigger
diagnostics, and a rejects-valid where potential constant expression testing
would assume that it knew the dynamic type of *this and would reject programs
which relied on it being some derived type.

llvm-svn: 183093
2013-06-03 05:03:02 +00:00
Richard Smith a23ab514c2 PR14772: Support constant expression evaluation for _Atomic types.
* Treat _Atomic(T) as a literal type if T is a literal type.
 * Evaluate expressions of this type properly.
 * Fix a lurking bug where we built completely bogus ASTs for converting to
   _Atomic types in C++ in some cases, caught by the tests for this change.

llvm-svn: 182541
2013-05-23 00:30:41 +00:00
Richard Smith 37dc92eb4c Tidy up now that PointerUnion has an operator== that works.
llvm-svn: 181983
2013-05-16 05:04:51 +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
Richard Smith 0838f3a1f2 Suppress bogus "use of undefined constexpr function" error if the function body
was erroneous and got discarded.

llvm-svn: 181758
2013-05-14 05:18:44 +00:00
Richard Smith f8cf9d4851 Suppress GCC warning for no return after covered switch, and remove some
debugging code from an unreachable codepath.

llvm-svn: 181731
2013-05-13 20:33:30 +00:00
Richard Smith 496ddcfba9 C++1y: support for 'switch' statements in constexpr functions. This is somewhat
inefficient; we perform a linear scan of switch labels to find the one matching
the condition, and then walk the body looking for that label. Both parts should
be straightforward to optimize.

llvm-svn: 181671
2013-05-12 17:32:42 +00:00
Richard Smith 7525ff67f1 Implement C++1y constant initializer rules: in a constant initializer for an
object x, x's subobjects can be constructed by constexpr constructor even if
they are of non-literal type, and can be read and written even though they're
not members of a constexpr object or temporary.

llvm-svn: 181506
2013-05-09 07:14:00 +00:00
Richard Smith a3d3bd215b C++1y: Add a step limit to constexpr evaluation, to catch runaway loops.
llvm-svn: 181388
2013-05-08 02:12:03 +00:00
Richard Smith 861b5b5aed C++1y constant expression evaluation: compound assignment support for floating-point and pointer types.
llvm-svn: 181376
2013-05-07 23:34:45 +00:00
Richard Smith 43e77733c2 C++1y constant expression evaluation: support for compound assignments on integers.
llvm-svn: 181287
2013-05-07 04:50:00 +00:00
Richard Smith 99005e65cd C++1y: an assignment operator is implicitly 'constexpr' if it would only call 'constexpr' assignment operators for a literal class type.
llvm-svn: 181284
2013-05-07 03:19:20 +00:00
Hans Wennborg 9242bd1b06 Add llvm_unreachable at end of fully covered switch
To pacify GCC warning about control reaching end of non-void function.

llvm-svn: 181197
2013-05-06 15:13:34 +00:00
John McCall 768439eb2e Require the containing type to be complete when we see
__alignof__ of a field.

This problem can only happen in C++11.

Also do some petty optimizations.

rdar://13784901

llvm-svn: 181185
2013-05-06 07:40:34 +00:00
Richard Smith 896e0d7568 C++1y: support range-based for loops in constant expressions.
llvm-svn: 181184
2013-05-06 06:51:17 +00:00
Richard Smith 4e18ca5200 C++1y: support 'for', 'while', and 'do ... while' in constant expressions.
llvm-svn: 181181
2013-05-06 05:56:11 +00:00
Richard Smith 243ef9077a C++1y: support for increment and decrement in constant expression evaluation.
llvm-svn: 181173
2013-05-05 23:31:59 +00:00
Richard Smith 3229b744a5 Factor out duplication between lvalue-to-rvalue conversions and variable
assignments in constant expressions. No significant functionality changes
(slight improvement to potential constant expression checking). 

llvm-svn: 181170
2013-05-05 21:17:10 +00:00
Richard Smith 9f8400eca4 PR15884: In the 'taking the address of a temporary' extension, materialize the
temporary to an lvalue before taking its address. This removes a weird special
case from the AST representation, and allows the constant expression evaluator
to deal with it without (broken) hacks.

llvm-svn: 180866
2013-05-01 19:00:39 +00:00
Benjamin Kramer 62498ab4d5 Move helper classes into anonymous namespaces.
llvm-svn: 180642
2013-04-26 22:01:47 +00:00
Richard Smith 3da88fac54 C++1y: support simple variable assignments in constexpr functions.
llvm-svn: 180603
2013-04-26 14:36:30 +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 9543c5e371 Fix array constant expression evaluation bug: we can have different values for
different array elements, even if they're all constructed using the same
default constructor.

llvm-svn: 180017
2013-04-22 14:44:29 +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
Richard Smith fd3834f7a1 Annotate flavor of TLS variable (statically or dynamically initialized) onto the AST.
llvm-svn: 179447
2013-04-13 02:43:54 +00:00
Jordan Rose b1312a5495 Force a load when creating a reference to a temporary copied from a bitfield.
For this source:
  const int &ref = someStruct.bitfield;

We used to generate this AST:

  DeclStmt [...]
  `-VarDecl [...] ref 'const int &'
    `-MaterializeTemporaryExpr [...] 'const int' lvalue
      `-ImplicitCastExpr [...] 'const int' lvalue <NoOp>
        `-MemberExpr [...] 'int' lvalue bitfield .bitfield [...]
          `-DeclRefExpr [...] 'struct X' lvalue ParmVar [...] 'someStruct' 'struct X'

Notice the lvalue inside the MaterializeTemporaryExpr, which is very
confusing (and caused an assertion to fire in the analyzer - PR15694).

We now generate this:

  DeclStmt [...]
  `-VarDecl [...] ref 'const int &'
    `-MaterializeTemporaryExpr [...] 'const int' lvalue
      `-ImplicitCastExpr [...] 'int' <LValueToRValue>
        `-MemberExpr [...] 'int' lvalue bitfield .bitfield [...]
          `-DeclRefExpr [...] 'struct X' lvalue ParmVar [...] 'someStruct' 'struct X'

Which makes a lot more sense. This allows us to remove code in both
CodeGen and AST that hacked around this special case.

The commit also makes Clang accept this (legal) C++11 code:

  int &&ref = std::move(someStruct).bitfield

PR15694 / <rdar://problem/13600396>

llvm-svn: 179250
2013-04-11 00:58:58 +00:00
Joey Gouly 0942e0b5e1 Fix a crash in OpenCL code by using the proper (RHS) bit-width.
llvm-svn: 173802
2013-01-29 15:09:40 +00:00
Fariborz Jahanian bbcf8548cb removed duplicated comment.
llvm-svn: 173378
2013-01-24 22:26:55 +00:00
Fariborz Jahanian e735ff93e8 Patch to check for integer overflow. It has been
commented on and approved by Richard Smith.

llvm-svn: 173377
2013-01-24 22:11:45 +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
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
Fariborz Jahanian 8b115b7872 Issue warning when case value is too large to fit
in case condition type. // rdar://11577384.
Test is conditionalized on x86_64-apple triple as
I am not sure if the INT_MAX/LONG_MAX values in the test
will pass this test for other hosts.

llvm-svn: 172016
2013-01-09 23:04:56 +00:00
David Tweed 042e0883cb Scalar shifts in the OpenCL specification (as of v. 1.2) are defined to be
with respect to the lower "left-hand-side bitwidth" bits, even when negative);
see OpenCL spec 6.3j. This patch both implements this behaviour in the code
generator and "constant folding" bits of Sema, and also prevents tests
to detect undefinedness in terms of the weaker C99 or C++ specifications
from being applied. 

llvm-svn: 171755
2013-01-07 16:43:27 +00:00