Commit Graph

1192 Commits

Author SHA1 Message Date
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
John McCall 2e6567ae60 Call PerformCopyInitialization to properly initialize the exception temporary
in a throw expression.  Use EmitAnyExprToMem to emit the throw expression,
which magically elides the final copy-constructor call (which raises a new
strict-compliance bug, but baby steps).  Give __cxa_throw a destructor pointer
if the exception type has a non-trivial destructor.

llvm-svn: 102039
2010-04-22 01:10:34 +00:00
Devang Patel b9ab309650 Encode field accessibility.
llvm-svn: 102033
2010-04-21 23:12:37 +00:00
Fariborz Jahanian acdfa7acfe Fixes a code gen. bug by removing an assert.
It is ok to have c++-ness inside extern "C" 
block. Fixes pr6644.

llvm-svn: 101948
2010-04-20 22:02:31 +00:00
Anders Carlsson 91baecfeb3 Back out r101911 and see if it makes the bots happy.
llvm-svn: 101921
2010-04-20 18:05:10 +00:00
Anders Carlsson 6a0227df49 Fix a bug which triggered the assertion I added yesterday. Basically, when we initialize the vtable pointer for a virtual base, and there was another path from the most derived class to another base with the same class type, we would use the wrong base.
llvm-svn: 101911
2010-04-20 16:22:16 +00:00
Chris Lattner 9cffdf1331 don't slap noalias attribute on stret result arguments.
This mirror's Dan's patch for llvm-gcc in r97989, and
fixes the miscompilation in PR6525.  There is some contention
over whether this is the right thing to do, but it is the
conservative answer and demonstrably fixes a miscompilation.

llvm-svn: 101877
2010-04-20 05:44:43 +00:00
John McCall 0f55a035cf Restore r101841 without modification. Also mark 'operator delete' as used for
actual delete expressions, not just new expressions.

llvm-svn: 101861
2010-04-20 02:18:25 +00:00
Rafael Espindola 683fe4fc4c If a method is virtual and the class key function is in another file, emit the method as available_externally.
Fixes PR6747

llvm-svn: 101757
2010-04-19 00:44:22 +00:00
Fariborz Jahanian 3fef72f0ba Local static variables must be available module-wise
as they are accessible in static methods in a class
local to the same function. Fixes PR6769.

llvm-svn: 101756
2010-04-18 21:01:23 +00:00
Anders Carlsson d5f27b0583 Simplify wide bit-field layout in CGRecordLayoutBuilder, and also fix a bug where assigning to a bit-field member would overwrite other parts of the struct.
llvm-svn: 101681
2010-04-17 22:54:57 +00:00
Anders Carlsson 2295f13bb0 Unnamed bit-fields in a union should be laid out with a type that doesn't affect alignment.
llvm-svn: 101673
2010-04-17 21:04:52 +00:00
Anders Carlsson aad5fa85d0 If a wide bit-field is inside a union its offset should always be 0.
llvm-svn: 101668
2010-04-17 20:21:41 +00:00
Anders Carlsson c6db5ab8b2 Fix a bug where we would sometimes incorrectly mark an vtable function as unused.
llvm-svn: 101643
2010-04-17 17:24:33 +00:00
Ted Kremenek 1a596562ed Specify temporary file for -emit-llvm output in test case so that we don't deposit the file
in the original source directory.

llvm-svn: 101402
2010-04-15 21:11:33 +00:00
Anders Carlsson ea7b18298e Split adding the primary virtual base offsets out into a separate pass. This fixes a bug where we would lay out virtual bases in the wrong order.
llvm-svn: 101373
2010-04-15 16:12:58 +00:00
Fariborz Jahanian 9ffd706bd4 Add encoding of reference types like gcc does for objc methods and
blocks. Fixes PR6468.

