aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaInit.cpp
AgeCommit message (Collapse)AuthorFilesLines
2021-11-12Revert "[clang] retain type sugar in auto / template argument deduction"Adrian Kuegel1-2/+2
This reverts commit 9b6036deedf28e10d797fc4ca734d57680d18053. Breaks two libc++ tests.
2021-11-12[clang] retain type sugar in auto / template argument deductionMatheus Izvekov1-2/+2
This implements the following changes: * AutoType retains sugared deduced-as-type. * Template argument deduction machinery analyses the sugared type all the way down. It would previously lose the sugar on first recursion. * Undeduced AutoType will be properly canonicalized, including the constraint template arguments. * Remove the decltype node created from the decltype(auto) deduction. As a result, we start seeing sugared types in a lot more test cases, including some which showed very unfriendly `type-parameter-*-*` types. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D110216
2021-10-11[Sema] Use llvm::is_contained (NFC)Kazu Hirata1-2/+1
2021-09-30[clang] do not emit note for bad conversion when destination type qualifiers ↵Zequan Wu1-3/+7
are not compatibly include source type qualifiers llvm.org/PR52014 Differential Revision: https://reviews.llvm.org/D110780
2021-09-20[clang] Fix a few comment more typos to cycle botsNico Weber1-2/+2
2021-08-25PR51105: look through ConstantExpr when looking for a braced string literal ↵Richard Smith1-1/+1
initialization.
2021-07-28[clang] NFC: change uses of `Expr->getValueKind` into `is?Value`Matheus Izvekov1-1/+1
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D100733
2021-06-29[OpenCL] Fix qualifiers check on binding references to temporariesOle Strohm1-3/+3
Fix the qualifiers check from PR49733. Fixes: PR49733 Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D103962
2021-06-11[ADT] Remove APInt/APSInt toString() std::string variantsSimon Pilgrim1-3/+3
<string> is currently the highest impact header in a clang+llvm build: https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html One of the most common places this is being included is the APInt.h header, which needs it for an old toString() implementation that returns std::string - an inefficient method compared to the SmallString versions that it actually wraps. This patch replaces these APInt/APSInt methods with a pair of llvm::toString() helpers inside StringExtras.h, adjusts users accordingly and removes the <string> from APInt.h - I was hoping that more of these users could be converted to use the SmallString methods, but it appears that most end up creating a std::string anyhow. I avoided trying to use the raw_ostream << operators as well as I didn't want to lose having the integer radix explicit in the code. Differential Revision: https://reviews.llvm.org/D103888
2021-06-09[clang] NFC: rename SK_CastDerivedToBaseRValue to SK_CastDerivedToBasePRValueMatheus Izvekov1-6/+6
This is a follow up to the "rvalue-to-prvalue" rename at D103720. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Depends on D103720 Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D103933
2021-06-09[clang] NFC: Rename rvalue to prvalueMatheus Izvekov1-44/+45
This renames the expression value categories from rvalue to prvalue, keeping nomenclature consistent with C++11 onwards. C++ has the most complicated taxonomy here, and every other language only uses a subset of it, so it's less confusing to use the C++ names consistently, and mentally remap to the C names when working on that context (prvalue -> rvalue, no xvalues, etc). Renames: * VK_RValue -> VK_PRValue * Expr::isRValue -> Expr::isPRValue * SK_QualificationConversionRValue -> SK_QualificationConversionPRValue * JSON AST Dumper Expression nodes value category: "rvalue" -> "prvalue" Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D103720
2021-04-13Remove warning "suggest braces" for aggregate initialization of an empty ↵Hana Dusíková1-12/+24
class with an aggregate base class. I recently ran into issues with aggregates and inheritance, I'm using it for creating a type-safe library where most of the types are build over "tagged" std::array. After bit of cleaning and enabling -Wall -Wextra -pedantic I noticed clang only in my pipeline gives me warning. After a bit of focusing on it I found it's not helpful, and contemplate disabling the warning all together. After a discussion with other library authors I found it's bothering more people and decided to fix it. Removes this warning: template<typename T, int N> struct StdArray { T contents[N]; }; template<typename T, int N> struct AggregateAndEmpty : StdArray<T,N> { }; AggregateAndEmpty<int, 3> p = {1, 2, 3}; // <-- warning here about omitted braces
2021-03-22[clang] Replaced some manual pointer tagging with llvm::PointerIntPair.Joshua Haberman1-6/+4
There is no functional change here (hence no new tests). The only change is to replace a couple uintptr_t members with llvm::PointerIntPair<> to clean up the code, making it more readable and less error prone. This cleanup highlighted that the old code was effectively casting away const. This is fixed by changing some function signatures. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D98889
2021-03-12[OpenCL] Refactor diagnostic for OpenCL extension/featureAnton Zabaznov1-4/+4
There is no need to check for enabled pragma for core or optional core features, thus this check is removed Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D97058
2021-03-09[Clang][Sema] Warn when function argument is less aligned than parameterTomas Matheson1-8/+7
See https://bugs.llvm.org/show_bug.cgi?id=42154. GCC's __attribute__((align)) can reduce the alignment of a type when applied to a typedef. However, functions which take a pointer or reference to the original type are compiled assuming the original alignment. Therefore when any such function is passed an object of the new, less-aligned type, an alignment fault can occur. In particular, this applies to the constructor, which is defined for the original type and called for the less-aligned object. This change adds a warning whenever an pointer or reference to an object is passed to a function that was defined for a more-aligned type. The calls to ASTContext::getTypeAlignInChars seem change the order in which record layouts are evaluated, which caused changes to the output of -fdump-record-layouts. As such some tests needed to be updated: * Use CHECK-LABEL rather than counting the number of "Dumping AST Record Layout" headers. * Check for end of line in labels, so that struct B1 doesn't match struct B etc. * Add --strict-whitespace, since the whitespace shows meaningful structure. * The order in which record layouts are printed has changed in some cases. * clang-format for regions changed Differential Revision: https://reviews.llvm.org/D97187
2021-02-27[clang][Lifetimes] Fix false positive warning from BUG 49342Gabor Horvath1-0/+2
Differential Revision: https://reviews.llvm.org/D97605
2021-02-09PR48545: Access check the inherited constructor, not the inheritingRichard Smith1-5/+6
constructor. We got this wrong only when forming a CXXTemporaryObjectExpr, which caused the bug to only appear for certain syntactic forms.
2021-02-03PR49020: Diagnose brace elision in designated initializers in C++.Richard Smith1-4/+20
This is a corner of the differences between C99 designators and C++20 designators that we'd previously overlooked. As with other such cases, this continues to be permitted as an extension and allowed by default, behind the -Wc99-designators warning flag, except in cases where it leads to a conformance difference (such as in overload resolution and in a SFINAE context).
2021-02-03[OpenCL] Fix address space in binding of initializer lists to referencsAnastasia Stulova1-5/+24
Prevent materializing temporaries in the address space of the references they are bind to. The temporaries should always be in the same address space - private for OpenCL. Tags: #clang Differential Revision: https://reviews.llvm.org/D95608
2021-01-08Attempt to complete an incomplete expression type when considering aRichard Smith1-2/+2
reference binding to an expression. We need to know the array bound in order to determine whether the parameter type is reference-compatible with the argument type, so we need to trigger instantiation in this case.
2021-01-06Fix MaterializeTemporaryExpr's type when its an incomplete array.Erich Keane1-1/+13
Like the VarDecl that gets its type updated based on an init-list, this patch corrects the MaterializeTemporaryExpr's type to make sure it isn't creating an incomplete type, which leads to a handful of CodeGen crashes (see PR 47636). Based on @rsmith 's comments on D88236 Differential Revision: https://reviews.llvm.org/D88298
2021-01-06[Sema] Fix deleted function problem in implicitly movable testYang Fan1-34/+56
In implicitly movable test, a two-stage overload resolution is performed. If the first overload resolution selects a deleted function, Clang directly performs the second overload resolution, without checking whether the deleted function matches the additional criteria. This patch fixes the above problem. Reviewed By: Quuxplusone Differential Revision: https://reviews.llvm.org/D92936
2021-01-04Revert "[Sema] Fix deleted function problem in implicitly movable test"Yang Fan1-46/+21
This reverts commit 89b0972a
2021-01-01[Sema] Fix deleted function problem in implicitly movable testYang Fan1-21/+46
In implicitly movable test, a two-stage overload resolution is performed. If the first overload resolution selects a deleted function, Clang directly performs the second overload resolution, without checking whether the deleted function matches the additional criteria. This patch fixes the above problem. Reviewed By: Quuxplusone Differential Revision: https://reviews.llvm.org/D92936
2020-11-22[Sema] Introduce function reference conversion, NFCAaron Puchert1-4/+24
Technically 'noexcept' isn't a qualifier, so this should be a separate conversion. Also make the test a pure frontend test. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D67112
2020-10-30PR47861: Expand dangling reference warning to look through copyRichard Smith1-13/+102
construction, and to assume that assignment operators return *this.
2020-10-21[c++20] For P0732R2 / P1907R1: Basic frontend support for class types asRichard Smith1-2/+19
non-type template parameters. Create a unique TemplateParamObjectDecl instance for each such value, representing the globally unique template parameter object to which the template parameter refers. No IR generation support yet; that will follow in a separate patch.
2020-10-18PR47870: Properly mangle placeholders for deduced class templateRichard Smith1-2/+2
specializations that have no deduced type.
2020-10-15Switch the default of VerifyIntegerConstantExpression from constantRichard Smith1-1/+2
folding to not constant folding. Constant folding of ICEs is done as a GCC compatibility measure, but new code was picking it up, presumably by accident, due to the bad default. While here, also switch the flag from a bool to an enum to make it more obvious what it means at call sites. This highlighted a couple of places where our behavior is different between C++11 and C++14 due to switching from checking for an ICE to checking for a converted constant expression (where there is no 'fold' codepath).
2020-10-03[Sema] List conversion validate character array.Mark de Wever1-0/+4
The function `TryListConversion` didn't properly validate the following part of the standard: Otherwise, if the parameter type is a character array [... ] and the initializer list has a single element that is an appropriately-typed string literal (8.5.2 [dcl.init.string]), the implicit conversion sequence is the identity conversion. This caused the following call to `f()` to be ambiguous. void f(int(&&)[1]); void f(unsigned(&&)[1]); void g(unsigned i) { f({i}); } This issue only occurs when the initializer list had one element. Differential Revision: https://reviews.llvm.org/D87561
2020-09-21Don't build a StringLiteral expression with reference type whenRichard Smith1-1/+2
performing list-initialization of a char array reference from a braced string literal of a smaller size.
2020-09-14[AST][FPEnv] Keep FP options in trailing storage of CastExprSerge Pavlov1-16/+18
This is recommit of 6c8041aa0f, reverted in de044f7562 because of some fails. Original commit message is below. This change allow a CastExpr to have optional FPOptionsOverride object, stored in trailing storage. Of all cast nodes only ImplicitCastExpr, CStyleCastExpr, CXXFunctionalCastExpr and CXXStaticCastExpr are allowed to have FPOptions. Differential Revision: https://reviews.llvm.org/D85960
2020-09-12Revert "[AST][FPEnv] Keep FP options in trailing storage of CastExpr"Serge Pavlov1-16/+14
This reverts commit 6c8041aa0ffed827636935e59c489b1e390c8542. It caused some fails on buildbots.
2020-09-12[AST][FPEnv] Keep FP options in trailing storage of CastExprSerge Pavlov1-14/+16
This change allow a CastExpr to have optional FPOptionsOverride object, stored in trailing storage. Of all cast nodes only ImplicitCastExpr, CStyleCastExpr, CXXFunctionalCastExpr and CXXStaticCastExpr are allowed to have FPOptions. Differential Revision: https://reviews.llvm.org/D85960
2020-08-12[clang] Check `expr` inside `InitListChecker::UpdateStructuredListElement()`Aleksandr Platonov1-15/+9
- Prevent nullptr-deference at try to emit warning for invalid `expr` - Simplify `InitListChecker::UpdateStructuredListElement()` usages. We do not need to check `expr` and increment `StructuredIndex` (for invalid `expr`) before the call anymore. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D85193
2020-08-07[Clang] Add note for bad conversion when expression is pointer to ↵Zequan Wu1-0/+10
forward-declared type Differential Revision: https://reviews.llvm.org/D85390
2020-07-21[clang] Set the error-bit for ill-formed semantic InitListExpr.Haojian Wu1-0/+2
When a semantic checking fails on a syntactic InitListExpr, we will get an ill-formed semantic InitListExpr (e.g. some inits are nullptr), using this semantic InitListExpr in clang (without setting the err-bits) is crashy. Differential Revision: https://reviews.llvm.org/D84140
2020-07-08[clang] Fix a crash when passing a C structure of incompatible type to a ↵Aleksandr Platonov1-9/+17
function with a reference parameter. __builtin_va_*() and __builtin_ms_va_*() are declared as functions with a parameter of reference type. This patch fixes a crash when using these functions in C where an argument of structure type is incompatible with the parameter type. Differential Revision: https://reviews.llvm.org/D82805 Reviewed By: riccibruno Patch by: Aleksandr Platonov <platonov.aleksandr@huawei.com>
2020-06-10[clang][Attribute] Fix noderef attribute false-negativesLeonard Chan1-3/+7
`noderef` was failing to trigger warnings in some cases related to c++ style casting. This patch addresses them. Differential Revision: https://reviews.llvm.org/D77836
2020-06-02[AST] Fix a null initializer crash for InitListExprHaojian Wu1-1/+1
Summary: The Initializer of a InitListExpr can be reset to null, which leads to nullptr-acces crashes. Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D80980
2020-06-01[Matrix] Implement matrix index expressions ([][]).Florian Hahn1-1/+15
This patch implements matrix index expressions (matrix[RowIdx][ColumnIdx]). It does so by introducing a new MatrixSubscriptExpr(Base, RowIdx, ColumnIdx). MatrixSubscriptExprs are built in 2 steps in ActOnMatrixSubscriptExpr. First, if the base of a subscript is of matrix type, we create a incomplete MatrixSubscriptExpr(base, idx, nullptr). Second, if the base is an incomplete MatrixSubscriptExpr, we create a complete MatrixSubscriptExpr(base->getBase(), base->getRowIdx(), idx) Similar to vector elements, it is not possible to take the address of a MatrixSubscriptExpr. For CodeGen, a new MatrixElt type is added to LValue, which is very similar to VectorElt. The only difference is that we may need to cast the type of the base from an array to a vector type when accessing it. Reviewers: rjmccall, anemet, Bigcheese, rsmith, martong Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D76791
2020-05-06[Sema][SVE] Fix handling of initialisers for built-in SVE typesRichard Sandiford1-17/+33
The built-in SVE types are supposed to be treated as opaque types. This means that for initialisation purposes they should be treated as a single unit, much like a scalar type. However, as Eli pointed out, actually using "scalar" in the diagnostics is likely to cause confusion, given the types are logically vectors. The patch therefore uses custom diagnostics or generalises existing ones. Some of the messages use the word "indivisible" to try to make it clear(er) that these types can't be initialised elementwise. I don't think it's possible to trigger warn_braces_around_(scalar_)init for sizeless types as things stand, since the types can't be used as members or elements of more complex types. But it seemed better to be consistent with ext_many_braces_around_(scalar_)init, so the patch changes it anyway. Differential Revision: https://reviews.llvm.org/D76689
2020-04-22Rename warning identifiers from cxx2a to cxx20; NFC.Aaron Ballman1-2/+2
2020-04-21C++2a -> C++20 in some identifiers; NFC.Aaron Ballman1-1/+1
2020-04-20[SemaObjC] Forbid storing an unboxed integer literal in an NSNumberErik Pilkington1-1/+1
This fixes a common mistake (the 3 should be @3): NSNumber *n = 3. This extends an existing check for NSString. Also, this only errs if the initializer isn't a null pointer constant, so NSNumber *n = 0; continues to work. rdar://47029572 Differential revision: https://reviews.llvm.org/D78066
2020-03-20[clang] Add support for consteval constructorsTyker1-6/+8
Summary: Changes: - handle immediate invocations for constructors. - add tests after this patch i believe the implementation of consteval is nearly standard compliant, but IR-gen still needs to be taught not to emit consteval declarations. Reviewers: rsmith Reviewed By: rsmith Subscribers: wchilders Differential Revision: https://reviews.llvm.org/D74007
2020-02-27Avoid SourceManager.h include in RawCommentList.h, add missing incsReid Kleckner1-0/+1
SourceManager.h includes FileManager.h, which is expensive due to dependencies on LLVM FS headers. Remove dead BeforeThanCompare specialization. Sink ASTContext::addComment to cpp file. This reduces the time to compile a file that does nothing but include ASTContext.h from ~3.4s to ~2.8s for me. Saves these includes: 219 - ../clang/include/clang/Basic/SourceManager.h 204 - ../clang/include/clang/Basic/FileSystemOptions.h 204 - ../clang/include/clang/Basic/FileManager.h 165 - ../llvm/include/llvm/Support/VirtualFileSystem.h 164 - ../llvm/include/llvm/Support/SourceMgr.h 164 - ../llvm/include/llvm/Support/SMLoc.h 161 - ../llvm/include/llvm/Support/Path.h 141 - ../llvm/include/llvm/ADT/BitVector.h 128 - ../llvm/include/llvm/Support/MemoryBuffer.h 124 - ../llvm/include/llvm/Support/FileSystem.h 124 - ../llvm/include/llvm/Support/Chrono.h 124 - .../MSVCSTL/include/stack 122 - ../llvm/include/llvm-c/Types.h 122 - ../llvm/include/llvm/Support/NativeFormatting.h 122 - ../llvm/include/llvm/Support/FormatProviders.h 122 - ../llvm/include/llvm/Support/CBindingWrapping.h 122 - .../MSVCSTL/include/xtimec.h 122 - .../MSVCSTL/include/ratio 122 - .../MSVCSTL/include/chrono 121 - ../llvm/include/llvm/Support/FormatVariadicDetails.h 118 - ../llvm/include/llvm/Support/MD5.h 109 - .../MSVCSTL/include/deque 105 - ../llvm/include/llvm/Support/Host.h 105 - ../llvm/include/llvm/Support/Endian.h Reviewed By: aaron.ballman, hans Differential Revision: https://reviews.llvm.org/D75279
2020-02-11CWG1423: don't permit implicit conversion of nullptr_t to bool.Richard Smith1-4/+21
The C++ rules briefly allowed this, but the rule changed nearly 10 years ago and we never updated our implementation to match. However, we've warned on this by default for a long time, and no other compiler accepts (even as an extension).
2020-01-30Replace 'AllowExplicit' bool with an enum. No functionality change.Richard Smith1-2/+2
In passing, split it up into three values (no explicit functions / explicit conversion functions only / any explicit functions) in preparation for using that in a future change.
2020-01-14PR44540: Prefer an inherited default constructor over an initializerRichard Smith1-2/+2
list constructor when initializing from {}. We would previously pick between calling an initializer list constructor and calling a default constructor unstably in this situation, depending on whether the inherited default constructor had already been used elsewhere in the program.