Commit Graph

522 Commits

Author SHA1 Message Date
David Blaikie 6adc78e0df Replace TypeLoc llvm::cast support to be well-defined.
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
2013-02-18 22:06:02 +00:00
Benjamin Kramer 3e3502686b Make helper functions static.
llvm-svn: 175265
2013-02-15 12:30:38 +00:00
Nick Lewycky a096b14d1d The meat of this patch is in BuildCXXMemberCalLExpr where we make it use
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
2013-02-12 08:08:54 +00:00
Guy Benyei 610541989a Add OpenCL samplers as Clang builtin types and check sampler related restrictions.
llvm-svn: 174601
2013-02-07 10:55:47 +00:00
Richard Smith 6b21696ee8 Add some missing diagnostics for C++11 narrowing conversions.
llvm-svn: 174337
2013-02-05 05:52:24 +00:00
Richard Smith d712d0dbdd Don't forget to run destructors when we create an array temporary of class type.
llvm-svn: 174257
2013-02-02 01:13:06 +00:00
Richard Smith d0c842d7a4 Revert r172285 (suppressing a 'redundant' -Wc++98-compat warning) and add a
testcase for a situation it caused us to miss.

llvm-svn: 173540
2013-01-26 00:39:02 +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
Richard Smith 03d9393b4a Don't crash when binding a reference to a temporary pointer created from
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
2013-01-15 07:58:29 +00:00
Richard Smith a7edaad3b6 Only produce one -Wc++98-compat warning when initializing a reference from an init list with multiple elements.
llvm-svn: 172285
2013-01-12 01:05:20 +00:00
Richard Smith 27874d603b PR14838: When a member reference is bound to a temporary, don't forget to
perform the semantic checks associated with the destruction of that temporary.
It'll be destroyed at the end of the constructor.

llvm-svn: 171818
2013-01-08 00:08:23 +00:00
Richard Smith 2bf7fdb723 s/CPlusPlus0x/CPlusPlus11/g
llvm-svn: 171367
2013-01-02 11:42:31 +00:00
Erik Verbruggen 11a2eccc8b Fix for PR12222.
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
2012-12-25 14:51:39 +00:00
Richard Smith d59b832320 PR13470: Ensure that copy-list-initialization isntantiates as
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
2012-12-19 01:39:02 +00:00
David Blaikie ff7d47a354 Change DeclContextLookup(Const)Result to (Mutable)ArrayRef<NamedDecl*>, as 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
2012-12-19 00:45:41 +00:00
Richard Smith 593f993a68 Implement C++03 [dcl.init]p5's checking for value-initialization of references
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
2012-12-08 02:01:17 +00:00
Chandler Carruth 3a02247dc9 Sort all of Clang's files under 'lib', and fix up the broken headers
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
2012-12-04 09:13:33 +00:00
Richard Smith 2be35f5fbb Consistently use 'needsImplicit<special member>' to determine whether we need
an implicit special member, rather than sometimes using '!hasDeclared<special
member>'. No functionality change.

llvm-svn: 169075
2012-12-01 02:35:44 +00:00
Argyrios Kyrtzidis a6567c4102 Don't return a pointer to an UnresolvedSetImpl in the CXXRecordDecl interface,
expose only the iterators instead.

llvm-svn: 168770
2012-11-28 03:56:09 +00:00
Fariborz Jahanian fbd19749a3 objective-C arc: load of a __weak object happens via call to
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
2012-11-27 23:02:53 +00:00
Argyrios Kyrtzidis 243d82345d Copy the decls returned by DeclContext::lookup_result to a
new container so we can safely iterate over them.

The container holding the lookup decls can under certain conditions
be changed while iterating (e.g. because of deserialization).

llvm-svn: 167816
2012-11-13 05:07:23 +00:00
David Blaikie 12be639dfc PR14021: Copy lookup results to ensure safe iteration.
Within the body of the loop the underlying map may be modified via

  Sema::AddOverloadCandidate
    -> Sema::CompareReferenceRelationship
    -> Sema::RequireCompleteType

to avoid the use of invalid iterators the sequence is copied first.

A reliable, though large, test case is available - it will be reduced and
committed shortly.

Patch by Robert Muth. Review by myself, Nico Weber, and Rafael Espindola.

