Commit Graph

1192 Commits

Author SHA1 Message Date
Fariborz Jahanian abaae2b692 Some support for unicode string constants
in wide strings. radar 8360841.

llvm-svn: 112672
2010-08-31 23:34:27 +00:00
John McCall 5d865c3292 Teach IR generation to return 'this' from constructors and destructors
under the ARM ABI.

llvm-svn: 112588
2010-08-31 07:33:07 +00:00
Devang Patel 96b7f55a03 Debug info for friends!
Patch originally by Alexander Herz.

llvm-svn: 112275
2010-08-27 17:47:47 +00:00
Devang Patel b0958c7699 test case for r112238.
llvm-svn: 112239
2010-08-26 22:54:33 +00:00
Argyrios Kyrtzidis 7648fb464b Fix miscompilation. The cookie was not used when new'ing arrays with multiple dimensions.
llvm-svn: 112188
2010-08-26 15:23:38 +00:00
Argyrios Kyrtzidis 1194d5e3d2 Fix miscompilation. The custom new[]/delete[] methods were not getting called for arrays with more than 1 dimension.
llvm-svn: 112107
2010-08-25 23:14:56 +00:00
Chandler Carruth cfe41db403 Support explicit instantiation of function templates and members of class
templates when only the declaration is in scope. This requires deferring the
instantiation to be lazy, and ensuring the definition is required for that
translation unit. We re-use the existing pending instantiation queue,
previously only used to track implicit instantiations which were required to be
lazy. Fixes PR7979.

A subsequent change will rename *PendingImplicitInstantiations to
*PendingInstatiations for clarity given its broader role.

llvm-svn: 112037
2010-08-25 08:27:02 +00:00
John McCall 8d75243029 Expression statements undergo lvalue-to-rvalue conversion in C,
but not in C++, so don't emit aggregate loads of volatile references
in null context in C++.  Happens to have been caught by an assertion.
We do not get the scalar case right.  Volatiles are really broken.

llvm-svn: 112019
2010-08-25 02:50:31 +00:00
Devang Patel df96c75731 test case for PR7920.
llvm-svn: 111821
2010-08-23 18:26:10 +00:00
Chris Lattner 65526f0190 fix rdar://8340348, a miscompile of boost that was exposed by r109848.
That revision started classifying truly empty structs like "Y" and "X"
as being NoClass/NoClass and turning them into 'ignore'.  The call code
turns around and allocates space for the ignored argument with 
GetUndefRValue.  The bug is that GetUndefRValue would return the address
as undef, instead of returning an object with a defined address but 
undefined contents.

llvm-svn: 111794
2010-08-23 05:26:13 +00:00
John McCall 7a9aac2d9f Abstract out everything having to do with member pointers into the ABI
class;  they should just be completely opaque throughout IR gen now,
although I haven't really audited that.

Fix a bug apparently inherited from gcc-4.2 where we failed to null-check
member data pointers when performing derived-to-base or base-to-derived
conversions on them.

llvm-svn: 111789
2010-08-23 01:21:21 +00:00
Douglas Gregor ec3a3f5257 Do not elide copy construction when we're performing base-class initialization
llvm-svn: 111783
2010-08-22 18:27:02 +00:00
Douglas Gregor 932c19dc9f Eliminate a stale assertion. Fixes Clang self-host.
llvm-svn: 111782
2010-08-22 18:26:35 +00:00
Douglas Gregor b0a04fff51 Preserve the zero-initialization and construction-kind settings when
instantiating CXXConstructExpr expressions.

llvm-svn: 111780
2010-08-22 17:20:18 +00:00
Douglas Gregor 630c76efb0 When performing value-initialization for a class with a non-trivial,
implicitly-defined default constructor, zero-initialize the memory
before calling the default constructor. Previously, we would only
zero-initialize in the case of a trivial default constructor.

Also, simplify the hideous logic that determines when we have a
trivial default constructor and, therefore, don't need to emit any
call at all.

llvm-svn: 111779
2010-08-22 16:15:35 +00:00
John McCall c29eb8a9d1 Clean up a very silly use of first-class aggregates.
llvm-svn: 111777
2010-08-22 11:04:31 +00:00
John McCall a1dee5300b Experiment with using first-class aggregates to represent member function
pointers.  I find the resulting code to be substantially cleaner, and it
makes it very easy to use the same APIs for data member pointers (which I have
conscientiously avoided here), and it avoids a plethora of potential
inefficiencies due to excessive memory copying, but we'll have to see if it
actually works.

llvm-svn: 111776
2010-08-22 10:59:02 +00:00
John McCall 1c456c89dc Abstract out member-pointer creation. I'm really unhappy about the current
duplication between the constant and non-constant paths in all of this.

Implement ARM ABI semantics for member pointer constants and conversion.

llvm-svn: 111772
2010-08-22 06:43:33 +00:00
Daniel Dunbar 30eb5fa3ba Improve test coverage.
llvm-svn: 111712
2010-08-21 02:46:28 +00:00
Douglas Gregor e3b3464d4e Fix a major regression with value-initialization of class types with
trivial default constructors. We're weren't zero-initializing them,
which manifested as <rdar://problem/8320532> (a regression in the GCC
test suite) and is likely to have caused significant other breakage.

llvm-svn: 111650
2010-08-20 16:57:37 +00:00
John McCall f834bcd659 Mangle explicit template arguments in dependent or overloaded names.
llvm-svn: 111591
2010-08-20 00:17:19 +00:00
John McCall 78fbb61ed7 Contextual arity is a feature of mangling expressions; kill off
mangleCallExpression.  Also, operator names with unknown arity should
be mangled as binary operators;  this is actually covered by an oddly-
positioned sentence in the ABI document.  Fixes PR7891.

llvm-svn: 111395
2010-08-18 19:18:59 +00:00
Douglas Gregor c1a42fdd53 Make sure to add MallocAttr to explicitly-declared operator new/new[]
when -fassume-sane-operator-new. Patch by Tom Jablin!

llvm-svn: 111363
2010-08-18 15:06:25 +00:00
Chris Lattner b1995dffaf Fix PR7889 by generalizing some over specialized code. There is no
reason that this should be limited to simple lvalues.

llvm-svn: 111331
2010-08-18 00:08:27 +00:00
Chris Lattner 00d5141aef fix PR7892, a crash on valid in c++ codegen of __PRETTY_FUNCTION__
llvm-svn: 111330
2010-08-17 23:58:10 +00:00
John McCall 6d86202fa7 Whoops. Don't fall through into the overload case when mangling a
dependent call expression.

llvm-svn: 111300
2010-08-17 21:51:21 +00:00
Argyrios Kyrtzidis a3ae3eb690 Fix initialization for members of anonymous struct in a union.
llvm-svn: 111159
2010-08-16 17:27:13 +00:00
John McCall 8823c65abd Properly give unique-external linkage to members of member templates
instantiated with unique-external parameters.

llvm-svn: 111012
2010-08-13 08:35:10 +00:00
John McCall b3732bb3b7 Just disable the hidden-visibility optimization for now by hiding it behind
a -cc1 option.  The Darwin linker complains about mixed visibility when linking
gcc-built objects with clang-built objects, and the optimization isn't really
that valuable.  Platforms with less ornery linkers can feel free to enable this.

llvm-svn: 110979
2010-08-12 23:36:15 +00:00
Dan Gohman c702acc81f Revert r110936; this fails on clang-i686-darwin10 too.
llvm-svn: 110942
2010-08-12 18:57:17 +00:00
Devang Patel 16e465bc5f Make this test darwin only.
llvm-svn: 110936
2010-08-12 17:42:42 +00:00
Dan Gohman ca4930b445 Temporarily disable this failing test, until it can be properly
investigated.

llvm-svn: 110917
2010-08-12 15:19:46 +00:00
John McCall 7e9e2b47b9 Test for rdar://problem/8073696.
llvm-svn: 110907
2010-08-12 07:31:42 +00:00
Devang Patel caa23f0708 Emit debug info for static const class member.
llvm-svn: 110885
2010-08-12 00:02:44 +00:00
Devang Patel d76c1dbe39 Emit a stop point for delegate constructor call. This gives user a chance to step into constructor body.
llvm-svn: 110853
2010-08-11 21:04:37 +00:00
Devang Patel bb9106b395 Test case for llvm r110712.
llvm-svn: 110713
2010-08-10 20:01:51 +00:00
John McCall 62eb9a8e84 When initializing a static local, pop the guard-abort EH cleanup after
the variable is fully initialized.

llvm-svn: 110704
2010-08-10 18:51:44 +00:00
John McCall 7cd1d97e33 Inline a special case of EmitAggregateCopy into EmitNullInitialization
to avoid the awesome-but-wrong-in-this-case assertion in the canon EAC.
Fixes PR7834.

Also fix a subtle address-space bug in the memset path.

llvm-svn: 110511
2010-08-07 08:21:30 +00:00
John McCall 491462425a Don't crash when mangling empty anonymous unions. We never actually *need*
these, but it's convenient to mangle them when deferring them (in the 99.99%
case where it's not an anonymous union, of course).

llvm-svn: 110381
2010-08-05 22:02:13 +00:00
John McCall 5513fce96b It turns out that linkers (at least, the Darwin linker) don't necessarily
do the right thing with mixed-visibility symbols, so disable the visibility
optimization where that's possible, i.e. with template classes (since it's
possible that an arbitrary template might be subject to an explicit
instantiation elsewhere).  447.dealII actually does this.

I've put the code under an option that's currently not hooked up to anything.

llvm-svn: 110374
2010-08-05 20:39:18 +00:00
Eli Friedman d986fc8b48 Tests for #pragma GCC visibility.
llvm-svn: 110316
2010-08-05 07:00:53 +00:00
John McCall c8bd9c277b Extend the visibility-hidden optimization to linkonce_odr thunks for
functions with in-line definitions, since such thunks will be emitted at any
use of the function.