llvm-svn: 101196
2010-04-13 23:45:47 +00:00
Devang Patel 74c10507a6 Fix debug info for cleanup block.
llvm-svn: 101100
2010-04-13 00:08:43 +00:00
Nick Lewycky 7ff88f8b00 Typo.
llvm-svn: 101015
2010-04-12 05:32:01 +00:00
Anders Carlsson 3383e2ad74 Fix another bug where we wouldn't generate secondary vtables for construction vtables in some cases.
llvm-svn: 100998
2010-04-11 22:20:36 +00:00
Anders Carlsson 343a26b56d Fix a bug where we were adding too many vcall offsets in some cases.
llvm-svn: 100985
2010-04-11 20:04:11 +00:00
Anders Carlsson 7a148f7141 Fix another vbase layout bug.
llvm-svn: 100952
2010-04-10 21:35:33 +00:00
Anders Carlsson 88cf34f2b4 Fix a bug where we would add the same function twice in a vtable.
llvm-svn: 100949
2010-04-10 20:39:29 +00:00
Anders Carlsson 291279e3a6 Simplify the virtual base layout code and fix a bug where we wouldn't store the offset for a virtual base.
llvm-svn: 100940
2010-04-10 18:42:27 +00:00
John McCall 09277542f2 Provide manglings for bool and character literal expressions. These are
just integer-literal expressions with special case implementations in the AST.

Fixes rdar://problem/7825453.

llvm-svn: 100905
2010-04-09 21:48:08 +00:00
John McCall 3155f573f5 Turn access control on by default in -cc1.
Remove -faccess-control from -cc1; add -fno-access-control.
Make the driver pass -fno-access-control by default.
Update a bunch of tests to be correct under access control.

llvm-svn: 100880
2010-04-09 19:03:51 +00:00
Douglas Gregor eadd3cace9 Eliminate excessive PCH deserialization caused by the search for
__cxxabiv1::__fundamental_type_info in every translation
unit. Previously, we would perform name lookup for
__cxxabiv1::__fundamental_type_info at the end of IRGen for a each
translation unit, to determine whether it was present. If so, we we
produce type information for all of the fundamental types. However,
this name lookup causes PCH deserialization of a significant part of the
translation unit, which has a woeful impact on performance.

With this change, we now look at each record type after we've
generated its vtable to see if it is
__cxxabiv1::__fundamental_type_info. If so, we generate type info for
all of the fundamental types. This works because
__cxxabiv1::__fundamental_type_info should always have a key function
(typically the virtual destructor), that will be defined once in the
support library. The fundamental type information will end up there.

Fixes <rdar://problem/7840011>.

llvm-svn: 100772
2010-04-08 15:52:03 +00:00
Mon P Wang cc2ab0cdc9 Reapply patch for adding support for address spaces and added a isVolatile field to memcpy, memmove, and memset.
llvm-svn: 100305
2010-04-04 03:10:52 +00:00
Rafael Espindola 8e7ca8e0b1 Don't produce a vtable for a class if we have an explicit template instantiation declaration and no key function. We will produce the vtable at the explicit template instantiation.
Fixes PR6748

llvm-svn: 100266
2010-04-03 04:26:42 +00:00
Douglas Gregor ce6c2748f7 We seem to get an inconsistent alignment value in the generated
assembly for the global "d7". We were previously testing for alignment
3, which seems to happen for some builders and not for others. I've
eliminated the alignment check and added a FIXME to unbreak the
buildbots.

llvm-svn: 100205
2010-04-02 19:02:06 +00:00
Mon P Wang f7f3bff646 Revert r100193 since it causes failures in objc in clang
llvm-svn: 100200
2010-04-02 18:43:42 +00:00
Douglas Gregor 45cf7e3d2a Rework our handling of copy construction of temporaries, which was a
poor (and wrong) approximation of the actual rules governing when to
build a copy and when it can be elided.

The correct implementation is actually simpler than the
approximation. When we only enumerate constructors as part of
initialization (e.g., for direct initialization or when we're copying
from a class type or one of its derived classes), we don't create a
copy. When we enumerate all conversion functions, we do create a
copy. Before, we created some extra copies and missed some
others. The new test copy-initialization.cpp shows a case where we
missed creating a (required, non-elidable) copy as part of a
user-defined conversion, which resulted in a miscompile. This commit
also fixes PR6757, where the missing copy made us reject well-formed
code in the ternary operator.