llvm-svn: 166188
2012-10-18 16:57:32 +00:00
Richard Smith fb26652c43 Tests for DR1507.
llvm-svn: 166162
2012-10-18 00:44:17 +00:00
Richard Smith fafc52c786 Update comment to match DR1502.
llvm-svn: 166158
2012-10-17 23:55:38 +00:00
Richard Trieu 3267347cca Cleaning up the self initialization checker.
-Allow Sema to do more processing on the initial Expr before checking it.
-Remove the special conditions in HandleExpr()
-Move the code so that only one call site is needed.
-Removed the function from Sema and only call it locally.
-Warn on potentially evaluated reference variables, not just casts to r-values.
-Update tests.

llvm-svn: 164951
2012-10-01 17:39:51 +00:00
Richard Smith 845aa66a8a When processing an InitListExpr and skipping the initialization of an invalid
record, skip at least one element from the InitListExpr to avoid an infinite
loop if we're initializing an array of unknown bound.

llvm-svn: 164851
2012-09-28 21:23:50 +00:00
Argyrios Kyrtzidis 54b102985d Move the null check outside of the loop, no functionality change.
llvm-svn: 163553
2012-09-10 22:04:26 +00:00
Benjamin Kramer c215e76f78 Push ArrayRef through the Expr hierarchy.
No functionality change.

llvm-svn: 162552
2012-08-24 11:54:20 +00:00
Benjamin Kramer cc4c49dd63 Now that ASTMultiPtr is nothing more than a array reference, make it a MutableArrayRef.
This required changing all get() calls to data() and using the simpler constructors.

llvm-svn: 162501
2012-08-23 23:38:35 +00:00
Benjamin Kramer f062343889 Remove ASTOwningVector, it doesn't own anything and provides no value over SmallVector.
llvm-svn: 162492
2012-08-23 22:51:59 +00:00
Benjamin Kramer 62b95d88dc Rip out remnants of move semantic emulation and smart pointers in Sema.
These were nops for quite a while and only lead to confusion. ASTMultiPtr
now behaves like a proper dumb array reference.

llvm-svn: 162475
2012-08-23 21:35:17 +00:00
Dmitri Gribenko adba9be7c5 Fix a bunch of -Wdocumentation warnings.
llvm-svn: 162452
2012-08-23 17:58:28 +00:00
Benjamin Kramer e073177e06 Simplify code, no functionality change.
llvm-svn: 161303
2012-08-04 17:00:46 +00:00
Aaron Ballman 899b9c6666 Explicitly defaulted constructors cannot be used for default initialization.
llvm-svn: 161088
2012-07-31 22:40:31 +00:00
Douglas Gregor f4cc61d525 When testing whether we can perform copy or move initialization, be
sure to supply an initialization location. Fixes <rdar://problem/11951661>.

llvm-svn: 161084
2012-07-31 22:15:04 +00:00
Richard Smith e20c83d9ed PR12670: Support for initializing an array of non-aggregate class type from an
initializer list. Patch by Olivier Goffart, with extra testcases by Meador Inge
and Daniel Lunow.

llvm-svn: 159896
2012-07-07 08:35:56 +00:00
Richard Smith d86812d95c PR13273: When performing list-initialization with an empty initializer list,
actually perform value initialization rather than trying to fake it with a call
to the default constructor. Fixes various bugs related to the previously-missing
zero-initialization in this case.

I've also moved this and the other list initialization 'special case' from
TryConstructorInitialization into TryListInitialization where they belong.

llvm-svn: 159733
2012-07-05 08:39:21 +00:00
James Dennett 634962f3e1 Still more Doxygen documentation fixes:
* Escape #, < and @ symbols where Doxygen would try to interpret them;
* Fix several function param documentation where names had got out of sync;
* Delete param documentation referring to parameters that no longer exist.

llvm-svn: 158472
2012-06-14 21:40:34 +00:00
David Blaikie 40ed29730b Revert Decl's iterators back to pointer value_type rather than reference value_type
In addition, I've made the pointer and reference typedef 'void' rather than T*
just so they can't get misused. I would've omitted them entirely but
std::distance likes them to be there even if it doesn't use them.

This rolls back r155808 and r155869.

Review by Doug Gregor incorporating feedback from Chandler Carruth.