Completes the feature work for rdar://problem/7523229.

llvm-svn: 110285
2010-08-04 23:46:35 +00:00
John McCall e16adc2b1e Emit standard-library RTTI with external linkage, not weak_odr.
Apply hidden visibility to most RTTI;  libstdc++ does not rely on exact
pointer equality for the type info (just the type info names).  Apply
the same optimization to RTTI that we do to vtables.

Fixes PR5962.

llvm-svn: 110192
2010-08-04 08:34:44 +00:00
John McCall 8a705c15d9 Extend the hidden-visibility vtables optimization to template classes that
haven't been explicitly instantiated.

llvm-svn: 110189
2010-08-04 06:38:15 +00:00
John McCall 8601a75118 Do a very simple pass over every function we emit to infer whether we can
mark it nounwind based on whether it contains any non-nounwind calls.
<rdar://problem/8087431>

llvm-svn: 110163
2010-08-03 22:46:07 +00:00
John McCall 5696d6d316 Emit weak vtables of non-template classes with hidden visibility.
llvm-svn: 110107
2010-08-03 07:24:12 +00:00
John McCall 45d494785d Emit global destructors even if the destroyed object has no initializers or has
an initializer requiring temporary object disposal.

Fixes rdar:://problem/8246444.

llvm-svn: 109849
2010-07-30 04:56:58 +00:00
Chris Lattner 8a2f3c778e fix PR5179 and correctly fix PR5831 to not miscompile.
The X86-64 ABI code didn't handle the case when a struct
would get classified and turn up as "NoClass INTEGER" for
example.  This is perfectly possible when the first slot
is all padding (e.g. due to empty base classes).  In this
situation, the first 8-byte doesn't take a register at all,
only the second 8-byte does.

This fixes this by enhancing the x86-64 abi stuff to allow
and handle this case, reverts the broken fix for PR5831,
and enhances the target independent stuff to be able to 
handle an argument value in registers being accessed at an
offset from the memory value.

This is the last x86-64 calling convention related miscompile
that I'm aware of.

llvm-svn: 109848
2010-07-30 04:02:24 +00:00
Chris Lattner cd84084f02 fix PR7742 / rdar://8250764, a miscompilation of struct
return where the struct has a base but no fields.  This
was because the x86-64 abi logic was checking the wrong
predicate in one place.

This was introduced in r91874, which was a fix for PR5831,
which lacked a CHECK line, so I verified and added it.

llvm-svn: 109759
2010-07-29 17:04:54 +00:00
Chris Lattner fe34c1d53e Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.

This simplifies things and fixes issues where X86-64 abi lowering would 
return coerce after making preferred types exactly match up.  This caused
us to compile:

typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 foo(v4f32 X) {
  return X+X;
}

into this code at -O0:

define <4 x float> @foo(<4 x float> %X.coerce) nounwind {
entry:
  %retval = alloca <4 x float>, align 16          ; <<4 x float>*> [#uses=2]
  %coerce = alloca <4 x float>, align 16          ; <<4 x float>*> [#uses=2]
  %X.addr = alloca <4 x float>, align 16          ; <<4 x float>*> [#uses=3]
  store <4 x float> %X.coerce, <4 x float>* %coerce
  %X = load <4 x float>* %coerce                  ; <<4 x float>> [#uses=1]
  store <4 x float> %X, <4 x float>* %X.addr
  %tmp = load <4 x float>* %X.addr                ; <<4 x float>> [#uses=1]
  %tmp1 = load <4 x float>* %X.addr               ; <<4 x float>> [#uses=1]
  %add = fadd <4 x float> %tmp, %tmp1             ; <<4 x float>> [#uses=1]
  store <4 x float> %add, <4 x float>* %retval
  %0 = load <4 x float>* %retval                  ; <<4 x float>> [#uses=1]
  ret <4 x float> %0
}

Now we get:

define <4 x float> @foo(<4 x float> %X) nounwind {
entry:
  %X.addr = alloca <4 x float>, align 16          ; <<4 x float>*> [#uses=3]
  store <4 x float> %X, <4 x float>* %X.addr
  %tmp = load <4 x float>* %X.addr                ; <<4 x float>> [#uses=1]
  %tmp1 = load <4 x float>* %X.addr               ; <<4 x float>> [#uses=1]
  %add = fadd <4 x float> %tmp, %tmp1             ; <<4 x float>> [#uses=1]
  ret <4 x float> %add
}

This implements rdar://8248065

llvm-svn: 109733
2010-07-29 06:26:06 +00:00
Eli Friedman 89eb5def01 PR7736: Make sure to mark &Class::Member correctly as being type-dependent
inside a template class.

llvm-svn: 109697
2010-07-28 23:26:18 +00:00
John McCall ba80390307 When creating a jump destination, its scope should be the scope of the
enclosing normal cleanup, not the top of the EH stack.  I'm *really*
surprised this hasn't been causing more problems.

Fixes rdar://problem/8231514.

llvm-svn: 109569
2010-07-28 01:07:35 +00:00
John McCall 5cbe152ffc Test for the presence of EH branch-throughs instead of normal branch-throughs.
I knew this code duplication would bite me.

llvm-svn: 109463
2010-07-26 22:44:58 +00:00
John McCall 268b576b72 Mangle enum constant expressions. Fixes rdar://problem/8204122
llvm-svn: 109315
2010-07-24 01:17:35 +00:00
Chris Lattner 938533db60 turn down the logical bitwise confusion warning to not warn
when the RHS of the ||/&& is ever 0 or 1.  This handles a variety of
creative idioms for "true" used in C programs and fixes many false 
positives at the expense of a few false negatives.  This fixes
rdar://8230351.

llvm-svn: 109314
2010-07-24 01:10:11 +00:00
John McCall ad5d61e227 Revise cleanup IR generation to fix a major bug with cleanups (PR7686)
as well as some significant asymptotic inefficiencies with threading
multiple jumps through deep cleanups.

llvm-svn: 109274
2010-07-23 21:56:41 +00:00
John McCall f99a631e4e Implement proper base/member destructor EH chaining.
llvm-svn: 108989
2010-07-21 05:30:47 +00:00
John McCall 1d9875654f Convert the EH cleanups for base and member destructors in a constructor into
lazy cleanups.

llvm-svn: 108978
2010-07-21 01:23:41 +00:00
Douglas Gregor 05fc5be32f Implement zero-initialization for array new when there is an
initializer of (). Make sure to use a simple memset() when we can, or
fall back to generating a loop when a simple memset will not
suffice. Fixes <rdar://problem/8212208>, a regression due to my work
in r107857.

llvm-svn: 108977
2010-07-21 01:10:17 +00:00
John McCall 5add20cefa Fix the IR generation for catching pointers by references.
Fixes <rdar://problem/8212123>.

llvm-svn: 108944
2010-07-20 22:17:55 +00:00
Chris Lattner 32ac583d91 in 'new int[4]', constant fold the 4*4=16 instead of
doing an overflow check.

llvm-svn: 108943
2010-07-20 21:55:52 +00:00
Chris Lattner 94027202e0 don't demand names to be on IR.
llvm-svn: 108937
2010-07-20 21:34:36 +00:00
Chris Lattner 2be2074f75 temporarily disable this to fix the build bot.
llvm-svn: 108936
2010-07-20 21:32:10 +00:00
Chris Lattner f2f3870189 Follow the implementation approach suggested by PR6687,
which generates more efficient and more obviously conformant
code.  We now test for overflow of the multiply then force
the result to -1 if so.  On X86, this generates nice code
like this:

__Z4testl:                              ## @_Z4testl
## BB#0:                                ## %entry
	subl	$12, %esp
	movl	$4, %eax
	mull	16(%esp)
	testl	%edx, %edx
	movl	$-1, %ecx
	cmovel	%eax, %ecx
	movl	%ecx, (%esp)
	call	__Znam
	addl	$12, %esp
	ret

llvm-svn: 108927
2010-07-20 21:07:09 +00:00
Devang Patel 6c01820900 Print template argument names for template class.
llvm-svn: 108916
2010-07-20 20:24:18 +00:00
Chris Lattner 26008e07de implement rdar://5739832 - operator new should check for overflow in multiply,
causing clang to compile this code into something that correctly throws a
length error, fixing a potential integer overflow security attack:

void *test(long N) {
  return new int[N];
}

int main() {
  test(1L << 62);
}

We do this even when exceptions are disabled, because it is better for the
code to abort than for the attack to succeed.

This is heavily based on a patch that Fariborz wrote.

llvm-svn: 108915
2010-07-20 20:19:24 +00:00
Benjamin Kramer 1b925d5717 Adjust test for float printing differences. Windows uses three digits for the exponent, everyone else two.
llvm-svn: 108693
2010-07-19 11:48:10 +00:00
Eli Friedman f8340deacd Fix mangling for static member variables of classes inside an extern "C"
linkage specification.  Not sure if this is the ideal fix, but I'm reasonably
sure it's correct vs. gcc.

llvm-svn: 108656
2010-07-18 20:49:59 +00:00
Eli Friedman 3ee1022f37 Fix crash initializing a bit-field with a non-constant in a place where we
try to evaluate the initializer as a constant.

llvm-svn: 108632
2010-07-17 23:55:01 +00:00
John McCall 70013b640f When deferring the emission of declarations with initializers in C++, remember
the order they appeared in the translation unit.  If they get emitted, put them
in their proper order.  Fixes rdar://problem/7458115

llvm-svn: 108477
2010-07-15 23:40:35 +00:00
Douglas Gregor cdb466e58f Reinstate the scalar-cast-to-const-reference improvements, this time
with the proper spelling of "non-class prvalue". Silly me, I think
class rvalues were xvalues rather than prvalues!

Hah hah hah.

llvm-svn: 108443
2010-07-15 18:58:16 +00:00
Douglas Gregor 31e225cc90 Revert r108431 and r108433 (the cast-to-const-reference fixes), which
broke nightlytest.

llvm-svn: 108439
2010-07-15 18:41:54 +00:00
Devang Patel 99c372134d Revert 108220 and subsequent patch.
This is not required (I am not 100% sure why) but method.exp from gdb testsuite flagged regression due to this patch.

llvm-svn: 108434
2010-07-15 18:16:09 +00:00
Douglas Gregor 1bae6a1be9 Teach CodeGenFunction::EmitCastLValue() to handle casts to an lvalue
that involve binding a reference to a pure rvalue temporary (e.g., not
a class temporary), by creating a new temporary and copying the result
there. Fixes PR6024.

llvm-svn: 108431
2010-07-15 18:04:13 +00:00
Douglas Gregor c357f4121e Add lvalue-bitcast support for complex numbers.
llvm-svn: 108363
2010-07-14 21:35:45 +00:00
John McCall 4f3b5f302c Fix the mangling of template template arguments, which do not always
follow <name>;  instead they follow <type>, which has <name> as a subset.

Fixes PR7446.

llvm-svn: 108326
2010-07-14 06:43:17 +00:00
Douglas Gregor c95a41b510 Add missing testcases for lvalue bitcasts
llvm-svn: 108296
2010-07-13 23:27:15 +00:00
John McCall 5c08ab956b Allow for the possibility that __cxa_end_catch might throw for a catch-all block
or a catch of a record type by value or reference.  Also convert this to a
lazy cleanup.

llvm-svn: 108287
2010-07-13 22:12:14 +00:00
John McCall bb0260139a Switch the __cxa_free_exception cleanup to be lazy.
llvm-svn: 108276
2010-07-13 21:17:51 +00:00
John McCall 2b7fc3828e Teach IR generation how to lazily emit cleanups. This has a lot of advantages,
mostly in avoiding unnecessary work at compile time but also in producing more
sensible block orderings.

Move the destructor cleanups for local variables over to use lazy cleanups.
Eventually all cleanups will do this;  for now we have some awkward code
duplication.

Tell IR generation just to never produce landing pads in -fno-exceptions.
This is a much more comprehensive solution to a problem which previously was
half-solved by checks in most cleanup-generation spots.

llvm-svn: 108270
2010-07-13 20:32:21 +00:00
Fariborz Jahanian a6c7efec2b More block instantiation stuff. Set variable/param DeclContext
to block context when first instantiating them.

llvm-svn: 108266
2010-07-13 20:05:58 +00:00
Chris Lattner 8406c5197b Add a warning to catch a bug recently caught by code review, like this:
t2.c:2:12: warning: use of logical && with constant operand; switch to bitwise &
      or remove constant [-Wlogical-bitwise-confusion]
  return x && 4;
           ^  ~

wording improvement suggestions are welcome.

llvm-svn: 108260
2010-07-13 19:41:32 +00:00
Devang Patel 01c8c100c2 Add volatile qualifiers for "this".
llvm-svn: 108245
2010-07-13 16:23:13 +00:00
Douglas Gregor a700f68828 Reinstate the optimization suppressing available_externally functions
at -O0. The only change from the previous patch is that we don't try
to generate virtual method thunks for an available_externally
function.

llvm-svn: 108230
2010-07-13 06:02:28 +00:00
Douglas Gregor 553f3a9b30 Speculatively revert r108156; it appears to be breaking self-host.
llvm-svn: 108194
2010-07-12 21:08:32 +00:00
Douglas Gregor dbb2806a7b Do not generate LLVM IR for available_externally function bodies at
-O0, since we won't be using the definitions for anything anyway. For
lib/System/Path.o when built in Debug+Asserts mode, this leads to a 4%
improvement in compile time (and suppresses 440 function bodies).

<rdar://problem/7987644>

llvm-svn: 108156
2010-07-12 17:24:55 +00:00
Fariborz Jahanian 4239aa104b BlockDeclRefExpr of a dependent type must
be a dependent expression when its is built.

llvm-svn: 108026
2010-07-09 22:21:32 +00:00
Fariborz Jahanian 2f8bd36bcf Instantiation of byref variable in
block literal expression.

llvm-svn: 108019
2010-07-09 21:27:28 +00:00
Fariborz Jahanian 1babe7778d Instantiation of block literal expressions. wip.
llvm-svn: 108000
2010-07-09 18:44:02 +00:00
John McCall be349def4b Mark calls to 'throw()' functions as nounwind, and mark the functions nounwind
as well.

llvm-svn: 107858
2010-07-08 06:48:12 +00:00
Douglas Gregor 747eb7840a Reinstate the fix for PR7556. A silly use of isTrivial() was
suppressing copies of objects with trivial copy constructors.

llvm-svn: 107857
2010-07-08 06:14:04 +00:00
Douglas Gregor e182370eda Revert r107828 and r107827, the fix for PR7556, which seems to be
breaking bootstrap on Linux.

llvm-svn: 107837
2010-07-07 23:37:33 +00:00
Douglas Gregor 442612c285 Do not use CXXZeroValueInitExpr for class types. Instead, use
CXXConstructExpr/CXXTemporaryObjectExpr/CXXNewExpr as
appropriate. Fixes PR7556, and provides a slide codegen improvement
when copy-initializing a POD class type from a value-initialized
temporary. Previously, we weren't eliding the copy.

llvm-svn: 107827
2010-07-07 22:35:13 +00:00
John McCall b609d3f5f9 Teach function-try-blocks on constructors and destructors to implicitly
rethrow.  Fixes rdar://problem/7696603

llvm-svn: 107757
2010-07-07 06:56:46 +00:00
John McCall 2d605ac1f5 When destroying a cleanup, kill any references to instructions in the entry
block before deleting it.  Fixes PR7575.

This really just a short-term fix before implementing lazy cleanups.

llvm-svn: 107676
2010-07-06 17:35:03 +00:00
John McCall 466e221037 When creating functions to run global initializers and destructors, mark them
as nounwind in -fno-exceptions.  Fixes rdar://problem/8090834.

llvm-svn: 107639
2010-07-06 04:38:10 +00:00
John McCall 2b6ac78e07 Stop testing for specific basic block numbers in this test.
llvm-svn: 107632
2010-07-06 02:14:28 +00:00
John McCall bd30929e4d Validated by nightly-test runs on x86 and x86-64 darwin, including after
self-host.  Hopefully these results hold up on different platforms.  

I tried to keep the GNU ObjC runtime happy, but it's hard for me to test.
Reimplement how clang generates IR for exceptions.  Instead of creating new
invoke destinations which sequentially chain to the previous destination,
push a more semantic representation of *why* we need the cleanup/catch/filter
behavior, then collect that information into a single landing pad upon request.

Also reorganizes how normal cleanups (i.e. cleanups triggered by non-exceptional
control flow) are generated, since it's actually fairly closely tied in with
the former.  Remove the need to track which cleanup scope a block is associated
with.

Document a lot of previously poorly-understood (by me, at least) behavior.

The new framework implements the Horrible Hack (tm), which requires every
landing pad to have a catch-all so that inlining will work.  Clang no longer
requires the Horrible Hack just to make exceptions flow correctly within
a function, however.  The HH is an unfortunate requirement of LLVM's EH IR.

llvm-svn: 107631
2010-07-06 01:34:17 +00:00
Charles Davis 3babfba597 Mangle Objective-C pointers and block pointers in the Microsoft C++ Mangler.
ObjC pointers were easy enough (as far as the ABI is concerned, they're
just pointers to structs), but I had to invent a new mangling for block
pointers. This is particularly worrying with the Microsoft ABI, because
it is a vendor-specific ABI; extending it could come back to bite us
later when MS extends it on their own (and you know they will).

llvm-svn: 107572
2010-07-03 16:56:59 +00:00
Charles Davis 3b10dd1bec Fix mangling of array dimensions in the Microsoft C++ Mangler.
llvm-svn: 107568
2010-07-03 08:15:16 +00:00
Charles Davis d49950a317 Mangle member pointer types in the Microsoft C++ Mangler.
llvm-svn: 107567
2010-07-03 08:01:32 +00:00
Charles Davis 0029a2a957 Fix mangling of function pointers in the Microsoft C++ Mangler.
llvm-svn: 107564
2010-07-03 05:53:41 +00:00
Charles Davis 77552766d9 Fix mangling of array parameters for functions in the Microsoft C++ Mangler.
Only actual functions get mangled correctly; I don't know how to fix it for
function pointers yet. Thanks to John McCall for the hint.

Also, mangle anonymous tag types. I don't have a suitable testcase yet; I have
a feeling that that's going to need support for static locals, and I haven't
figured out exactly how MSVC's scheme for mangling those works.

llvm-svn: 107561
2010-07-03 02:41:45 +00:00
Douglas Gregor 957551609c Reinstate fix for PR7526, which was failing because, now that we
aren't dropping all exception specifications on destructors, the
exception specifications on implicitly-declared destructors were
detected as being wrong (which they were). 

Introduce logic to provide a proper exception-specification for
implicitly-declared destructors. This also fixes PR6972.

Note that the other implicitly-declared special member functions also
need to get exception-specifications. I'll deal with that in a
subsequent commit.

llvm-svn: 107385
2010-07-01 05:10:53 +00:00
Douglas Gregor 3671ad4571 Revert r107374, which broke bootstrap.
llvm-svn: 107378
2010-07-01 03:28:42 +00:00
Douglas Gregor c6e4c68371 When building the type of a destructor, make sure to keep the
exception specification. Fixes PR7526.

llvm-svn: 107374
2010-07-01 02:33:15 +00:00
Chris Lattner 5c740f1523 Reapply:
r107173, "fix PR7519: after thrashing around and remembering how all this stuff"
r107216, "fix PR7523, which was caused by the ABI code calling ConvertType instead"

This includes a fix to make ConvertTypeForMem handle the "recursive" case, and call
it as such when lowering function types which have an indirect result.

llvm-svn: 107310
2010-06-30 19:14:05 +00:00
Charles Davis 2a47730767 Mangle arrays in the Microsoft C++ Mangler. It's not quite finished (it
doesn't mangle array parameters right), but I think that should be fixed
in Sema (Doug, John, what do you think?).

Also, stub out the remaining mangleType() routines.

llvm-svn: 107264
2010-06-30 08:09:57 +00:00
Daniel Dunbar 8386469d7d Revert r107216, "fix PR7523, which was caused by the ABI code calling ConvertType instead", it is part of a boostrap breaking sequence.
llvm-svn: 107231
2010-06-30 00:22:30 +00:00
Chris Lattner 466b1419c6 fix PR7523, which was caused by the ABI code calling ConvertType instead
of ConvertTypeRecursive when it needed to in a few cases, causing pointer
types to get resolved at the wrong time.

llvm-svn: 107216
2010-06-29 22:39:04 +00:00
Daniel Dunbar c85ea8e175 IRgen: Assignment to Objective-C properties shouldn't reload the value (which
would trigger an extra method call).
 - While in the area, I also changed Clang to not emit an unnecessary load from
   'x' in cases like 'y = (x = 1)'.

llvm-svn: 107210
2010-06-29 22:00:45 +00:00
Daniel Dunbar 8452ef0798 tests: Use %clangxx when using driver for C++, in case C++ support is disabled.
llvm-svn: 107153
2010-06-29 16:52:24 +00:00
Chris Lattner 22a931e3bb Change X86_64ABIInfo to have ASTContext and TargetData ivars to
avoid passing ASTContext down through all the methods it has.

When classifying an argument, or argument piece, as INTEGER, check
to see if we have a pointer at exactly the same offset in the 
preferred type.  If so, use that pointer type instead of i64.  This
allows us to compile A function taking a stringref into something
like this:

define i8* @foo(i64 %D.coerce0, i8* %D.coerce1) nounwind ssp {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=4]
  %0 = getelementptr %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  store i64 %D.coerce0, i64* %0
  %1 = getelementptr %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
  store i8* %D.coerce1, i8** %1
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
  %tmp3 = load i8** %tmp2                         ; <i8*> [#uses=1]
  %add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
  ret i8* %add.ptr
}

instead of this:

define i8* @foo(i64 %D.coerce0, i64 %D.coerce1) nounwind ssp {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=3]
  %0 = insertvalue %0 undef, i64 %D.coerce0, 0    ; <%0> [#uses=1]
  %1 = insertvalue %0 %0, i64 %D.coerce1, 1       ; <%0> [#uses=1]
  %2 = bitcast %struct.DeclGroup* %D to %0*       ; <%0*> [#uses=1]
  store %0 %1, %0* %2, align 1
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
  %tmp3 = load i8** %tmp2                         ; <i8*> [#uses=1]
  %add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
  ret i8* %add.ptr
}

This implements rdar://7375902 - [codegen quality] clang x86-64 ABI lowering code punishing StringRef

llvm-svn: 107123
2010-06-29 06:01:59 +00:00
Chris Lattner 9e748e9d6e add IR names to coerced arguments.
llvm-svn: 107105
2010-06-29 00:14:52 +00:00
Chris Lattner 3dd716c3c3 Change CGCall to handle the "coerce" case where the coerce-to type
is a FCA to pass each of the elements as individual scalars.  This
produces code fast isel is less likely to reject and is easier on
the optimizers.

For example, before we would compile:
struct DeclGroup { long NumDecls; char * Y; };
char * foo(DeclGroup D) {
  return D.NumDecls+D.Y;
}

to:
%struct.DeclGroup = type { i64, i64 }

define i64 @_Z3foo9DeclGroup(%struct.DeclGroup) nounwind {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=3]
  store %struct.DeclGroup %0, %struct.DeclGroup* %D, align 1
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i64*> [#uses=1]
  %tmp3 = load i64* %tmp2                         ; <i64> [#uses=1]
  %add = add nsw i64 %tmp1, %tmp3                 ; <i64> [#uses=1]
  ret i64 %add
}

Now we get:

%0 = type { i64, i64 }
%struct.DeclGroup = type { i64, i8* }

define i8* @_Z3foo9DeclGroup(i64, i64) nounwind {
entry:
  %D = alloca %struct.DeclGroup, align 8          ; <%struct.DeclGroup*> [#uses=3]
  %2 = insertvalue %0 undef, i64 %0, 0            ; <%0> [#uses=1]
  %3 = insertvalue %0 %2, i64 %1, 1               ; <%0> [#uses=1]
  %4 = bitcast %struct.DeclGroup* %D to %0*       ; <%0*> [#uses=1]
  store %0 %3, %0* %4, align 1
  %tmp = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 0 ; <i64*> [#uses=1]
  %tmp1 = load i64* %tmp                          ; <i64> [#uses=1]
  %tmp2 = getelementptr inbounds %struct.DeclGroup* %D, i32 0, i32 1 ; <i8**> [#uses=1]
  %tmp3 = load i8** %tmp2                         ; <i8*> [#uses=1]
  %add.ptr = getelementptr inbounds i8* %tmp3, i64 %tmp1 ; <i8*> [#uses=1]
  ret i8* %add.ptr
}

Elimination of the FCA inside the function is still-to-come.

llvm-svn: 107099
2010-06-28 23:44:11 +00:00
Chris Lattner 93af332819 pass/return structs of char and short as i8/i16 to avoid
aweful through-memory coersion, just like we do for i32 now.

llvm-svn: 107078
2010-06-28 21:59:07 +00:00
Chris Lattner a7d81ab7f3 X86-64:
pass/return structs of float/int as float/i32 instead of double/i64
to make the code generated for ABI cleaner.  Passing in the low part
of a double is the same as passing in a float.

For example, we now compile:

struct DeclGroup { float NumDecls; };
float foo(DeclGroup D);
void bar(DeclGroup *D) {
 foo(*D);
}

into:

%struct.DeclGroup = type { float }

define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) nounwind {
entry:
  %D.addr = alloca %struct.DeclGroup*, align 8    ; <%struct.DeclGroup**> [#uses=2]
  %agg.tmp = alloca %struct.DeclGroup, align 4    ; <%struct.DeclGroup*> [#uses=2]
  store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
  %tmp = load %struct.DeclGroup** %D.addr         ; <%struct.DeclGroup*> [#uses=1]
  %tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
  %tmp2 = bitcast %struct.DeclGroup* %tmp to i8*  ; <i8*> [#uses=1]
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
  %coerce.dive = getelementptr %struct.DeclGroup* %agg.tmp, i32 0, i32 0 ; <float*> [#uses=1]
  %0 = load float* %coerce.dive, align 1          ; <float> [#uses=1]
  %call = call float @_Z3foo9DeclGroup(float %0)  ; <float> [#uses=0]
  ret void
}

instead of:

%struct.DeclGroup = type { float }

define void @_Z3barP9DeclGroup(%struct.DeclGroup* %D) nounwind {
entry:
  %D.addr = alloca %struct.DeclGroup*, align 8    ; <%struct.DeclGroup**> [#uses=2]
  %agg.tmp = alloca %struct.DeclGroup, align 4    ; <%struct.DeclGroup*> [#uses=2]
  %tmp3 = alloca double                           ; <double*> [#uses=2]
  store %struct.DeclGroup* %D, %struct.DeclGroup** %D.addr
  %tmp = load %struct.DeclGroup** %D.addr         ; <%struct.DeclGroup*> [#uses=1]
  %tmp1 = bitcast %struct.DeclGroup* %agg.tmp to i8* ; <i8*> [#uses=1]
  %tmp2 = bitcast %struct.DeclGroup* %tmp to i8*  ; <i8*> [#uses=1]
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 4, i32 4, i1 false)
  %coerce.dive = getelementptr %struct.DeclGroup* %agg.tmp, i32 0, i32 0 ; <float*> [#uses=1]
  %0 = bitcast double* %tmp3 to float*            ; <float*> [#uses=1]
  %1 = load float* %coerce.dive                   ; <float> [#uses=1]
  store float %1, float* %0, align 1
  %2 = load double* %tmp3                         ; <double> [#uses=1]
  %call = call float @_Z3foo9DeclGroup(double %2) ; <float> [#uses=0]
  ret void
}

which is this machine code (at -O0):

__Z3barP9DeclGroup:
	subq	$24, %rsp
	movq	%rdi, 16(%rsp)
	movq	16(%rsp), %rdi
	leaq	8(%rsp), %rax
	movl	(%rdi), %ecx
	movl	%ecx, (%rax)
	movss	8(%rsp), %xmm0
	callq	__Z3foo9DeclGroup
	addq	$24, %rsp
	ret

vs this:

__Z3barP9DeclGroup:
	subq	$24, %rsp
	movq	%rdi, 16(%rsp)
	movq	16(%rsp), %rdi
	leaq	8(%rsp), %rax
	movl	(%rdi), %ecx
	movl	%ecx, (%rax)
	movss	8(%rsp), %xmm0
	movss	%xmm0, (%rsp)
	movsd	(%rsp), %xmm0
	callq	__Z3foo9DeclGroup
	addq	$24, %rsp
	ret

At -O3, it is the difference between this now:

__Z3barP9DeclGroup:
	movss	(%rdi), %xmm0
	jmp	__Z3foo9DeclGroup  # TAILCALL

vs this before:

__Z3barP9DeclGroup:
	movl	(%rdi), %eax
	movd	%rax, %xmm0
	jmp	__Z3foo9DeclGroup  # TAILCALL

llvm-svn: 107048
2010-06-28 19:56:59 +00:00
Daniel Dunbar ebf9da9849 tests: Rewrite test to check intent instead of implementation.
llvm-svn: 107024
2010-06-28 17:43:18 +00:00
Anders Carlsson 3f48c603fb Correctly destroy reference temporaries with global storage. Remove ErrorUnsupported call when binding a global reference to a non-lvalue. Fixes PR7326.
llvm-svn: 106983
2010-06-27 17:52:15 +00:00
Chris Lattner 3fcc790cd8 Change IR generation for return (in the simple case) to avoid doing silly
load/store nonsense in the epilog.  For example, for:

int foo(int X) {
  int A[100];
  return A[X];
}

we used to generate:

  %arrayidx = getelementptr inbounds [100 x i32]* %A, i32 0, i64 %idxprom ; <i32*> [#uses=1]
  %tmp1 = load i32* %arrayidx                     ; <i32> [#uses=1]
  store i32 %tmp1, i32* %retval
  %0 = load i32* %retval                          ; <i32> [#uses=1]
  ret i32 %0
}

which codegen'd to this code:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	subq	$408, %rsp              ## imm = 0x198
	movl	%edi, 400(%rsp)
	movl	400(%rsp), %edi
	movslq	%edi, %rax
	movl	(%rsp,%rax,4), %edi
	movl	%edi, 404(%rsp)
	movl	404(%rsp), %eax
	addq	$408, %rsp              ## imm = 0x198
	ret

Now we generate:

  %arrayidx = getelementptr inbounds [100 x i32]* %A, i32 0, i64 %idxprom ; <i32*> [#uses=1]
  %tmp1 = load i32* %arrayidx                     ; <i32> [#uses=1]
  ret i32 %tmp1
}

and:

_foo:                                   ## @foo
## BB#0:                                ## %entry
	subq	$408, %rsp              ## imm = 0x198
	movl	%edi, 404(%rsp)
	movl	404(%rsp), %edi
	movslq	%edi, %rax
	movl	(%rsp,%rax,4), %eax
	addq	$408, %rsp              ## imm = 0x198
	ret

This actually does matter, cutting out 2000 lines of IR from CGStmt.ll 
for example.

Another interesting effect is that altivec.h functions which are dead
now get dce'd by the inliner.  Hence all the changes to 
builtins-ppc-altivec.c to ensure the calls aren't dead.

llvm-svn: 106970
2010-06-27 01:06:27 +00:00
Chris Lattner 217e056e40 implement rdar://7432000 - signed negate should codegen as NSW.
While I'm in there, adjust pointer to member adjustments as well.

llvm-svn: 106955
2010-06-26 20:27:24 +00:00
Charles Davis f4db33cbdf Mangle pointer and (lvalue) reference types in the Microsoft C++ Mangler.
Also, fix mangling of throw specs. Turns out MSVC totally ignores throw
specs when mangling names.

llvm-svn: 106937
2010-06-26 03:50:05 +00:00
Fariborz Jahanian d3a476b976 Try making BuildBot happy again.
llvm-svn: 106898
2010-06-25 22:32:31 +00:00
Fariborz Jahanian 07b0a6e4d6 Test case for pr7490.
llvm-svn: 106887
2010-06-25 21:08:10 +00:00
Fariborz Jahanian 9b5528d278 Patch to correctly mangle block helper functions
when block literal is declared inside a ctor/dtor.
Fixes radr 8096995.

llvm-svn: 106700
2010-06-24 00:08:06 +00:00
Douglas Gregor 5dd34744c5 Instantiations subject to an explicit template instantiation
declaration have default visibility even under
-fvisibility=hidden. Fixes <rdar://problem/8109763>.

llvm-svn: 106440
2010-06-21 18:41:26 +00:00
Fariborz Jahanian cc99b3ca9e Fixes a corner case bug whereby declaring and defining an extern variable in a
particular sequence causes its definition to not be generated in the object file.
(fixes radar 8071804).

llvm-svn: 106424
2010-06-21 16:08:37 +00:00
Eli Friedman c96b2496fc Fix for PR7415: refactor CodeGenModule::MayDeferGeneration and make it less
conservative for static variables in templated classes.

llvm-svn: 106385
2010-06-19 06:24:06 +00:00
Chris Lattner 87233f785b Fix PR7097, a bad interaction between -fno-use-cxa-atexit and
-mconstructor-aliases by using a WeakVH instead of a raw pointer.

llvm-svn: 106384
2010-06-19 05:52:45 +00:00
Charles Davis 108f5a2748 Mangle tag types (unions, structs, classes, enums) in the Microsoft C++ Mangler.
Also, test that static members with default visibility in a struct have the
right mangling.

llvm-svn: 106276
2010-06-18 07:51:00 +00:00
Fariborz Jahanian 6fdb139cdd Do not treat @selector as lvalue (unlike g++).
Patch by Nico Weber (pr7390).

llvm-svn: 106242
2010-06-17 21:45:48 +00:00
Charles Davis 8c02c13e19 Mangle operator names in the Microsoft C++ Mangler.
llvm-svn: 106211
2010-06-17 06:47:31 +00:00
Rafael Espindola 23a8a06554 Change the test for which ABI/CC to use on ARM to be base on the environment
(the last argument of the triple).

llvm-svn: 106131
2010-06-16 19:01:17 +00:00
Rafael Espindola b35e7b8659 Fix tests that I missed from my previous commit.
llvm-svn: 106118
2010-06-16 17:49:52 +00:00
Charles Davis 89338af1ff Start mangling function types in the Microsoft C++ Mangler.
llvm-svn: 106081
2010-06-16 05:33:16 +00:00
Fariborz Jahanian 56d3b8c578 Moved objective-c++ code gen. tests to their own directory and
added a new test case (related to radar 8070772).

llvm-svn: 106067
2010-06-15 23:49:10 +00:00
Fariborz Jahanian 021510e96f Patch adds support for copying of those
objective-c++ class objects which have GC'able objc object
pointers and need to use ObjC's objc_memmove_collectable
API (radar 8070772). 

llvm-svn: 106061
2010-06-15 22:44:06 +00:00
Douglas Gregor 0832963acd Implement -fvisibility-inlines-hidden. <rdar://problem/7819834>
llvm-svn: 106003
2010-06-15 17:05:35 +00:00
Douglas Gregor 4f6e8deec4 Make sure to set the visible on a vtable; VTTs and typeinfo already
handle visibility properly. Fixes <rdar://problem/8091955>. 

llvm-svn: 105977
2010-06-14 23:41:45 +00:00
Douglas Gregor 1726d1517e Add name mangling for address spaces. We use the vendor-extension
mangling for types, where the <source-name> is ASxxx (xxx is the
address-space number).

llvm-svn: 105975
2010-06-14 23:15:08 +00:00
Charles Davis 2d7b10cc97 Microsoft C++ Mangler:
- Mangle qualifiers.
- Start mangling variables' types into the name. A variable declared with a
  builtin type should now mangle properly.

llvm-svn: 105931
2010-06-14 05:29:01 +00:00
Charles Davis 7dacc95299 Microsoft C++ Mangler:
- Don't mangle static variables at global scope.
- Add support for mangling builtin types. This will be used later.

llvm-svn: 105881
2010-06-12 08:11:16 +00:00
Charles Davis b6a5a0d9e1 When mangling for the Microsoft C++ ABI, mangle variables in the global
namespace, too.

llvm-svn: 105809
2010-06-11 04:25:47 +00:00
Charles Davis 9af2d4a614 Start implementing the Microsoft-style name mangler. Mangle simple names
(but not their types; that's later).

NOTE: Right now, variables in the global namespace don't get mangled, even
though they're supposed to be. This is because the default mangler
implements the shouldMangleDeclName() method that tells clang not to mangle
them. This will be fixed in a later patch.

llvm-svn: 105805
2010-06-11 03:07:32 +00:00
Anders Carlsson 13f7c7dd77 Fix test.
llvm-svn: 105668
2010-06-09 01:42:52 +00:00
Anders Carlsson 642da419a6 Try to fix buildbot tests.
llvm-svn: 105660
2010-06-08 23:10:20 +00:00
Anders Carlsson 044cab3325 Add test case.
llvm-svn: 105651
2010-06-08 22:48:02 +00:00
Fariborz Jahanian 3b83618054 Block Code Gen. API. Call destructor on descriptior
entry previously constructed via copy constructor.

llvm-svn: 105641
2010-06-08 20:57:22 +00:00
Fariborz Jahanian 8e73928f52 Fixes a typo which prevented proper code gen. for
copy-in of c++ class objects into blocks.

llvm-svn: 105622
2010-06-08 17:52:11 +00:00
Anders Carlsson 248704c517 Correctly mangle static variables of anonymous struct/union type.
llvm-svn: 105606
2010-06-08 14:49:03 +00:00
Rafael Espindola 85dc7e0909 Add test for previous commit.
llvm-svn: 105594
2010-06-08 03:29:31 +00:00
Rafael Espindola e971b9a260 Correctly align large arrays in x86-64. This fixes PR5599.
llvm-svn: 105500
2010-06-04 23:15:27 +00:00
Fariborz Jahanian ea882cd92e Build AST for copy-construction of copied-in
class object in blocks and carry it to IRGen.

llvm-svn: 105487
2010-06-04 21:35:44 +00:00
Fariborz Jahanian 64176c2c97 For C++ copied in objects, use copy constructors in
setting up block's descriptor. This is on going work to
support c++ specific issues in setting up blocks
various APIs.

llvm-svn: 105469
2010-06-04 16:10:00 +00:00
Eli Friedman 986b6ae96a Check the output of this test.
llvm-svn: 105434
2010-06-03 23:34:11 +00:00
Eli Friedman 4e7bd4a8a1 Think through my commit this time.
llvm-svn: 105433
2010-06-03 23:31:53 +00:00
Eli Friedman cd70980c8e Make sure this test doesn't break when we disallow throwing an exception
in -fno-exceptions mode.

llvm-svn: 105432
2010-06-03 23:22:25 +00:00
Eli Friedman 91a3d27ec0 Make sure to check the accessibility of and mark the destructor for the
operand of a throw expression.  Fixes PR7281.

llvm-svn: 105408
2010-06-03 20:39:03 +00:00
Eli Friedman cce5b81ce1 Don't intentionally try to ignore the value of a scalar expression when we
actually care about it. Fixes PR7291.

llvm-svn: 105404
2010-06-03 19:58:07 +00:00
Anders Carlsson bcb2e4cb63 Don't try to explicitly zero out bit-fields.
llvm-svn: 105391
2010-06-03 15:36:07 +00:00
Fariborz Jahanian d1b378e08d Block C++ code gen. Adds support for block reference argument
types. Executable test will be added to LLVM test suite.
(radar 8041962).

llvm-svn: 105347
2010-06-02 21:35:17 +00:00
John McCall 6a7f9f5c8f Don't try to emit the vtable for a class just because we're emitting a
virtual function from it.

Fixes PR7241.

llvm-svn: 105345
2010-06-02 21:22:02 +00:00
Anders Carlsson b4d2cdbb46 Don't substitute 'St' for 'std' when the namespace is nested inside another namespace.
llvm-svn: 105330
2010-06-02 15:58:27 +00:00
Anders Carlsson a85c1469c7 When building RTTI descriptors for pointer types, we need to get the unqualified array type and the qualifiers from it.
llvm-svn: 105326
2010-06-02 15:44:35 +00:00
Douglas Gregor 876cec2898 typeid() produces type information for the cv-unqualified version of
the type. Thanks to Anders for the bug report!

llvm-svn: 105314
2010-06-02 06:16:02 +00:00
Anders Carlsson d951a7ebf8 Correctly mangle unsigned integer literals where the high bit is set.
llvm-svn: 105312
2010-06-02 05:07:26 +00:00
Anders Carlsson 728fe444f1 Correctly mangle variadic functions that don't have any other parameters.
llvm-svn: 105311
2010-06-02 04:40:13 +00:00
Anders Carlsson d563923cf1 When mangling member function pointers, fake adding a substitution corresponding to the function type.
llvm-svn: 105310
2010-06-02 04:29:50 +00:00
Eli Friedman c8731be34d Fix for PR7040: Don't try to compute the LLVM type for a function where it
isn't possible to compute.

This patch is mostly refactoring; the key change is the addition of the code
starting with the comment, "Check whether the function has a computable LLVM
signature."  The solution here is essentially the same as the way the
vtable code handles such functions.

llvm-svn: 105151
2010-05-30 06:03:20 +00:00
Anders Carlsson da265b8d63 When null-initializing bases with data member pointers, don't assert on virtual bases. Just initialize them to null.
llvm-svn: 104868
2010-05-27 18:51:01 +00:00
John McCall 1cfca7292a Give this test a triple.
llvm-svn: 104798
2010-05-27 02:04:58 +00:00
John McCall c2af939ab4 When deciding whether a deferred declaration has already been emitted,
aliases count as definitions regardless of whether their target has been
emitted yet.  Fixes PR 7142.

llvm-svn: 104796
2010-05-27 01:45:30 +00:00
John McCall 23f6626262 Correctly pass aggregates by reference when emitting thunks.
llvm-svn: 104778
2010-05-26 22:34:26 +00:00
Fariborz Jahanian 5f81b9f3f6 Patch to fix a irgen crash accessing an initialized local static
variable in a local function. Fixes pr7101.

llvm-svn: 104743
2010-05-26 21:45:50 +00:00
Douglas Gregor 0094eb26fc Be sure to use the standard substitutions when mangling the names of
vtables, VTTs, and construction vtables. Fixes PR7201.

llvm-svn: 104675
2010-05-26 05:11:13 +00:00
John McCall 7cb0220e53 If a function definition has any sort of weak linkage, its static local
variables should have that linkage.  Otherwise, its static local
variables should have internal linkage.  To avoid computing this excessively,
set a function's linkage before we emit code for it.

Previously we were assigning weak linkage to the static variables of
static inline functions in C++, with predictably terrible results.  This
fixes that and also gives better linkage than 'weak' when merging is required.

llvm-svn: 104581
2010-05-25 04:30:21 +00:00
Daniel Dunbar 532177685a IRgen/C++: When mark vtables used, make sure to still append to the VTableUse array if we promote a vtable from being just used to having its definition required. This ensures that we properly inform the consumer about whether the vtable is required or not, previously we could fail to do so when the vtable was in the VTableUses array before the decl which marked it as required.
- I think this can be cleaned up, since this means we may notify the consumer about the vtable twice, but I didn't see an easy fix for this without more substantial refactoring.
 - Doug, please review!

llvm-svn: 104577
2010-05-25 00:33:13 +00:00
Benjamin Kramer dc99965343 Add a comment for r104472.
llvm-svn: 104473
2010-05-23 20:57:46 +00:00
Benjamin Kramer 11d4d9ec4e PR5863: Don't erase unreachable BBs which have an associated cleanup size.
This works around a crash where malloc reused the memory of an erased BB for a
new BB leaving old cleanup information pointing at the new block.

llvm-svn: 104472
2010-05-23 20:00:44 +00:00
Anders Carlsson 5b94443b16 Really fix PR7139. There was one boost test that we still failed, and my first fix broke self-host.
llvm-svn: 104447
2010-05-22 17:45:10 +00:00
Anders Carlsson c0964b60e5 Re-land the fix for PR7139.
llvm-svn: 104446
2010-05-22 17:35:42 +00:00
Douglas Gregor 959d5a0cbd Implement support for variable length arrays in C++. VLAs are limited
in several important ways:

  - VLAs of non-POD types are not permitted.
  - VLAs cannot be used in conjunction with C++ templates.

These restrictions are intended to keep VLAs out of the parts of the
C++ type system where they cause the most trouble. Fixes PR5678 and
<rdar://problem/8013618>.

llvm-svn: 104443
2010-05-22 16:17:30 +00:00
Douglas Gregor aae38d6610 Improve our handling of reference binding for subobjects of
temporaries. There are actually several interrelated fixes here:

  - When converting an object to a base class, it's only an lvalue
  cast when the original object was an lvalue and we aren't casting
  pointer-to-derived to pointer-to-base. Previously, we were
  misclassifying derived-to-base casts of class rvalues as lvalues,
  causing various oddities (including problems with reference binding
  not extending the lifetimes of some temporaries).

  - Teach the code for emitting a reference binding how to look
  through no-op casts and parentheses directly, since
  Expr::IgnoreParenNoOpCasts is just plain wrong for this. Also, make
  sure that we properly look through multiple levels of indirection
  from the temporary object, but destroy the actual temporary object;
  this fixes the reference-binding issue mentioned above.

  - Teach Objective-C message sends to bind the result as a temporary
    when needed. This is actually John's change, but it triggered the
    reference-binding problem above, so it's included here. Now John
    can actually test his return-slot improvements.

llvm-svn: 104434
2010-05-22 05:17:18 +00:00
Anders Carlsson c866eb5ba9 Unbreak self-host.
llvm-svn: 104390
2010-05-21 22:17:48 +00:00
Anders Carlsson da1641cd12 Rename CodeGenFunction::EmitMemSetToZero to EmitNullInitialization. Handle setting null data member pointers correctly. Fixes PR7139.
llvm-svn: 104387
2010-05-21 21:45:41 +00:00
Douglas Gregor c5871f07f0 When generating the call arguments in a thunk to call the thunkee, do
not make copies non-POD arguments or arguments passed by reference:
just copy the pointers directly. This eliminates another source of the
dreaded memcpy-of-non-PODs. Fixes PR7188.

llvm-svn: 104327
2010-05-21 17:55:12 +00:00
John McCall c4094935c0 When emitting an lvalue for an anonymous struct or union member during
class initialization, drill down through an arbitrary number of anonymous
records.

llvm-svn: 104310
2010-05-21 01:18:57 +00:00
John McCall bc83b3f011 Be sure to apply initializers to members of anonymous structs and unions
recursively, e.g. so that members of anonymous unions inside anonymous structs
still get initialized.  Also generate default constructor calls for anonymous
struct members when necessary.

llvm-svn: 104292
2010-05-20 23:23:51 +00:00
Douglas Gregor 7c38f153ac Rework our handling of binding a reference to a temporary
subobject. Previously, we could only properly bind to a base class
subobject while extending the lifetime of the complete object (of a
derived type); for non-static data member subobjects, we could memcpy
(!) the result and bind to that, which is rather broken.

Now, we pull apart the expression that we're binding to, to figure out
which subobject we're accessing, then construct the temporary object
(adding a destruction if needed) and, finally, dig out the subobject
we actually meant to access.

This fixes yet another instance where we were memcpy'ing rather than
doing the right thing. However, note the FIXME in references.cpp:
there's more work to be done for binding to subobjects, since the AST
is incorrectly modeling some member accesses in base classes as
lvalues when they are really rvalues.

llvm-svn: 104219
2010-05-20 08:36:28 +00:00
Douglas Gregor aa2ac80eaa When creating a this-adjustment thunk where the return value is of C++
class type (that uses a return slot), pass the return slot to the
callee directly rather than allocating new storage and trying to copy
the object. This appears to have been the cause of the remaining two
Boost.Interprocess failures.

llvm-svn: 104215
2010-05-20 05:54:35 +00:00
Anders Carlsson be48c548c5 Correctly initialize bases with member pointers. This should fix PR6441 but that test case is a bit weird and I'd like to investigate further before closing that bug.
llvm-svn: 104025
2010-05-18 16:51:41 +00:00
Daniel Dunbar cd20ce1513 C++/Darwin/i386 ABI: Fix some problems with empty record handling.
- Check bases as part of isEmptyRecord().

 - C++ record fields are never empty in the Itanium ABI.

llvm-svn: 103944
2010-05-17 16:46:00 +00:00
Douglas Gregor 9154b5dffe Ensure that destructors are called for NRVO'd objects when the
function does not return. Thanks to Eli for pointing out this corner
case.

llvm-svn: 103941
2010-05-17 15:52:46 +00:00
Chandler Carruth e299ba66f5 When constant folding reference variables with an initializer to the
initializer, don't fold paramters. Their initializers are just default
arguments which can be overridden. This fixes some spectacular regressions due
to more things making it into the constant folding.

llvm-svn: 103904
2010-05-16 09:32:51 +00:00
Douglas Gregor 51150ab1f1 When initializing thread-safe statics, put the call to
__cxa_guard_abort along the exceptional edge into (in effect) a nested
"try" that rethrows after aborting. Fixes PR7144 and the remaining
Boost.ProgramOptions failures, along with the regressions that r103880
caused.

The crucial difference between this and r103880 is that we now follow
LLVM's little dance with the llvm.eh.exception and llvm.eh.selector
calls, then use _Unwind_Resume_or_Rethrow to rethrow.

llvm-svn: 103892
2010-05-16 01:24:12 +00:00
Douglas Gregor c278d1b3b9 Revert r103880 (thread-safe static initialization w/ exceptions),
because it's causing strange linker errors. Unfixes PR7144.

llvm-svn: 103890
2010-05-16 00:44:00 +00:00
Douglas Gregor 58142dd8a1 When initializing thread-safe statics, put the call to
__cxa_guard_abort along the exceptional edge into (in effect) a nested
"try" that rethrows after aborting. Fixes PR7144 and the remaining
Boost.ProgramOptions failures.

llvm-svn: 103880
2010-05-15 17:55:51 +00:00
Douglas Gregor 4f0ed42601 Attempt to satisfy Release-Asserts build
llvm-svn: 103879
2010-05-15 17:28:53 +00:00
Douglas Gregor 170125648c When applying the named return value optimization, we still need to
destroy the variable along the exceptional edge; it's only during
normal execution that we avoid destroying this variable.

llvm-svn: 103872
2010-05-15 16:39:56 +00:00
Douglas Gregor 290c93ec0d Implement a simple form of the C++ named return value optimization for
return statements. We perform NRVO only when all of the return
statements in the function return the same variable. Fixes some link
failures in Boost.Interprocess (which is relying on NRVO), and
probably improves performance for some C++ applications.

llvm-svn: 103867
2010-05-15 06:46:45 +00:00
Daniel Dunbar 36d4d1541c C++/ABI/x86_64: Member pointers should be classified as INTEGER.
llvm-svn: 103843
2010-05-15 00:00:37 +00:00
Daniel Dunbar 4bd95c65e7 C++/ABI/i386: Member function pointers should be passed by value.
llvm-svn: 103842
2010-05-15 00:00:30 +00:00
Douglas Gregor 2d15ecad39 Tweak test so that it does not require <typeinfo>
llvm-svn: 103819
2010-05-14 21:50:50 +00:00
Douglas Gregor 1c073f47da Emit an lvalue dynamic_cast even if the result is not used. Another
part (or possibly all) of PR7132.

llvm-svn: 103810
2010-05-14 21:31:02 +00:00
Douglas Gregor fa8b4955bb When a failed dynamic_cast<T&> (which is an lvalue) results in a
throw, it should use invoke when needed. The fixes the
Boost.Statechrt failures that motivated PR7132, but there are a few
side issues to tackle as well.

llvm-svn: 103803
2010-05-14 21:14:41 +00:00
Anders Carlsson 65c6d541dd Make sure that value-initialized pointers to data members are initialized correctly.
llvm-svn: 103771
2010-05-14 15:05:19 +00:00
Douglas Gregor 83de20f5e3 A vtable is used if the key function is defined... even if that key
function's definition is an out-of-class definition marked
"inline". Fixes an assertion in WebKit.

llvm-svn: 103763
2010-05-14 04:08:48 +00:00
Daniel Dunbar 64585cdb66 XFAIL a test on Win32.
llvm-svn: 103762
2010-05-14 03:54:53 +00:00
Daniel Dunbar 6b45b67b26 C++/Darwin/x86: Teach IRgen it can pass reference types in registers.
llvm-svn: 103761
2010-05-14 03:40:53 +00:00
Douglas Gregor 500d9f8221 Disable the available_externally optimization for inline virtual
methods for which the key function is guaranteed to be in another
translation unit. Unfortunately, this guarantee isn't the case when
dealing with shared libraries that fail to export these virtual method
definitions. 

I'm reopening PR6747 so we can consider this again at a later point in
time.

llvm-svn: 103741
2010-05-13 21:36:56 +00:00
Douglas Gregor 88d292ccb8 Rework when and how vtables are emitted, by tracking where vtables are
"used" (e.g., we will refer to the vtable in the generated code) and
when they are defined (i.e., because we've seen the key function
definition). Previously, we were effectively tracking "potential
definitions" rather than uses, so we were a bit too eager about emitting
vtables for classes without key functions. 

The new scheme:
  - For every use of a vtable, Sema calls MarkVTableUsed() to indicate
  the use. For example, this occurs when calling a virtual member
  function of the class, defining a constructor of that class type,
  dynamic_cast'ing from that type to a derived class, casting
  to/through a virtual base class, etc.
  - For every definition of a vtable, Sema calls MarkVTableUsed() to
  indicate the definition. This happens at the end of the translation
  unit for classes whose key function has been defined (so we can
  delay computation of the key function; see PR6564), and will also
  occur with explicit template instantiation definitions.
 - For every vtable defined/used, we mark all of the virtual member
 functions of that vtable as defined/used, unless we know that the key
 function is in another translation unit. This instantiates virtual
 member functions when needed.
  - At the end of the translation unit, Sema tells CodeGen (via the
  ASTConsumer) which vtables must be defined (CodeGen will define
  them) and which may be used (for which CodeGen will define the
  vtables lazily). 

From a language perspective, both the old and the new schemes are
permissible: we're allowed to instantiate virtual member functions
whenever we want per the standard. However, all other C++ compilers
were more lazy than we were, and our eagerness was both a performance
issue (we instantiated too much) and a portability problem (we broke
Boost test cases, which now pass).

Notes:
  (1) There's a ton of churn in the tests, because the order in which
  vtables get emitted to IR has changed. I've tried to isolate some of
  the larger tests from these issues.
  (2) Some diagnostics related to
  implicitly-instantiated/implicitly-defined virtual member functions
  have moved to the point of first use/definition. It's better this
  way.
  (3) I could use a review of the places where we MarkVTableUsed, to
  see if I missed any place where the language effectively requires a
  vtable.

Fixes PR7114 and PR6564.

llvm-svn: 103718
2010-05-13 16:44:06 +00:00
Daniel Dunbar 12ebb47a07 IRgen/i386/C++: Fix isSingleElementStruct computation for C++ record decls.
- Fixes PR7098.

llvm-svn: 103514
2010-05-11 21:15:36 +00:00
Douglas Gregor ff73a9e380 When instantiating statements that involve conditions (if, while, do,
for, and switch), be careful to construct the full expressions as soon
as we perform template instantation, so we don't either forget to call
temporary destructors or destroy temporaries at the wrong time. This
is the template-instantiation analogue to r103187, during which I
hadn't realized that the issue would affect the handling of these
constructs differently inside and outside of templates.

Fixes a regression in Boost.Function.

llvm-svn: 103357
2010-05-08 22:20:28 +00:00
Douglas Gregor 14653638de Fix test for Release-Asserts build
llvm-svn: 103337
2010-05-08 16:04:01 +00:00
Douglas Gregor d8bb3aff76 Do not give implicitly-defined virtual members functions
available_externally linkage, since they may not have been given a
strong definition in another translation unit. Without this patch, the
following test case fails to link with a GCC-compiled libstdc++:

  #include <sstream>
  int main() { std::basic_stringbuf<char> bs; }

Fixes the last problem with the Boost.IO library.

llvm-svn: 103208
2010-05-06 23:13:35 +00:00
Douglas Gregor ae498b3211 The global variable for the VTT might not have external linkage; allow
us to find local variables, too. Fixes the last remaining
Boost.Rational failure.

llvm-svn: 103203
2010-05-06 22:18:21 +00:00
Douglas Gregor e60e41add9 Rework our handling of temporary objects within the conditions of
if/switch/while/do/for statements. Previously, we would end up either:

  (1) Forgetting to destroy temporaries created in the condition (!),
  (2) Destroying the temporaries created in the condition *before*
  converting the condition to a boolean value (or, in the case of a
  switch statement, to an integral or enumeral value), or
  (3) In a for statement, destroying the condition's temporaries at
  the end of the increment expression (!).

We now destroy temporaries in conditions at the right times. This
required some tweaking of the Parse/Sema interaction, since the parser
was building full expressions too early in many places.

Fixes PR7067.

llvm-svn: 103187
2010-05-06 17:25:47 +00:00
Chris Lattner 44456d294c simplify EmitAggMemberInitializer a bit and make it work in 32-bit mode,
fixing PR7063.

llvm-svn: 103171
2010-05-06 06:35:23 +00:00
Chris Lattner 3baada6fd7 Pass the globaldecl into GetOrCreateLLVMFunction so that llvm
function attributes like byval get applied to the function 
definition. This fixes PR7058 and makes i386 llvm/clang bootstrap 
pass all the same tests as x86-64 bootstrap for me (the llvmc 
tests still fail in both).

llvm-svn: 103131
2010-05-05 22:55:13 +00:00
Douglas Gregor d450f06ef4 When we emit a non-constant initializer for a global variable of
reference type, make sure that the initializer we build is the
of the appropriate type for the *reference*, not for the thing that it
refers to. Fixes PR7050.

llvm-svn: 103115
2010-05-05 20:15:55 +00:00
Douglas Gregor 370eadf38d For thread-safe static initialization of local statics with
destructors, place the __cxa_atexit call after the __cxa_guard_release
call, mimicking GCC/LLVM-GCC behavior. Noticed while debugging
something related.

llvm-svn: 103088
2010-05-05 15:38:32 +00:00
Douglas Gregor 94f9a4820a Reimplement code generation for copying fields in the
implicitly-generated copy constructor. Previously, Sema would perform
some checking and instantiation to determine which copy constructors,
etc., would be called, then CodeGen would attempt to figure out which
copy constructor to call... but would get it wrong, or poke at an
uninstantiated default argument, or fail in other ways.

The new scheme is similar to what we now do for the implicit
copy-assignment operator, where Sema performs all of the semantic
analysis and builds specific ASTs that look similar to the ASTs we'd
get from explicitly writing the copy constructor, so that CodeGen need
only do a direct translation.

However, it's not quite that simple because one cannot explicit write
elementwise copy-construction of an array. So, I've extended
CXXBaseOrMemberInitializer to contain a list of indexing variables
used to copy-construct the elements. For example, if we have:

  struct A { A(const A&); };
  
  struct B {
    A array[2][3];
  };

then we generate an implicit copy assignment operator for B that looks
something like this:

  B::B(const B &other) : array[i0][i1](other.array[i0][i1]) { }

CodeGen will loop over the invented variables i0 and i1 to visit all
elements in the array, so that each element in the destination array
will be copy-constructed from the corresponding element in the source
array. Of course, if we're dealing with arrays of scalars or class
types with trivial copy-assignment operators, we just generate a
memcpy rather than a loop.

Fixes PR6928, PR5989, and PR6887. Boost.Regex now compiles and passes
all of its regression tests.

Conspicuously missing from this patch is handling for the exceptional
case, where we need to destruct those objects that we have
constructed. I'll address that case separately.

llvm-svn: 103079
2010-05-05 05:51:00 +00:00
Anders Carlsson 58fe1756fb Use a more appropriate LLVM type for the vtable pointer.
llvm-svn: 103078
2010-05-05 05:47:36 +00:00
Fariborz Jahanian eeb233793d Fixes a code gen crash when block is a reference type, etc.
(radar 7495203).

llvm-svn: 103022
2010-05-04 17:59:32 +00:00
John McCall e61b02bcaf When inheriting a default argument expression, inherit the full expression,
not just the inner expression.  This is important if the expression has any
temporaries.  Fixes PR 7028.

Basically a symptom of really tragic method names.

llvm-svn: 102998
2010-05-04 01:53:42 +00:00
Fariborz Jahanian 751f7bc03c Fixes a Code Gen. Crash when calling destructor on a __block
variabe. Blocks and their construction/destruction is
wip though. 

llvm-svn: 102985
2010-05-04 00:26:07 +00:00
John McCall 5828ee7a27 Just bail out immediately when emitting an unreachable function-local static
variable.  Surprisingly, this does seem to be the right way to solve this.

llvm-svn: 102961
2010-05-03 21:39:56 +00:00
Douglas Gregor aee1f51485 If we're generating code to create a pointer-to-member function
aggregate and the result of the aggregate is unused, bail out
early. Fixes PR7027.

llvm-svn: 102942
2010-05-03 20:00:27 +00:00
Anders Carlsson 3572d44190 When computing the address of a virtual member function pointer, use the pointer width instead of hardcoding for 64-bit.
llvm-svn: 102921
2010-05-03 16:05:06 +00:00
Douglas Gregor df9ae794ca Try to unbreak clang-i686-darawin10 builder
llvm-svn: 102920
2010-05-03 15:51:04 +00:00
Anders Carlsson f93cb3bacb Get rid of virt.cpp.
llvm-svn: 102918
2010-05-03 15:49:15 +00:00
Douglas Gregor 456ad1a817 When a class contains a non-empty anonymous union or struct, mark is
as non-empty. Fixes PR7021.

llvm-svn: 102913
2010-05-03 15:18:25 +00:00
Anders Carlsson d040e6b25a Don't build an aggregate constructor loop when the constructor is trivial.
llvm-svn: 102912
2010-05-03 15:09:17 +00:00
Anders Carlsson 604f560c39 Add test case that I forgot to check in.
llvm-svn: 102905
2010-05-03 14:22:40 +00:00
Anders Carlsson 16e94af67c Don't copy or initialize empty classes. Fixes PR7012.
llvm-svn: 102891
2010-05-03 01:20:20 +00:00
Douglas Gregor b139cd5843 Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators. 

Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.

This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:

  - For a class subobject, call the appropriate copy-assignment
    operator, after overload resolution has determined what that is.
  - For an array of scalar types or an array of class types that have
    trivial copy assignment operators, construct a call to
    __builtin_memcpy.
  - For an array of class types with non-trivial copy assignment
    operators, synthesize a (possibly nested!) for loop whose inner
    statement calls the copy constructor.
  - For a scalar type, use built-in assignment.

This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.

Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.

llvm-svn: 102853
2010-05-01 20:49:11 +00:00
Chris Lattner 036078ca76 with recent optimizer changes, these all get devirtualized.
llvm-svn: 102825
2010-05-01 01:42:06 +00:00
John McCall b3cec96a7c Account for the VTT argument when making an implicit copy constructor for
a class with virtual bases.  Just a patch until Sema starts (correctly) doing
most of this analysis.

Fixes PR 6622.

llvm-svn: 102692
2010-04-30 05:56:45 +00:00
John McCall 48bf349471 Fix -fno-rtti -fexceptions by forcing the emission of (non-"builtin") RTTI
when used by the exceptions routines.  Fixes PR 6974.

llvm-svn: 102684
2010-04-30 01:15:21 +00:00
Douglas Gregor 980fb16f9a When determining a standard conversion sequence involves resolving the
address of an overloaded function (or function template), perform that
resolution prior to determining the implicit conversion
sequence. This resolution is not part of the implicit conversion
sequence itself.

Previously, we would always consider this resolution to be a
function pointer decay, which was a lie: there might be an explicit &
in the expression, in which case decay should not occur. This caused
the CodeGen assertion in PR6973 (where we created a 
pointer to a pointer to a function when we should have had a pointer
to a function), but it's likely that there are corner cases of
overload resolution where this would have failed.

Cleaned up the code involved in determining the type that will
produced afer resolving the overloaded function reference, and added
an assertion to make sure the result is correct. Fixes PR6973.

llvm-svn: 102650
2010-04-29 18:24:40 +00:00
Douglas Gregor 7988def89f Improve name mangling for dependent template names (e.g., typename
T::template apply<U>), handling a few cases where we previously failed
and performing substitutions on such dependent names. Fixes a crash in
Boost.PropertyTree.

llvm-svn: 102490
2010-04-28 05:58:56 +00:00
Douglas Gregor 199db36b79 When explicitly building a temporary object (CXXTemporaryObjectExpr),
keep track of whether we need to zero-initialize storage prior to
calling its constructor. Previously, we were only tracking this when
implicitly constructing the object (a CXXConstructExpr).

Fixes Boost's value-initialization tests, which means that the
Boost.Config library now passes all of its tests.

llvm-svn: 102461
2010-04-27 20:36:09 +00:00
Chris Lattner 5e8416a77f emit dtors with the right calling convention in -fno-use-cxa-atexit
mode.

llvm-svn: 102377
2010-04-26 20:35:54 +00:00
Chris Lattner 954daf9aa5 remove alignment specifier on this. CAn't this test be removed yet? :)
llvm-svn: 102369
2010-04-26 19:47:56 +00:00
Douglas Gregor 9094fcb7c1 Tweak test for destruction of copied temporary objects
llvm-svn: 102291
2010-04-25 00:56:07 +00:00
Douglas Gregor d0ace02496 When copying a temporary object to initialize an entity for which the
temporary needs to be bound, bind the copy object. Otherwise, we won't
end up calling the destructor for the copy. Fixes Boost.Optional.

llvm-svn: 102290
2010-04-25 00:55:24 +00:00
Douglas Gregor 914af2182b Handle compound assignment expressions (i += j) as lvalues, which is
permitted in C++ but not in C. Fixes PR6900. Clang can now handle all
of Boost.Lambda's regression tests.

llvm-svn: 102170
2010-04-23 04:16:32 +00:00
Douglas Gregor 173627188d Mangle dependent template names such as the nested-name-specifier in
T::apply <U>::type

Fixes PR6899, although I want to dig a little deeper into the FIXME
for dependent template names that refer to operators.

llvm-svn: 102167
2010-04-23 03:10:43 +00:00
Douglas Gregor 19043f0a6a I hate default statements. Fixes PR6874.
llvm-svn: 102160
2010-04-23 02:02:43 +00:00
John McCall 69349f458b Neuter this testcase a little. The way LLVM writes labels for anonymous blocks
makes it impossible to check labels.

llvm-svn: 102048
2010-04-22 03:27:09 +00:00