This commit also cleans up our handling of copy elision in the case
where we create an extra copy of a temporary object, which became
necessary now that we produce the right copies. The code that seeks to
find the temporary object being copied has moved into
Expr::getTemporaryObject(); it used to have two different
not-quite-the-same implementations, one in Sema and one in CodeGen.

Note that we still do not attempt to perform the named return value
optimization, so we miss copy elisions for return values and throw
expressions.

llvm-svn: 100196
2010-04-02 18:24:57 +00:00
Mon P Wang 4b82a88764 Reapply patch for adding support for address spaces and added a isVolatile field to memcpy, memmove, and memset.
llvm-svn: 100193
2010-04-02 18:04:30 +00:00
Douglas Gregor d7f18dd750 Drastically simplify the computation of linkage for typeinfo by using
the existing (and already well-tested) linkage computation for types,
with minor tweaks for dynamic classes and (pointers to) incomplete
types. Fixes PR6597.

llvm-svn: 99968
2010-03-31 00:15:35 +00:00
John McCall d9c7c6568e Introduce a new kind of derived-to-base cast which bypasses the need for
null checks, and make sure we elide null checks when accessing base class
members.

llvm-svn: 99963
2010-03-30 23:58:03 +00:00
Bob Wilson adb58e32cc Revert Mon Ping's 99930 due to broken llvm-gcc buildbots.
llvm-svn: 99949
2010-03-30 22:28:46 +00:00
Mon P Wang 231e99743a Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset
llvm-svn: 99930
2010-03-30 21:02:45 +00:00
Rafael Espindola ff6a1fc1f3 Don't produce a vtable if we are just instantiating a method and the
class has no key function.

Fix PR6738.

llvm-svn: 99900
2010-03-30 18:07:27 +00:00
Anders Carlsson 9d08fc1cd2 Use the new function in EmitClassAggrMemberwiseCopy, fixing the same assert as seen in PR6628 but for arrays this time.
llvm-svn: 99867
2010-03-30 03:30:08 +00:00
Anders Carlsson 10834b8d56 Handle default arguments when calling copy constructors for bases or members when synthesizing a copy constructor. Fixes PR6628.
llvm-svn: 99864
2010-03-30 02:57:48 +00:00
Anders Carlsson c3a4b12c82 Change a test to FileCheck bitcode instead of assembler.
llvm-svn: 99863
2010-03-30 02:53:30 +00:00
Anders Carlsson 85e64359df Flip the switch and use the new vtable layout code for everything. I've verified that this passes a self-host but I'll let the bots self host as well before removing the now dead code.
llvm-svn: 99861
2010-03-30 02:21:54 +00:00
Anders Carlsson e47380fb19 When collecting virtual bases it's very important to use the canonical type of the base class. Otherwise, we might add the same virtual base class twice if the virtual base is an instantiated template. Fixes PR6251.
llvm-svn: 99829
2010-03-29 19:49:09 +00:00
Anders Carlsson eba1a60ef0 Another vtable layout fix, making us match gcc better.
llvm-svn: 99812
2010-03-29 15:08:41 +00:00
Anders Carlsson 174376629a Give thunks the same linkage as their original methods.
llvm-svn: 99729
2010-03-27 20:50:27 +00:00
Rafael Espindola 6e281ffdc0 Test for the previous commit.
llvm-svn: 99702
2010-03-27 02:52:40 +00:00
Douglas Gregor c14922f14a When adding initializers to a constructor, be sure that we are looking
through the bases and fields of the definition of the class in which
the constructor is declared, rather than some other declaration of
that class.