llvm-svn: 158104
2012-06-06 20:45:41 +00:00
Richard Smith eb3cad53e7 Add a warning for when an array-to-pointer decay is performed on an array
temporary or an array subobject of a class temporary, and the resulting value
is used to initialize a pointer which outlives the temporary. Such a pointer
is always left dangling after the initialization completes and the array's
lifetime ends.

In order to detect this situation, this change also adds an
LValueClassification of LV_ArrayTemporary for temporaries of array type which
aren't subobjects of class temporaries. These occur in C++11 T{...} and GNU C++
(T){...} expressions, when T is an array type. Previously we treated the former
as a generic prvalue and the latter as a class temporary.

llvm-svn: 157955
2012-06-04 22:27:30 +00:00
Richard Smith e2648bac3a A union can have a constexpr defaulted default constructor, if it has an
in-class initializer for one of its fields. Value-initialization of such
a type should use the in-class initializer!

The former was just a bug, the latter is a (reported) standard defect.

llvm-svn: 156274
2012-05-07 01:07:30 +00:00
Douglas Gregor 7bfb2d026e Move Sema::RequireCompleteType() and Sema::RequireCompleteExprType()
off PartialDiagnostic. PartialDiagnostic is rather heavyweight for
something that is in the critical path and is rarely used. So, switch
over to an abstract-class-based callback mechanism that delays most of
the work until a diagnostic is actually produced. Good for ~11k code
size reduction in the compiler and 1% speedup in -fsyntax-only on the
code in <rdar://problem/11004361>.

llvm-svn: 156176
2012-05-04 16:32:21 +00:00
David Blaikie 2d7c57ec1d Remove the ref/value inconsistency in filter_decl_iterator.
filter_decl_iterator had a weird mismatch where both op* and op-> returned T*
making it difficult to generalize this filtering behavior into a reusable
library of any kind.

This change errs on the side of value, making op-> return T* and op* return
T&.

(reviewed by Richard Smith)

llvm-svn: 155808
2012-04-30 02:36:29 +00:00
Richard Smith 2b349aee5b Add missing -Wc++98-compat warnings for initializer list initializations which
initialize references, create std::initializer_list objects, or call constructors.

llvm-svn: 155105
2012-04-19 06:58:00 +00:00
Douglas Gregor 85f3423509 When we determine that an initialization sequence failed due to an
incomplete type, keep track of the actual type that was
incomplete. Otherwise, we might fail to produce a diagnostic. Fixes
PR12498.

llvm-svn: 154432
2012-04-10 20:43:46 +00:00
John McCall 5dadb65e07 Fix several problems with protected access control:
- The [class.protected] restriction is non-trivial for any instance
    member, even if the access lacks an object (for example, if it's
    a pointer-to-member constant).  In this case, it is equivalent to
    requiring the naming class to equal the context class.
  - The [class.protected] restriction applies to accesses to constructors
    and destructors.  A protected constructor or destructor can only be
    used to create or destroy a base subobject, as a direct result.
  - Several places were dropping or misapplying object information.

The standard could really be much clearer about what the object type is
supposed to be in some of these accesses.  Usually it's easy enough to
find a reasonable answer, but still, the standard makes a very confident
statement about accesses to instance members only being possible in
either pointer-to-member literals or member access expressions, which
just completely ignores concepts like constructor and destructor
calls, using declarations, unevaluated field references, etc.

llvm-svn: 154248
2012-04-07 03:04:20 +00:00
Douglas Gregor bf13895a4b Dependent-sequence initialization of a single element can be direct
list-initialization. Loosen an over-eager assertion to fix PR12453.

llvm-svn: 153995
2012-04-04 04:06:51 +00:00
Matt Beaumont-Gay 5dcce096b6 Silence -Wunused-variable in -Asserts build
llvm-svn: 153885
2012-04-02 19:05:35 +00:00
Sebastian Redl 048a6d7976 Properly handle explicit constructors in list-initialization. Fixes PR12120.
llvm-svn: 153849
2012-04-01 19:54:59 +00:00
Richard Smith 852265ff1c PR10217: Provide diagnostics explaining why an implicitly-deleted special
member function is deleted.

llvm-svn: 153773
2012-03-30 20:53:28 +00:00