summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaInit.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Reapply r183721, reverted in r183776, with a fix for a bug in the former (weRichard Smith2013-06-121-5/+13
| | | | | | | | | | | | | | | | | | | | | | | were lacking ExprWithCleanups nodes in some cases where the new approach to lifetime extension needed them). Original commit message: Rework IR emission for lifetime-extended temporaries. Instead of trying to walk into the expression and dig out a single lifetime-extended entity and manually pull its cleanup outside the expression, instead keep a list of the cleanups which we'll need to emit when we get to the end of the full-expression. Also emit those cleanups early, as EH-only cleanups, to cover the case that the full-expression does not terminate normally. This allows IR generation to properly model temporary lifetime when multiple temporaries are extended by the same declaration. We have a pre-existing bug where an exception thrown from a temporary's destructor does not clean up lifetime-extended temporaries created in the same expression and extended to automatic storage duration; that is not fixed by this patch. llvm-svn: 183859
* Tweak r183791 so we don't print a note without a source location.Eli Friedman2013-06-111-2/+2
| | | | llvm-svn: 183803
* Correctly handle designated initializers which modify an array initializedEli Friedman2013-06-111-0/+58
| | | | | | | | | | with a string. This case is sort of tricky because we can't modify the StringLiteral used to represent such initializers. We are forced to decompose the string into individual characters. Fixes <rdar://problem/10465114>. llvm-svn: 183791
* Revert r183721. It caused cleanups to be delayed too long in some cases.Richard Smith2013-06-111-3/+0
| | | | | | Testcase to follow. llvm-svn: 183776
* Rework IR emission for lifetime-extended temporaries. Instead of trying to walkRichard Smith2013-06-111-0/+3
| | | | | | | | | | | | | | | | | into the expression and dig out a single lifetime-extended entity and manually pull its cleanup outside the expression, instead keep a list of the cleanups which we'll need to emit when we get to the end of the full-expression. Also emit those cleanups early, as EH-only cleanups, to cover the case that the full-expression does not terminate normally. This allows IR generation to properly model temporary lifetime when multiple temporaries are extended by the same declaration. We have a pre-existing bug where an exception thrown from a temporary's destructor does not clean up lifetime-extended temporaries created in the same expression and extended to automatic storage duration; that is not fixed by this patch. llvm-svn: 183721
* Recursively lifetime-extend into array temporaries. These can get implicitlyRichard Smith2013-06-081-4/+3
| | | | | | created through binding a reference-to-array to an initializer list. llvm-svn: 183594
* Implement DR1270: braces can be elided in all aggregate initialization, notRichard Smith2013-06-061-22/+8
| | | | | | | just copy-list-initialization in a variable declaration. This effectively reverts r142147. llvm-svn: 183397
* Silence GCC warning.Benjamin Kramer2013-06-051-0/+1
| | | | llvm-svn: 183317
* Model temporary lifetime-extension explicitly in the AST. Use this model toRichard Smith2013-06-051-4/+188
| | | | | | | | | 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
* Fix handling of braced-init-list as reference initializer within aggregateRichard Smith2013-05-311-5/+6
| | | | | | | initialization. Previously we would incorrectly require an extra set of braces around such initializers. llvm-svn: 182983
* Fix crash-on-invalid if list-initialization works, but we bail out whenRichard Smith2013-05-231-1/+2
| | | | | | building the resulting expression because it invokes a deleted constructor. llvm-svn: 182624
* SemaInit.cpp: give both IsStringInit() functions the same return type.Hans Wennborg2013-05-161-4/+6
| | | | | | This addresses Richard's comment on r181880. llvm-svn: 181995
* Better diagnostics for string initialization.Hans Wennborg2013-05-151-36/+131
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit improves Clang's diagnostics for string initialization. Where it would previously say: /tmp/a.c:3:9: error: array initializer must be an initializer list wchar_t s[] = "Hi"; ^ /tmp/a.c:4:6: error: array initializer must be an initializer list or string literal char t[] = L"Hi"; ^ It will now say /tmp/a.c:3:9: error: initializing wide char array with non-wide string literal wchar_t s[] = "Hi"; ^ /tmp/a.c:4:6: error: initializing char array with wide string literal char t[] = L"Hi"; ^ As a bonus, it also fixes the fact that Clang would previously reject this valid C11 code: char16_t s[] = u"hi"; char32_t t[] = U"hi"; because it would only recognize the built-in types for char16_t and char32_t, which do not exist in C. llvm-svn: 181880
* Add support for __wchar_t in -fms-extensions mode.Hans Wennborg2013-05-101-1/+1
| | | | | | | | | | | | | | | | | MSVC provides __wchar_t. This is the same as the built-in wchar_t type from C++, but it is also available with -fno-wchar and in C. The commit changes ASTContext to have two different types for this: - WCharTy is the built-in type used for wchar_t in C++ and __wchar_t. - WideCharTy is the type of a wide character literal. In C++ this is the same as WCharTy, and in C it is an integer type compatible with the type in <stddef.h>. This fixes PR15815. llvm-svn: 181587
* Grab-bag of bit-field fixes:John McCall2013-05-061-5/+10
| | | | | | | | | | | | | | - 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
* Fix representation of compound literals for C++ objects with destructors.Jordan Rose2013-05-061-5/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, this compound literal expression (a GNU extension in C++): (AggregateWithDtor){1, 2} resulted in this AST: `-CXXBindTemporaryExpr [...] 'struct Point' (CXXTemporary [...]) `-CompoundLiteralExpr [...] 'struct AggregateWithDtor' `-CXXBindTemporaryExpr [...] 'struct AggregateWithDtor' (CXXTemporary [...]) `-InitListExpr [...] 'struct AggregateWithDtor' |-IntegerLiteral [...] 'int' 1 `-IntegerLiteral [...] 'int' 2 Note the two CXXBindTemporaryExprs. The InitListExpr is really part of the CompoundLiteralExpr, not an object in its own right. By introducing a new entity initialization kind in Sema specifically for compound literals, we avoid the treatment of the inner InitListExpr as a temporary. `-CXXBindTemporaryExpr [...] 'struct Point' (CXXTemporary [...]) `-CompoundLiteralExpr [...] 'struct AggregateWithDtor' `-InitListExpr [...] 'struct AggregateWithDtor' |-IntegerLiteral [...] 'int' 1 `-IntegerLiteral [...] 'int' 2 llvm-svn: 181212
* Fix assert if __extension__ or _Generic is used when initializing a char ↵Richard Smith2013-05-061-4/+11
| | | | | | array from a string literal. llvm-svn: 181174
* Replace 'MultiExprArg()' with 'None'Dmitri Gribenko2013-05-051-7/+7
| | | | llvm-svn: 181166
* Handle parens properly when initializing a char array from a string literal.Richard Smith2013-05-051-3/+14
| | | | llvm-svn: 181159
* Replace ArrayRef<T>() with None, now that we have an implicit ArrayRef ↵Dmitri Gribenko2013-05-051-2/+2
| | | | | | | | constructor from None Patch by Robert Wilhelm. llvm-svn: 181139
* Don't build a call expression referring to a function which we're not allowedRichard Smith2013-05-041-7/+14
| | | | | | | | | to use. This makes very little difference right now (other than suppressing follow-on errors in some cases), but will matter more once we support deduced return types (we don't want expressions with undeduced return types in the AST). llvm-svn: 181107
* ArrayRef'ize InitializationSequence constructor and ↵Dmitri Gribenko2013-05-031-65/+52
| | | | | | | | InitializationSequence::Diagnose() Patch by Robert Wilhelm. llvm-svn: 181022
* C++1y: support simple variable assignments in constexpr functions.Richard Smith2013-04-261-0/+1
| | | | llvm-svn: 180603
* C++1y: Allow aggregates to have default initializers.Richard Smith2013-04-201-10/+49
| | | | | | | | | | | 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
* Basic support for Microsoft property declarations andJohn McCall2013-04-161-12/+15
| | | | | | | | references thereto. Patch by Tong Shen! llvm-svn: 179585
* Force a load when creating a reference to a temporary copied from a bitfield.Jordan Rose2013-04-111-9/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* <rdar://problem/13278115> Improve diagnostic when failing to bind an rvalue ↵Douglas Gregor2013-03-261-0/+8
| | | | | | reference to an lvalue of compatible type. llvm-svn: 178095
* <rdar://problem/13395022> Strip references when extracting an ↵Douglas Gregor2013-03-251-2/+2
| | | | | | initializer_list's element type during application of an initialization sequence. llvm-svn: 177944
* Add a clarifying note when a return statement is rejected becauseJohn McCall2013-03-191-6/+22
| | | | | | | | we expect a related result type. rdar://12493140 llvm-svn: 177378
* Bring inheriting constructor implementation up-to-date with current defectRichard Smith2013-03-181-3/+6
| | | | | | | | | reports, and implement implicit definition of inheriting constructors. Remaining missing features: inheriting constructor templates, implicit exception specifications for inheriting constructors, inheriting constructors from dependent bases. llvm-svn: 177320
* Replace TypeLoc llvm::cast support to be well-defined.David Blaikie2013-02-181-3/+3
| | | | | | | | | | | | | | The TypeLoc hierarchy used the llvm::cast machinery to perform undefined behavior by casting pointers/references to TypeLoc objects to derived types and then using the derived copy constructors (or even returning pointers to derived types that actually point to the original TypeLoc object). Some context is in this thread: http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/056804.html Though it's spread over a few months which can be hard to read in the mail archive. llvm-svn: 175462
* Make helper functions static.Benjamin Kramer2013-02-151-1/+2
| | | | llvm-svn: 175265
* The meat of this patch is in BuildCXXMemberCalLExpr where we make it useNick Lewycky2013-02-121-7/+4
| | | | | | | | | | | | MarkMemberReferenced instead of marking functions referenced directly. An audit of callers to MarkFunctionReferenced and DiagnoseUseOfDecl also caused a few other changes: * don't mark functions odr-used when considering them for an initialization sequence. Do mark them referenced though. * the function nominated by the cleanup attribute should be diagnosed. * operator new/delete should be diagnosed when building a 'new' expression. llvm-svn: 174951
* Add OpenCL samplers as Clang builtin types and check sampler related ↵Guy Benyei2013-02-071-1/+45
| | | | | | restrictions. llvm-svn: 174601
* Add some missing diagnostics for C++11 narrowing conversions.Richard Smith2013-02-051-4/+9
| | | | llvm-svn: 174337
* Don't forget to run destructors when we create an array temporary of class type.Richard Smith2013-02-021-2/+5
| | | | llvm-svn: 174257
* Revert r172285 (suppressing a 'redundant' -Wc++98-compat warning) and add aRichard Smith2013-01-261-1/+0
| | | | | | testcase for a situation it caused us to miss. llvm-svn: 173540
* Implement OpenCL event_t as Clang builtin type, including event_t related ↵Guy Benyei2013-01-201-1/+48
| | | | | | OpenCL restrictions (OpenCL 1.2 spec 6.9) llvm-svn: 172973
* Don't crash when binding a reference to a temporary pointer created fromRichard Smith2013-01-151-0/+4
| | | | | | | | resolving an overloaded function reference within an initializer list. Previously we would try to resolve the overloaded function reference without first stripping off the InitListExpr wrapper. llvm-svn: 172517
* Only produce one -Wc++98-compat warning when initializing a reference from ↵Richard Smith2013-01-121-0/+1
| | | | | | an init list with multiple elements. llvm-svn: 172285
* PR14838: When a member reference is bound to a temporary, don't forget toRichard Smith2013-01-081-2/+2
| | | | | | | perform the semantic checks associated with the destruction of that temporary. It'll be destroyed at the end of the constructor. llvm-svn: 171818
* s/CPlusPlus0x/CPlusPlus11/gRichard Smith2013-01-021-17/+17
| | | | llvm-svn: 171367
* Fix for PR12222.Erik Verbruggen2012-12-251-5/+5
| | | | | | | | 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
* PR13470: Ensure that copy-list-initialization isntantiates asRichard Smith2012-12-191-10/+16
| | | | | | | | | | | | copy-list-initialization (and doesn't add an additional copy step): Fill in the ListInitialization bit when creating a CXXConstructExpr. Use it when instantiating initializers in order to correctly handle instantiation of copy-list-initialization. Teach TreeTransform that function arguments are initializations, and so need this special treatment too. Finally, remove some hacks which were working around SubstInitializer's shortcomings. llvm-svn: 170489
* Change DeclContextLookup(Const)Result to (Mutable)ArrayRef<NamedDecl*>, as ↵David Blaikie2012-12-191-14/+10
| | | | | | | | | | | | | | | per review discussion in r170365 This does limit these typedefs to being sequences, but no current usage requires them to be contiguous (we could expand this to a more general iterator pair range concept at some point). Also, it'd be nice if SmallVector were constructible directly from an ArrayRef but this is a bit tricky since ArrayRef depends on SmallVectorBaseImpl for the inverse conversion. (& generalizing over all range-like things, while nice, would require some nontrivial SFINAE I haven't thought about yet) llvm-svn: 170482
* Implement C++03 [dcl.init]p5's checking for value-initialization of referencesRichard Smith2012-12-081-4/+64
| | | | | | | | properly, rather than faking it up by pretending that a reference member makes the default constructor non-trivial. That leads to rejects-valids when putting such types inside unions. llvm-svn: 169662
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-4/+4
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
* Consistently use 'needsImplicit<special member>' to determine whether we needRichard Smith2012-12-011-5/+2
| | | | | | | an implicit special member, rather than sometimes using '!hasDeclared<special member>'. No functionality change. llvm-svn: 169075
* Don't return a pointer to an UnresolvedSetImpl in the CXXRecordDecl interface,Argyrios Kyrtzidis2012-11-281-9/+10
| | | | | | expose only the iterators instead. llvm-svn: 168770
* objective-C arc: load of a __weak object happens via call toFariborz Jahanian2012-11-271-7/+19
| | | | | | | | | | | objc_loadWeak. This retains and autorelease the weakly-refereced object. This hidden autorelease sometimes makes __weak variable alive even after the weak reference is erased, because the object is still referenced by an autorelease pool. This patch overcomes this behavior by loading a weak object via call to objc_loadWeakRetained(), followng it by objc_release at appropriate place, thereby removing the hidden autorelease. // rdar://10849570 llvm-svn: 168740
OpenPOWER on IntegriCloud