llvm-svn: 99661
2010-03-26 22:43:07 +00:00
Anders Carlsson 151b062fee Don't add address points for virtual primary bases that aren't primary bases in the complete class.
llvm-svn: 99555
2010-03-25 21:45:14 +00:00
Fariborz Jahanian bb4978fbae Check for some code gen. for PR6641 test.
llvm-svn: 99526
2010-03-25 18:05:35 +00:00
Douglas Gregor 99970f008c Check for ret, so that we know we hit the end of the function
llvm-svn: 99448
2010-03-24 23:19:27 +00:00
Douglas Gregor 02dde146e0 When returning from a function that has a reference return type, use
EmitReferenceBindingToExpr() rather than assuming we have an
lvalue. This is just the lowest hanging fruit for PR6024, which still
requires a bit of work.

llvm-svn: 99447
2010-03-24 23:14:04 +00:00
Rafael Espindola 1dbd474f2e Discussing with dgregor we decided that we should not force the emission of
implicit methods on explicit template instantiation definitions. As a
consequence, we should emit them at every use, even if we see a explicit
template instantiation declaration.

This is already the current behaviour, but it is good to test for that :-)

llvm-svn: 99443
2010-03-24 22:43:31 +00:00
Fariborz Jahanian 47b4629b3b Code gen for multi-dimensional dynamic allocations.
Fixes PR6641.

llvm-svn: 99404
2010-03-24 16:57:01 +00:00
Anders Carlsson e90954de64 More vtable improvements. We now compute and keep track of all vtable related information which avoids computing the same vtable layout over and over.
llvm-svn: 99403
2010-03-24 16:42:11 +00:00
Anders Carlsson b35ea55e2e More vtable work; preparations for moving over to the new vtable layout code (finally).
llvm-svn: 99381
2010-03-24 03:57:14 +00:00
Anders Carlsson 68fdb871dc Flip the switch and use the new vtable layout code for thunks by default. Add a thunks.cpp test.
llvm-svn: 99367
2010-03-24 00:41:37 +00:00
Anders Carlsson 3537413c4a Remove parts of virt.cpp
llvm-svn: 99363
2010-03-24 00:32:03 +00:00
Rafael Espindola fa1708fdea revert 99311. Looks like it broke darwin bootstrap.
llvm-svn: 99317
2010-03-23 19:55:22 +00:00
Rafael Espindola 4d3745ade6 Avoid producing implicit methods when we have a explicit template instantiation
declaration.

llvm-svn: 99311
2010-03-23 18:56:16 +00:00
Rafael Espindola 8d04f0604e A fixed version of r99174 which also includes a test that we emit vtables when
we see an specialization definition ever if we then see a extern template declaration.

llvm-svn: 99226
2010-03-22 23:12:48 +00:00
Rafael Espindola 46b7987f85 Fix PR6648 by not creating a temporary with the type of a
CXXExprWithTemporaries.

Not emitting the expression as an aggregate might be the right thing to do,
but is orthogonal. Emitting it as an scalar expression will still try to
create a temporary for the incomplete type of the CXXExprWithTemporaries and
fail.

llvm-svn: 99134
2010-03-21 17:11:05 +00:00
Daniel Dunbar e46b52a35f Driver: Fix a number of -fapple-kext issues:
- Disable RTTI.
 - Disable use of __cxa_atexit.
 - Disable unwind tables.
 - Enable freestanding mode.

Also, honor -fhosted correctly.

<rdar://problem/7515383> C++ support: -fapple-kext not honored

llvm-svn: 99041
2010-03-20 04:52:14 +00:00
Daniel Dunbar fe06df4bf3 C++: Add support for -fno-use-cxa-atexit.
- So much typing, so little gain...

Also, rename the __cxx_global_initialization function just to match llvm-gcc.

llvm-svn: 99039
2010-03-20 04:15:41 +00:00
John McCall 7ec5043c2c Change CodeGenModule to rely on the Module's symbol table instead of
shadowing it in the GlobalDeclMap.  Eliminates the string-uniquing
requirement for mangled names, which should help C++ codegen times a little.
Forces us to do string lookups instead of pointer lookups, which might hurt
codegen times a little across the board.  We'll see how it plays out.

