summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST
Commit message (Collapse)AuthorAgeFilesLines
...
* Treat the range of representable values of floating-point types as [-inf, ↵Richard Smith2019-07-061-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +inf] not as [-max, +max]. Summary: Prior to r329065, we used [-max, max] as the range of representable values because LLVM's `fptrunc` did not guarantee defined behavior when truncating from a larger floating-point type to a smaller one. Now that has been fixed, we can make clang follow normal IEEE 754 semantics in this regard and take the larger range [-inf, +inf] as the range of representable values. In practice, this affects two parts of the frontend: * the constant evaluator no longer treats floating-point evaluations that result in +-inf as being undefined (because they no longer leave the range of representable values of the type) * UBSan no longer treats conversions to floating-point type that are outside the [-max, +max] range as being undefined In passing, also remove the float-divide-by-zero sanitizer from -fsanitize=undefined, on the basis that while it's undefined per C++ rules (and we disallow it in constant expressions for that reason), it is defined by Clang / LLVM / IEEE 754. Reviewers: rnk, BillyONeal Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63793 llvm-svn: 365272
* Fix -Wcast-qual const warning. NFCI.Simon Pilgrim2019-07-031-1/+1
| | | | llvm-svn: 365031
* Fix MSVC "not all control paths return a value" warnings. NFCI.Simon Pilgrim2019-07-031-0/+2
| | | | llvm-svn: 365012
* Change std::{lower,upper}_bound to llvm::{lower,upper}_bound or ↵Fangrui Song2019-07-032-8/+5
| | | | | | llvm::partition_point. NFC llvm-svn: 365006
* [C++2a] Add __builtin_bit_cast, used to implement std::bit_castErik Pilkington2019-07-026-7/+523
| | | | | | | | | | | | | | | | | | This commit adds a new builtin, __builtin_bit_cast(T, v), which performs a bit_cast from a value v to a type T. This expression can be evaluated at compile time under specific circumstances. The compile time evaluation currently doesn't support bit-fields, but I'm planning on fixing this in a follow up (some of the logic for figuring this out is in CodeGen). I'm also planning follow-ups for supporting some more esoteric types that the constexpr evaluator supports, as well as extending __builtin_memcpy constexpr evaluation to use the same infrastructure. rdar://44987528 Differential revision: https://reviews.llvm.org/D62825 llvm-svn: 364954
* [ASTImporter] Structural eq: handle DependentScopeDeclRefExprGabor Marton2019-07-021-1/+74
| | | | | | | | | | | | | | | | Summary: Structural equivalence did not handle dependent template args properly when the arg contained a DependentScopeDeclRefExpr. Reviewers: a_sidorin, a.sidorin Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62329 llvm-svn: 364889
* [ASTImporter] Mark erroneous nodes in shared stGabor Marton2019-07-011-14/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Now we store the errors for the Decls in the "to" context too. For that, however, we have to put these errors in a shared state (among all the ASTImporter objects which handle the same "to" context but different "from" contexts). After a series of imports from different "from" TUs we have a "to" context which may have erroneous nodes in it. (Remember, the AST is immutable so there is no way to delete a node once we had created it and we realized the error later.) All these erroneous nodes are marked in ASTImporterSharedState::ImportErrors. Clients of the ASTImporter may use this as an input. E.g. the static analyzer engine may not try to analyze a function if that is marked as erroneous (it can be queried via ASTImporterSharedState::getImportDeclErrorIfAny()). Reviewers: a_sidorin, a.sidorin, shafik Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62376 llvm-svn: 364785
* [ASTImporter] Silence unused variable warning in Release builds. NFC.Benjamin Kramer2019-07-011-0/+1
| | | | llvm-svn: 364774
* [ASTImporter] Mark erroneous nodes in from ctxGabor Marton2019-07-011-8/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: During import of a specific Decl D, it may happen that some AST nodes had already been created before we recognize an error. In this case we signal back the error to the caller, but the "to" context remains polluted with those nodes which had been created. Ideally, those nodes should not had been created, but that time we did not know about the error, the error happened later. Since the AST is immutable (most of the cases we can't remove existing nodes) we choose to mark these nodes as erroneous. Here are the steps of the algorithm: 1) We keep track of the nodes which we visit during the import of D: See ImportPathTy. 2) If a Decl is already imported and it is already on the import path (we have a cycle) then we copy/store the relevant part of the import path. We store these cycles for each Decl. 3) When we recognize an error during the import of D then we set up this error to all Decls in the stored cycles for D and we clear the stored cycles. Reviewers: a_sidorin, a.sidorin, shafik Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62375 llvm-svn: 364771
* [ASTImporter] Propagate error from ImportDeclContextGabor Marton2019-07-011-6/+27
| | | | | | | | | | | | | | | | | | | | | | Summary: During analysis of one project we failed to import one CXXDestructorDecl. But since we did not propagate the error in importDeclContext we had a CXXRecordDecl without a destructor. Then the analyzer engine had a CallEvent where the nonexistent dtor was requested (crash). Solution is to propagate the errors we have during importing a DeclContext. Reviewers: a_sidorin, a.sidorin, shafik Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63603 llvm-svn: 364752
* [ODRHash] Fix null pointer dereference for ObjC selectors with empty slots.Volodymyr Sapsai2019-06-281-1/+6
| | | | | | | | | | | | | | | | | `Selector::getIdentifierInfoForSlot` returns NULL if a slot has no corresponding identifier. Add a boolean to the hash and a NULL check. rdar://problem/51615164 Reviewers: rtrieu Reviewed By: rtrieu Subscribers: dexonsmith, cfe-commits, jkorous Differential Revision: https://reviews.llvm.org/D63789 llvm-svn: 364664
* Revert r363191 "[MS] Pretend constexpr variable template specializations are ↵Reid Kleckner2019-06-261-19/+4
| | | | | | | | | inline" The next Visual Studio update will fix this issue, and it doesn't make sense to implement this non-conforming behavior going forward. llvm-svn: 364476
* [ASTImporter] Store import errors for DeclsGabor Marton2019-06-251-18/+80
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: We add a new member which is a mapping from the already-imported declarations in the "from" context to the error status of the import of that declaration. This map contains only the declarations that were not correctly imported. The same declaration may or may not be included in ImportedDecls. This map is updated continuously during imports and never cleared (like ImportedDecls). In Import(Decl*) we use this mapping, so if there was a previous failed import we return with the existing error. We add/remove from the Lookuptable in consistency with ImportedFromDecls. When we map a decl in the 'to' context to something in the 'from' context then and only then we add it to the lookup table. When we remove a mapping then and only then we remove it from the lookup table. This patch is the first in a series of patches whose aim is to further strengthen the error handling in ASTImporter. Reviewers: a_sidorin, a.sidorin, shafik Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62373 llvm-svn: 364279
* [cxx2a] P1236R1: the validity of a left shift does not depend on theRichard Smith2019-06-251-1/+3
| | | | | | value of the LHS operand. llvm-svn: 364265
* Augment location information when dumping the AST to JSON.Aaron Ballman2019-06-241-33/+44
| | | | | | Rather than create JSON objects for source locations and ranges, we instead stream them out directly. This allows us to elide duplicate information (without JSON field reordering causing an issue) like file names and line numbers, similar to the text dump. This also adds token length information when dumping the source location. llvm-svn: 364226
* [ODRHash] Skip some typedef types.Richard Trieu2019-06-221-0/+45
| | | | | | | | | | | | | | | In some cases, a typedef only strips aways a keyword for a type, keeping the same name as the root record type. This causes some confusion when the type is defined in one modules but only forward declared in another. Skipping the typedef and going straight to the record will avoid this issue. typedef struct S {} S; S* s; // S is TypedefType here struct S; S* s; // S is RecordType here llvm-svn: 364119
* Ensure that top-level QualType objects also have a "kind" field when dumping ↵Aaron Ballman2019-06-211-0/+1
| | | | | | the AST to JSON. llvm-svn: 364078
* Print more type node information when dumping the AST to JSON.Aaron Ballman2019-06-211-0/+20
| | | | llvm-svn: 364067
* Print information about various type nodes when dumping the AST to JSON.Aaron Ballman2019-06-211-0/+119
| | | | llvm-svn: 364043
* [clang] Small improvments after Adding APValue to ConstantExprGauthier Harnisch2019-06-213-8/+33
| | | | | | | | | | | | | | | | | | | | | | | Summary: this patch has multiple small improvements related to the APValue in ConstantExpr. changes: - APValue in ConstantExpr are now cleaned up using ASTContext::addDestruction instead of there own system. - ConstantExprBits Stores the ValueKind of the result beaing stored. - VerifyIntegerConstantExpression now stores the evaluated value in ConstantExpr. - the Constant Evaluator uses the stored value of ConstantExpr when available. Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63376 llvm-svn: 364011
* Print information about various ObjC expression nodes when dumping the AST ↵Aaron Ballman2019-06-201-0/+90
| | | | | | to JSON. llvm-svn: 363988
* P0840R2: support for [[no_unique_address]] attributeRichard Smith2019-06-203-45/+136
| | | | | | | | | | | | | | | | | Summary: Add support for the C++2a [[no_unique_address]] attribute for targets using the Itanium C++ ABI. This depends on D63371. Reviewers: rjmccall, aaron.ballman Subscribers: dschuff, aheejin, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63451 llvm-svn: 363976
* Fix crash and rejects-valid when a later template parameter or defaultRichard Smith2019-06-201-1/+1
| | | | | | | | | | | | | | | | | | | | template argument contains a backreference to a dependently-typed earlier parameter. In a case like: template<typename T, T A, decltype(A) = A> struct X {}; template<typename U> auto Y = X<U, 0>(); we previously treated both references to `A` in the third parameter as being of type `int` when checking the template-id in `Y`. That`s wrong; the type of `A` in these contexts is the dependent type `U`. When we encounter a non-type template argument that we can't convert to the parameter type because of type-dependence, we now insert a dependent conversion node so that the SubstNonTypeTemplateParmExpr for the template argument will have the parameter's type rather than whatever type the argument had. llvm-svn: 363972
* Print additional information about @encode expressions when dumping the AST ↵Aaron Ballman2019-06-201-0/+4
| | | | | | to JSON. llvm-svn: 363966
* Print additional information on dependent scopes when dumping the AST to JSON.Aaron Ballman2019-06-201-0/+17
| | | | llvm-svn: 363965
* Dump more information about expressions involving temporaries when dumping ↵Aaron Ballman2019-06-201-0/+45
| | | | | | the AST to JSON. llvm-svn: 363943
* Removing a helper function that was trivial to inline into its only use; NFC.Aaron Ballman2019-06-201-8/+3
| | | | llvm-svn: 363935
* Dump more information about construct expressions (resolved and unresolved) ↵Aaron Ballman2019-06-201-0/+32
| | | | | | when dumping the AST to JSON. llvm-svn: 363926
* [clang][AST] Refactoring ASTNameGenerator to use pimpl pattern (NFC).Puyan Lotfi2019-06-201-146/+168
| | | | | | | | | | | The original pimpl pattern used between CodegenNameGenerator and CodegenNameGeneratorImpl did a good job of hiding DataLayout making it so that users of CodegenNameGenerator did not need to link with llvm core. This is an NFC change to neatly wrap ASTNameGenerator in a pimpl. Differential Revision: https://reviews.llvm.org/D63584 llvm-svn: 363908
* [clang][AST] ASTNameGenerator: A refactoring of CodegenNameGeneratorImpl (NFC).Puyan Lotfi2019-06-192-0/+184
| | | | | | | | | | | | This is a NFC refactor move of CodegenNameGeneratorImpl from clang::Index to clang:AST (and rename to ASTNameGenerator). The purpose is to make the highlevel mangling code more reusable inside of clang (say in places like clang FrontendAction). This does not affect anything in CodegenNameGenerator, except that CodegenNameGenerator will now use ASTNameGenerator (in AST). Differential Revision: https://reviews.llvm.org/D63535 llvm-svn: 363878
* Print whether a generic selection expression is result dependent when ↵Aaron Ballman2019-06-191-0/+5
| | | | | | dumping the AST to JSON. llvm-svn: 363873
* Print out the union field being initialized by an InitListExpr when dumping ↵Aaron Ballman2019-06-191-0/+5
| | | | | | the AST to JSON. llvm-svn: 363869
* Dump the value calculated by a constant expression when dumping the AST to JSON.Aaron Ballman2019-06-191-0/+9
| | | | llvm-svn: 363866
* [AST] Fixed extraneous warnings for binary conditional operatorNathan Huckleberry2019-06-191-6/+7
| | | | | | | | | | | | | | | | | | | | Summary: Binary conditional operator gave warnings where ternary operators did not. They have been fixed to warn similarly to ternary operators. Link: https://bugs.llvm.org/show_bug.cgi?id=42239 Reviewers: rsmith, aaron.ballman, nickdesaulniers Reviewed By: rsmith, nickdesaulniers Subscribers: srhines, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D63369 llvm-svn: 363857
* Change the way we output templates for JSON AST dumping and dump information ↵Aaron Ballman2019-06-191-0/+67
| | | | | | | | about template arguments. Previously, we attempted to write out template parameters and specializations to their own array, but due to the architecture of the ASTNodeTraverser, this meant that other nodes were not being written out. This now follows the same behavior as the regular AST dumper and puts all the (correct) information into the "inner" array. When we correct the AST node traverser itself, we can revisit splitting this information into separate arrays again. llvm-svn: 363819
* [OPENMP]Use host's mangling for 128 bit float types on the device.Alexey Bataev2019-06-181-6/+22
| | | | | | Device have to use the same mangling as the host for 128bit float types. Otherwise, the codegen for the device is unable to find the parent function when it tries to generate the outlined function for the target region and it leads to incorrect compilation and crash at the runtime. llvm-svn: 363734
* [OPENMP]Use host's long double when compiling the code for device.Alexey Bataev2019-06-181-2/+9
| | | | | | | | | The device code must use the same long double type as the host. Otherwise the code cannot be linked and executed properly. Patch adds only basic support and checks for supporting of the host long double double on the device. llvm-svn: 363717
* Fix crash when checking a dependently-typed reference that isRichard Smith2019-06-171-1/+1
| | | | | | initialized from a non-value-dependent initializer. llvm-svn: 363622
* [clang] Add storage for APValue in ConstantExprGauthier Harnisch2019-06-155-38/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When using ConstantExpr we often need the result of the expression to be kept in the AST. Currently this is done on a by the node that needs the result and has been done multiple times for enumerator, for constexpr variables... . This patch adds to ConstantExpr the ability to store the result of evaluating the expression. no functional changes expected. Changes: - Add trailling object to ConstantExpr that can hold an APValue or an uint64_t. the uint64_t is here because most ConstantExpr yield integral values so there is an optimized layout for integral values. - Add basic* serialization support for the trailing result. - Move conversion functions from an enum to a fltSemantics from clang::FloatingLiteral to llvm::APFloatBase. this change is to make it usable for serializing APValues. - Add basic* Import support for the trailing result. - ConstantExpr created in CheckConvertedConstantExpression now stores the result in the ConstantExpr Node. - Adapt AST dump to print the result when present. basic* : None, Indeterminate, Int, Float, FixedPoint, ComplexInt, ComplexFloat, the result is not yet used anywhere but for -ast-dump. Reviewers: rsmith, martong, shafik Reviewed By: rsmith Subscribers: rnkovacs, hiraditya, dexonsmith, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D62399 llvm-svn: 363493
* [clang] perform semantic checking in constant contextGauthier Harnisch2019-06-151-14/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Since the addition of __builtin_is_constant_evaluated the result of an expression can change based on whether it is evaluated in constant context. a lot of semantic checking performs evaluations with out specifying context. which can lead to wrong diagnostics. for example: ``` constexpr int i0 = (long long)__builtin_is_constant_evaluated() * (1ll << 33); //#1 constexpr int i1 = (long long)!__builtin_is_constant_evaluated() * (1ll << 33); //#2 ``` before the patch, #2 was diagnosed incorrectly and #1 wasn't diagnosed. after the patch #1 is diagnosed as it should and #2 isn't. Changes: - add a flag to Sema to passe in constant context mode. - in SemaChecking.cpp calls to Expr::Evaluate* are now done in constant context when they should. - in SemaChecking.cpp diagnostics for UB are not checked for in constant context because an error will be emitted by the constant evaluator. - in SemaChecking.cpp diagnostics for construct that cannot appear in constant context are not checked for in constant context. - in SemaChecking.cpp diagnostics on constant expression are always emitted because constant expression are always evaluated. - semantic checking for initialization of constexpr variables is now done in constant context. - adapt test that were depending on warning changes. - add test. Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62009 llvm-svn: 363488
* Use getOperatorSpelling to get the spelling of an overloaded operatorRichard Smith2019-06-143-25/+6
| | | | | | rather than duplicating operator name tables in multiple places. llvm-svn: 363446
* PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of typeRichard Smith2019-06-141-0/+5
| | | | | | | | | | | nullptr_t does not access memory. We now reuse CK_NullToPointer to represent a conversion from a glvalue of type nullptr_t to a prvalue of nullptr_t where necessary. This reinstates r363337, reverted in r363352. llvm-svn: 363429
* [C++20] add Basic consteval specifierGauthier Harnisch2019-06-145-41/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: this revision adds Lexing, Parsing and Basic Semantic for the consteval specifier as specified by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1073r3.html with this patch, the consteval specifier is treated as constexpr but can only be applied to function declaration. Changes: - add the consteval keyword. - add parsing of consteval specifier for normal declarations and lambdas expressions. - add the whether a declaration is constexpr is now represented by and enum everywhere except for variable because they can't be consteval. - adapt diagnostic about constexpr to print constexpr or consteval depending on the case. - add tests for basic semantic. Reviewers: rsmith, martong, shafik Reviewed By: rsmith Subscribers: eraman, efriedma, rnkovacs, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61790 llvm-svn: 363362
* Revert 363295, it caused PR42276. Also revert follow-ups 363337, 363340.Nico Weber2019-06-141-5/+0
| | | | | | | | Revert 363340 "Remove unused SK_LValueToRValue initialization step." Revert 363337 "PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of type" Revert 363295 "C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue conversion applied to a member access or similar not-quite-trivial lvalue expression." llvm-svn: 363352
* PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of typeRichard Smith2019-06-131-0/+5
| | | | | | | | | | | | nullptr_t does not access memory. We now reuse CK_NullToPointer to represent a conversion from a glvalue of type nullptr_t to a prvalue of nullptr_t where necessary. This reinstates r345562, reverted in r346065, now that CodeGen's handling of non-odr-used variables has been fixed. llvm-svn: 363337
* Add comment to r363191 code as requested in code reviewReid Kleckner2019-06-121-2/+5
| | | | llvm-svn: 363195
* [MS] Pretend constexpr variable template specializations are inlineReid Kleckner2019-06-121-4/+16
| | | | | | | | | | | | | | | | | | | Fixes link errors with clang and the latest Visual C++ 14.21.27702 headers, which was reported as PR42027. I chose to intentionally make these things linkonce_odr, i.e. discardable, so that we don't emit definitions of these things in every translation unit that includes STL headers. Note that this is *not* what MSVC does: MSVC has not yet implemented C++ DR2387, so they emit fully specialized constexpr variable templates with static / internal linkage. Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D63175 llvm-svn: 363191
* For DR712: store on a MemberExpr whether it constitutes an odr-use.Richard Smith2019-06-114-8/+23
| | | | llvm-svn: 363087
* For DR712: store on a DeclRefExpr whether it constitutes an odr-use.Richard Smith2019-06-115-19/+51
| | | | | | | Begin restructuring to support the forms of non-odr-use reference permitted by DR712. llvm-svn: 363086
* [ASTImporter] Fix unhandled cases in ASTImporterLookupTableGabor Marton2019-06-112-7/+21
| | | | | | | | | | | | | | | | | | | | | Summary: In most cases the FriendDecl contains the declaration of the befriended class as a child node, so it is discovered during the recursive visitation. However, there are cases when the befriended class is not a child, thus it must be fetched explicitly from the FriendDecl, and only then can we add it to the lookup table. (Note, this does affect only CTU and does not affect LLDB, because we cannot and do not use the ASTImporterLookupTable in LLDB.) Reviewers: a_sidorin, a.sidorin, shafik Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62064 llvm-svn: 363062
OpenPOWER on IntegriCloud