summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ExprConstant.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Create ConstantExpr classBill Wendling2018-10-311-2/+5
| | | | | | | | | | | | | | | | A ConstantExpr class represents a full expression that's in a context where a constant expression is required. This class reflects the path the evaluator took to reach the expression rather than the syntactic context in which the expression occurs. In the future, the class will be expanded to cache the result of the evaluated expression so that it's not needlessly re-evaluated Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D53475 llvm-svn: 345692
* PR26547: alignof should return ABI alignment, not preferred alignmentRichard Smith2018-10-261-10/+27
| | | | | | | | | | | | Summary: - Add `UETT_PreferredAlignOf` to account for the difference between `__alignof` and `alignof` - `AlignOfType` now returns ABI alignment instead of preferred alignment iff clang-abi-compat > 7, and one uses _Alignof or alignof Patch by Nicole Mazzuca! Differential Revision: https://reviews.llvm.org/D53207 llvm-svn: 345419
* [Fixed Point Arithmetic] Fixed Point to Boolean CastLeonard Chan2018-10-231-0/+9
| | | | | | | | | | This patch is a part of https://reviews.llvm.org/D48456 in an attempt to split the casting logic up into smaller patches. This contains the code for casting from fixed point types to boolean types. Differential Revision: https://reviews.llvm.org/D53308 llvm-svn: 345063
* [OpenCL][NFC] Unify ZeroToOCL* cast typesAndrew Savonichev2018-10-231-4/+2
| | | | | | | | | | | | Reviewers: Anastasia, yaxunl Reviewed By: Anastasia Subscribers: asavonic, cfe-commits Differential Revision: https://reviews.llvm.org/D52654 llvm-svn: 345038
* [Diagnostics] Check for integer overflow in array size expressions David Bolvansky2018-10-181-0/+13
| | | | | | | | | | | | | | Summary: Fixes PR27439 Reviewers: rsmith, Rakete1111 Reviewed By: rsmith Subscribers: Rakete1111, cfe-commits Differential Revision: https://reviews.llvm.org/D52750 llvm-svn: 344759
* [Fixed Point Arithmetic] FixedPointCastLeonard Chan2018-10-151-0/+2
| | | | | | | | | | | | | This patch is a part of https://reviews.llvm.org/D48456 in an attempt to split them up. This contains the code for casting between fixed point types and other fixed point types. The method for converting between fixed point types is based off the convert() method in APFixedPoint. Differential Revision: https://reviews.llvm.org/D50616 llvm-svn: 344530
* ExprConstant: Make __builtin_object_size use EM_IgnoreSideEffects.James Y Knight2018-10-101-24/+7
| | | | | | | | | | | | | | | | | | | | | | | And, since EM_OffsetFold is now unused, remove it. While builtin_object_size intends to ignore the presence of side-effects in its argument, the EM_OffsetFold mode was NOT configured to ignore side-effects. Rather it was effectively identical to EM_ConstantFold -- its explanatory comment notwithstanding. However, currently, keepEvaluatingAfterSideEffect() is not always honored -- sometimes evaluation continues despite it returning false. Therefore, since the b_o_s code was only checking the return value from evaluation, and not additionally checking the HasSideEffects flag, side-effects _were_ in many cases actually being ignored. This change is a prerequisite cleanup towards fixing that issue. Differential Revision: https://reviews.llvm.org/D52924 llvm-svn: 344110
* Emit CK_NoOp casts in C mode, not just C++.James Y Knight2018-10-051-5/+1
| | | | | | | | | | | | Previously, it had been using CK_BitCast even for casts that only change const/restrict/volatile. Now it will use CK_Noop where appropriate. This is an alternate solution to r336746. Differential Revision: https://reviews.llvm.org/D52918 llvm-svn: 343892
* Emit diagnostic note when calling an invalid function declaration.James Y Knight2018-10-051-3/+6
| | | | | | | | | | | | | | The comment said it was intentionally not emitting any diagnostic because the declaration itself was already diagnosed. However, everywhere else that wants to not emit a diagnostic without an extra note emits note_invalid_subexpr_in_const_expr instead, which gets suppressed later. This was the only place which did not emit a diagnostic note. Differential Revision: https://reviews.llvm.org/D52919 llvm-svn: 343867
* [constexpr] Fix ICE when memcpy() is given a pointer to an incomplete arrayPetr Pavlu2018-10-041-0/+4
| | | | | | | | | | Fix code for constant evaluation of __builtin_memcpy() and __builtin_memmove() that would attempt to divide by zero when given two pointers to an incomplete array. Differential Revision: https://reviews.llvm.org/D51855 llvm-svn: 343761
* [cxx2a] P0614R1: Support init-statements in range-based for loops.Richard Smith2018-09-281-0/+7
| | | | | | | We don't yet support this for the case where a range-based for loop is implicitly rewritten to an ObjC for..in statement. llvm-svn: 343350
* Fix crash on call to __builtin_memcpy with a null pointer to anRichard Smith2018-09-131-2/+16
| | | | | | | | incomplete type. Also improve the diagnostics for similar situations. llvm-svn: 342192
* Port getLocEnd -> getEndLocStephen Kelly2018-08-091-1/+1
| | | | | | | | | | Reviewers: teemperor! Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50351 llvm-svn: 339386
* Port getLocStart -> getBeginLocStephen Kelly2018-08-091-26/+27
| | | | | | | | | | Reviewers: teemperor! Subscribers: jholewinski, whisperity, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50350 llvm-svn: 339385
* [Builtins] Add __builtin_clrsb support to IntExprEvaluator::VisitBuiltinCallExprCraig Topper2018-08-081-3/+9
| | | | | | | | | | This addresses a FIXME that has existed since before clang supported the builtin. This time with only reviewed changes. Differential Revision: https://reviews.llvm.org/D50471 llvm-svn: 339295
* Revert r339287 "[Builtins] Add __builtin_clrsb support to ↵Craig Topper2018-08-081-9/+3
| | | | | | | | IntExprEvaluator::VisitBuiltinCallExpr" This add an additional unintended change in it. llvm-svn: 339289
* [Builtins] Add __builtin_clrsb support to IntExprEvaluator::VisitBuiltinCallExprCraig Topper2018-08-081-3/+9
| | | | | | | | This addresses a FIXME that has existed since before clang supported the builtin. Differential Revision: https://reviews.llvm.org/D50471 llvm-svn: 339287
* [Fixed Point Arithmetic] Fix for FixedPointValueToStringLeonard Chan2018-08-061-2/+1
| | | | | | | | | | | | - Print negative numbers correctly - Handle APInts of different sizes - Add formal unit tests for FixedPointValueToString - Add tests for checking correct printing when padding is set - Restrict to printing in radix 10 since that's all we need for now Differential Revision: https://reviews.llvm.org/D49945 llvm-svn: 339026
* [constexpr] Support for constant evaluation of __builtin_memcpy andRichard Smith2018-08-041-48/+199
| | | | | | | | | | | | | | | | | | __builtin_memmove (in non-type-punning cases). This is intended to permit libc++ to make std::copy etc constexpr without sacrificing the optimization that uses memcpy on trivially-copyable types. __builtin_strcpy and __builtin_wcscpy are not handled by this change. They'd be straightforward to add, but we haven't encountered a need for them just yet. This reinstates r338455, reverted in r338602, with a fix to avoid trying to constant-evaluate a memcpy call if either pointer operand has an invalid designator. llvm-svn: 338941
* Revert r338455 "[constexpr] Support for constant evaluation of ↵Hans Wennborg2018-08-011-198/+48
| | | | | | | | | | | | | | | | __builtin_memcpy and __builtin_memmove (in non-type-punning cases)." It caused asserts during Chromium builds, see reply on the cfe-commits thread. > This is intended to permit libc++ to make std::copy etc constexpr > without sacrificing the optimization that uses memcpy on > trivially-copyable types. > > __builtin_strcpy and __builtin_wcscpy are not handled by this change. > They'd be straightforward to add, but we haven't encountered a need for > them just yet. llvm-svn: 338602
* [constexpr] Support for constant evaluation of __builtin_memcpy andRichard Smith2018-07-311-48/+198
| | | | | | | | | | | | | | __builtin_memmove (in non-type-punning cases). This is intended to permit libc++ to make std::copy etc constexpr without sacrificing the optimization that uses memcpy on trivially-copyable types. __builtin_strcpy and __builtin_wcscpy are not handled by this change. They'd be straightforward to add, but we haven't encountered a need for them just yet. llvm-svn: 338455
* Remove trailing spaceFangrui Song2018-07-301-32/+32
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* Prevent Scoped Enums from being Integral constant expressions:Erich Keane2018-07-201-1/+1
| | | | | | | | | | | | | | | | Discovered because of: https://bugs.llvm.org/show_bug.cgi?id=38235 It seems to me that a scoped enum should NOT be an integral constant expression without a cast, so this seems like a sensical change. Attributes that check for an integer parameter simply use this function to ensure that they have an integer, so it was previously allowing a scoped enum. Also added a test based on Richard's feedback to ensure that case labels still work. Differential Revision: https://reviews.llvm.org/D49599 llvm-svn: 337585
* PR38095: Allow constant-folding of loads through bitcasted pointers ifRichard Smith2018-07-111-3/+7
| | | | | | the bitcast only changed cvr-qualifications within the pointer type. llvm-svn: 336746
* Fix __builtin_*_overflow when out-param isn't constexprErich Keane2018-07-051-1/+2
| | | | | | | | | | | | | | | As brought up on cfe-commits[1], r334650 causes the dependency of the out parameter to the __builtin_*_overflow functions to be ignored. The result was a usage that was otherwise constexpr (both operands to the operation were constexpr) would be evaluated, but the out parameter wouldn't be modified, so it would still be 'undef'. This patch correctly handles the return value of handleAssignment to ensure that this value is properly considered/evaluated. [1] http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180702/233667.html llvm-svn: 336364
* [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point LiteralsLeonard Chan2018-06-201-0/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This diff includes the logic for setting the precision bits for each primary fixed point type in the target info and logic for initializing a fixed point literal. Fixed point literals are declared using the suffixes ``` hr: short _Fract uhr: unsigned short _Fract r: _Fract ur: unsigned _Fract lr: long _Fract ulr: unsigned long _Fract hk: short _Accum uhk: unsigned short _Accum k: _Accum uk: unsigned _Accum ``` Errors are also thrown for illegal literal values ``` unsigned short _Accum u_short_accum = 256.0uhk; // expected-error{{the integral part of this literal is too large for this unsigned _Accum type}} ``` Differential Revision: https://reviews.llvm.org/D46915 llvm-svn: 335148
* [Fixed Point Arithmetic] Addition of the remaining fixed point types and ↵Leonard Chan2018-06-141-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | their saturated equivalents This diff includes changes for the remaining _Fract and _Sat fixed point types. ``` signed short _Fract s_short_fract; signed _Fract s_fract; signed long _Fract s_long_fract; unsigned short _Fract u_short_fract; unsigned _Fract u_fract; unsigned long _Fract u_long_fract; // Aliased fixed point types short _Accum short_accum; _Accum accum; long _Accum long_accum; short _Fract short_fract; _Fract fract; long _Fract long_fract; // Saturated fixed point types _Sat signed short _Accum sat_s_short_accum; _Sat signed _Accum sat_s_accum; _Sat signed long _Accum sat_s_long_accum; _Sat unsigned short _Accum sat_u_short_accum; _Sat unsigned _Accum sat_u_accum; _Sat unsigned long _Accum sat_u_long_accum; _Sat signed short _Fract sat_s_short_fract; _Sat signed _Fract sat_s_fract; _Sat signed long _Fract sat_s_long_fract; _Sat unsigned short _Fract sat_u_short_fract; _Sat unsigned _Fract sat_u_fract; _Sat unsigned long _Fract sat_u_long_fract; // Aliased saturated fixed point types _Sat short _Accum sat_short_accum; _Sat _Accum sat_accum; _Sat long _Accum sat_long_accum; _Sat short _Fract sat_short_fract; _Sat _Fract sat_fract; _Sat long _Fract sat_long_fract; ``` This diff only allows for declaration of these fixed point types. Assignment and other operations done on fixed point types according to http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf will be added in future patches. Differential Revision: https://reviews.llvm.org/D46911 llvm-svn: 334718
* Implement constexpr __builtin_*_overflowErich Keane2018-06-131-0/+118
| | | | | | | | | As requested here:https://bugs.llvm.org/show_bug.cgi?id=37633 permit the __builtin_*_overflow builtins in constexpr functions. Differential Revision: https://reviews.llvm.org/D48040 llvm-svn: 334650
* This diff includes changes for supporting the following types.Leonard Chan2018-06-041-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | // Primary fixed point types signed short _Accum s_short_accum; signed _Accum s_accum; signed long _Accum s_long_accum; unsigned short _Accum u_short_accum; unsigned _Accum u_accum; unsigned long _Accum u_long_accum; // Aliased fixed point types short _Accum short_accum; _Accum accum; long _Accum long_accum; This diff only allows for declaration of the fixed point types. Assignment and other operations done on fixed point types according to http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf will be added in future patches. The saturated versions of these types and the equivalent _Fract types will also be added in future patches. The tests included are for asserting that we can declare these types. Fixed the test that was failing by not checking for dso_local on some targets. Differential Revision: https://reviews.llvm.org/D46084 llvm-svn: 333923
* Revert "This diff includes changes for supporting the following types."Leonard Chan2018-06-021-5/+0
| | | | | | | This reverts commit r333814, which fails for a test checking the bit width on ubuntu. llvm-svn: 333815
* This diff includes changes for supporting the following types.Leonard Chan2018-06-021-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | ``` // Primary fixed point types signed short _Accum s_short_accum; signed _Accum s_accum; signed long _Accum s_long_accum; unsigned short _Accum u_short_accum; unsigned _Accum u_accum; unsigned long _Accum u_long_accum; // Aliased fixed point types short _Accum short_accum; _Accum accum; long _Accum long_accum; ``` This diff only allows for declaration of the fixed point types. Assignment and other operations done on fixed point types according to http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf will be added in future patches. The saturated versions of these types and the equivalent `_Fract` types will also be added in future patches. The tests included are for asserting that we can declare these types. Differential Revision: https://reviews.llvm.org/D46084 llvm-svn: 333814
* Rework __builtin_classify_type support to better match GCC and to not assert onRichard Smith2018-05-231-80/+96
| | | | | | | | | | | | | | | | | | | | | | unusual types. Following the observed behavior of GCC, we now return -1 for vector types (along with all of our extensions that GCC doesn't support), and for atomic types we classify the underlying type. GCC appears to have changed its classification for function and array arguments between version 5 and version 6. Previously it would classify them as pointers in C and as functions or arrays in C++, but from version 6 onwards, it classifies them as pointers. We now follow the more recent GCC behavior rather than emulating what I can only assume to be a historical bug in their C++ support for this builtin. Finally, no version of GCC that I can find has ever used the "method" classification for C++ pointers to member functions. Instead, GCC classifies them as record types, presumably reflecting an internal implementation detail, but whatever the reason we now produce compatible results. llvm-svn: 333126
* Revert r332847; it caused us to miscompile certain forms of reference ↵Richard Smith2018-05-211-3/+9
| | | | | | initialization. llvm-svn: 332886
* [CodeGen] Recognize more cases of zero initializationSerge Pavlov2018-05-211-9/+3
| | | | | | | | | | | | | | | | | | | | | If a variable has an initializer, codegen tries to build its value. If the variable is large in size, building its value requires substantial resources. It causes strange behavior from user viewpoint: compilation of huge zero initialized arrays like: char data_1[2147483648u] = { 0 }; consumes enormous amount of time and memory. With this change codegen tries to determine if variable initializer is equivalent to zero initializer. In this case variable value is not constructed. This change fixes PR18978. Differential Revision: https://reviews.llvm.org/D46241 llvm-svn: 332847
* [clang] Update uses of DEBUG macro to LLVM_DEBUG.Nicola Zaghen2018-05-151-2/+2
| | | | | | | | | | | | | The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM Explicitly avoided changing the strings in the clang-format tests. Differential Revision: https://reviews.llvm.org/D44975 llvm-svn: 332350
* Allow dllimport non-type template arguments in C++17Reid Kleckner2018-05-101-19/+38
| | | | | | | | | | | Summary: Fixes PR35772. Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D43320 llvm-svn: 332018
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-12/+12
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* Fix 'not all control paths return a value' MSVC warnings. NFCI.Simon Pilgrim2018-05-081-0/+1
| | | | llvm-svn: 331753
* [C++2a] Implement operator<=> CodeGen and ExprConstantEric Fiselier2018-05-071-269/+348
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch tackles long hanging fruit for the builtin operator<=> expressions. It is currently needs some cleanup before landing, but I want to get some initial feedback. The main changes are: * Lookup, build, and store the required standard library types and expressions in `ASTContext`. By storing them in ASTContext we don't need to store (and duplicate) the required expressions in the BinaryOperator AST nodes. * Implement [expr.spaceship] checking, including diagnosing narrowing conversions. * Implement `ExprConstant` for builtin spaceship operators. * Implement builitin operator<=> support in `CodeGenAgg`. Initially I emitted the required comparisons using `ScalarExprEmitter::VisitBinaryOperator`, but this caused the operand expressions to be emitted once for every required cmp. * Implement [builtin.over] with modifications to support the intent of P0946R0. See the note on `BuiltinOperatorOverloadBuilder::addThreeWayArithmeticOverloads` for more information about the workaround. Reviewers: rsmith, aaron.ballman, majnemer, rnk, compnerd, rjmccall Reviewed By: rjmccall Subscribers: rjmccall, rsmith, aaron.ballman, junbuml, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D45476 llvm-svn: 331677
* Implement P0482R2, support for char8_t type.Richard Smith2018-05-011-0/+1
| | | | | | | | | | | | This is not yet part of any C++ working draft, and so is controlled by the flag -fchar8_t rather than a -std= flag. (The GCC implementation is controlled by a flag with the same name.) This implementation is experimental, and will be removed or revised substantially to match the proposal as it makes its way through the C++ committee. llvm-svn: 331244
* [AST] strcmp/memcmp always compares unsigned chars.Benjamin Kramer2018-04-231-2/+12
| | | | | | | This makes it return the right result in a couple of edge cases. The wide versions always do the comparison on the underlying wchar_t type. llvm-svn: 330656
* Clean carriage returns from lib/ and include/. NFC.Malcolm Parsons2018-04-161-41/+41
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Clean carriage returns from lib/ and include/. NFC. (I have to make this change locally in order for `git diff` to show sane output after I edit a file, so I might as well ask for it to be committed. I don't have commit privs myself.) (Without this patch, `git rebase`ing any change involving SemaDeclCXX.cpp is a real nightmare. :( So while I have no right to ask for this to be committed, geez would it make my workflow easier if it were.) Here's the command I used to reformat things. (Requires bash and OSX/FreeBSD sed.) git grep -l $'\r' lib include | xargs sed -i -e $'s/\r//' find lib include -name '*-e' -delete Reviewers: malcolm.parsons Reviewed By: malcolm.parsons Subscribers: emaste, krytarowski, cfe-commits Differential Revision: https://reviews.llvm.org/D45591 Patch by Arthur O'Dwyer. llvm-svn: 330112
* [ExprConstant] Use an AST node and a version number as a key to createAkira Hatanaka2018-04-101-58/+128
| | | | | | | | | | | | | | | an APValue and retrieve it from map Temporaries. The version number is needed when a single AST node is visited multiple times and is used to create APValues that are required to be distinct from each other (for example, MaterializeTemporaryExprs in default arguments and VarDecls in loops). rdar://problem/36505742 Differential Revision: https://reviews.llvm.org/D42776 llvm-svn: 329671
* Disable -fmerge-all-constants as default.Manoj Gupta2018-04-051-3/+0
| | | | | | | | | | | | | | | | | | | Summary: "-fmerge-all-constants" is a non-conforming optimization and should not be the default. It is also causing miscompiles when building Linux Kernel (https://lkml.org/lkml/2018/3/20/872). Fixes PR18538. Reviewers: rjmccall, rsmith, chandlerc Reviewed By: rsmith, chandlerc Subscribers: srhines, cfe-commits Differential Revision: https://reviews.llvm.org/D45289 llvm-svn: 329300
* [AST] Don't track lambda captures when checking a potential constant expression.Erik Pilkington2018-04-051-6/+19
| | | | | | | | Fixes PR36054. Differential revision: https://reviews.llvm.org/D45194 llvm-svn: 329244
* Reland "[Attr] Fix parameter indexing for several attributes"Joel E. Denny2018-03-131-6/+4
| | | | | | | | | Relands r326602 (reverted in r326862) with new test and fix for PR36620. Differential Revision: https://reviews.llvm.org/D43248 llvm-svn: 327405
* PR36645: Go looking for an appropriate array bound when constant-evaluating aRichard Smith2018-03-091-4/+12
| | | | | | name of an array object. llvm-svn: 327099
* Reland r326766 (with a slightly modified test)George Burgess IV2018-03-071-1/+5
| | | | | | | | | The original revert was done in r326869, since reverting r326602 broke the test added by this. The new test should be less dependent on r326602. llvm-svn: 326872
* Revert 326766 too, after r326862 the test fails and I don't know how to fix.Nico Weber2018-03-071-5/+1
| | | | llvm-svn: 326869
* Revert r326602, it caused PR36620.Nico Weber2018-03-071-4/+6
| | | | llvm-svn: 326862
OpenPOWER on IntegriCloud