Removing the string-uniquing requirement implicitly fixes any bugs like
PR6635 which arose from the fact that we had multiple uniquing tables for
different kinds of identifiers.

llvm-svn: 99012
2010-03-19 23:29:14 +00:00
Anders Carlsson 18c582d9c8 When dumping vtables, also dump the thunks.
llvm-svn: 98799
2010-03-18 02:44:19 +00:00
Rafael Espindola cd7eef900f Correctly mangle dependent TypenameType.
Fixes PR6625.

llvm-svn: 98707
2010-03-17 04:28:11 +00:00
Douglas Gregor b14d123774 Give explicit template instantiations weak ODR linkage. Former
iterations of this patch gave explicit template instantiation
link-once ODR linkage, which permitted the back end to eliminate
unused symbols. Weak ODR linkage still requires the symbols to be
generated.

llvm-svn: 98441
2010-03-13 18:23:07 +00:00
Douglas Gregor 17b76185f1 Re-revert the explicit template instantiation linkage patch. I am beginning to look incompetent
llvm-svn: 98425
2010-03-13 03:49:57 +00:00
Douglas Gregor 89cae0f224 Reinstate patch to turn explicit template instantiations into weak symbols
llvm-svn: 98424
2010-03-13 03:14:19 +00:00
Douglas Gregor 539bc40906 Revert the linkage change for explicit template instantiations; something is amiss
llvm-svn: 98332
2010-03-12 05:13:59 +00:00
Douglas Gregor ee3f72299c Give explicit template instantiations weak linkage (but don't defer
them). Fixes PR6578.

llvm-svn: 98328
2010-03-12 04:49:06 +00:00
Daniel Dunbar 44e51ea41f Use -emit-llvm-only, to avoid leaving a temp around.
llvm-svn: 98267
2010-03-11 18:23:02 +00:00
Rafael Espindola 4d5c3d99e5 Correctly mangle address of member in template arguments. Fixes PR6460
llvm-svn: 98254
2010-03-11 14:07:00 +00:00
Anders Carlsson 3521552ebe Add a test.
llvm-svn: 98246
2010-03-11 06:44:31 +00:00
Anders Carlsson 423406f335 Fix calculation of whether a member function needs a thunk in construction vtables.
llvm-svn: 98191
2010-03-10 21:25:37 +00:00
Anders Carlsson 115b4756b5 We were mistakenly marking morally virtual bases as being uninteresting. Fix this.
llvm-svn: 98180
2010-03-10 19:39:11 +00:00
Anders Carlsson 703a08605f Ignore non-interesting bases when emitting construction vtables.
llvm-svn: 98177
2010-03-10 19:15:26 +00:00
Rafael Espindola e81620fb88 Move test and also test codegen.
llvm-svn: 98154
2010-03-10 14:01:14 +00:00
Anders Carlsson 45be0e069d Add newline.
llvm-svn: 98140
2010-03-10 06:51:56 +00:00
Anders Carlsson 804cf51dcf Don't accidentally mark some functions in construction vtables as unused. Also land the test for a previous checkin, now that it's correct.
llvm-svn: 98139
2010-03-10 06:51:42 +00:00
Anders Carlsson ca82a4fdba Improve vcall offset handling in construction vtables. With this we layout the construction vtables from the ABI examples correctly.
llvm-svn: 98127
2010-03-10 02:33:41 +00:00
Rafael Espindola e7113ca907 Delay codegen of vtables when handling implicit instantiations.
This fixes PR6474.

llvm-svn: 98123
2010-03-10 02:19:29 +00:00
Devang Patel 4f26205ba8 More then one anonymous aggregates on one line creates chaos when MDNode uniquness is combined with RAUW operation. Right solution is to avoid using RAUW.
This fixes PR 6554.

