Commit Graph

940 Commits

Author SHA1 Message Date
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