llvm-svn: 98083
2010-03-09 21:32:27 +00:00
Douglas Gregor 589973b097 In C++98/03, an uninitialized variable that has POD class type will be
uninitialized. This seems not to be the case in C++0x, where we still
call the (trivial) default constructor for a POD class
(!). Previously, we had implemented only the C++0x rules; now we
implement both. Fixes PR6536.

llvm-svn: 97928
2010-03-08 02:45:10 +00:00
Douglas Gregor c934bc840c Perform overload resolution when static_cast'ing from a
pointer-to-member-to-derived to a pointer-to-member-to-base. Fixes
PR6072.

llvm-svn: 97923
2010-03-07 23:24:59 +00:00
Eli Friedman b632e30e41 Fix for PR6294: we should only delay recording nested dynamic classes if they
are lexically nested.  Othewise, we never end up recording semantically nested
classes.

llvm-svn: 97900
2010-03-07 05:49:51 +00:00
Douglas Gregor 577cf97cf3 Don't turn off mangling in implicitly extern "C" system headers. GCC
doesn't do this on any of the major platforms, and we don't really
support any of the platforms that do (nor will we actually handle
those headers well). Fixes PR6217; see PR6530 for details on what we
would need to do to support these platforms.

llvm-svn: 97899
2010-03-07 05:10:40 +00:00
Fariborz Jahanian 9eba9dfb0c Refactor local class name mangling and make it
ABI conforming.

llvm-svn: 97702
2010-03-04 01:02:03 +00:00
Fariborz Jahanian a529c25555 Implements mangling of local class names to
fix a code gen crash. This is WIP as not
all ABI cases are covered (there is a FIXME to 
this effect). Fixes radar 7696748.

llvm-svn: 97658
2010-03-03 19:41:08 +00:00
Anders Carlsson 5b0057c05b Fix a bug with base offset merging that Devang noticed.
llvm-svn: 97641
2010-03-03 04:58:02 +00:00
John McCall 1950a11939 Don't emit derived-to-base destructor aliases if we don't have a definition
for the base destructor, because aliases to declarations aren't legal.

Fixes PR 6471.

llvm-svn: 97637
2010-03-03 03:40:11 +00:00
John McCall bd8d9bd39c Split out types that are non-canonical unless dependent as their own
category.  Use this in a few places to eliminate unnecessary TST cases and
do some future-proofing.  Provide terrible manglings for typeof.  Mangle
decltype with some hope of accuracy.

Our manglings for some of the cases covered in the testcase are different
from gcc's, which I've raised as an issue with the ABI list.

llvm-svn: 97523
2010-03-01 23:49:17 +00:00
John McCall de9607bc6f The latest draft uses 'dt' to mangle member expressions, and now so do we.
llvm-svn: 97479
2010-03-01 19:12:25 +00:00
Douglas Gregor a51c67424e Improve name mangling for dependently-scoped declaration references.
llvm-svn: 97422
2010-02-28 22:05:49 +00:00
Douglas Gregor 5610db6923 Add name mangling for DeclRefExprs that refer to external names
llvm-svn: 97418
2010-02-28 21:40:32 +00:00
Anders Carlsson 7162ab947b Handle unused functions in construction vtables correctly.
llvm-svn: 97406
2010-02-28 18:37:33 +00:00
Anders Carlsson 8b37bb7c48 When laying out vtables for virtual bases in construction vtables, we need to check if the vtable is a primary base in the layout class.
llvm-svn: 97402
2010-02-28 18:08:38 +00:00
Anders Carlsson b15d8c57ad Add another construction vtable test.
llvm-svn: 97401
2010-02-28 17:59:36 +00:00
Anders Carlsson e3385f566b More improvements to construction vtables; we know handle vbase offsets correctly (I hope).
llvm-svn: 97361
2010-02-28 01:43:58 +00:00
Anders Carlsson c3f92a16f2 Add a simple construction vtable test.
llvm-svn: 97344
2010-02-27 21:09:00 +00:00
Anders Carlsson e02a926a1c Use the real base offset when calculating vbase offsets.
llvm-svn: 97338
2010-02-27 19:21:58 +00:00