Commit Graph

4034 Commits

Author SHA1 Message Date
Chris Lattner 1f3a063f00 move the last hunk of getCoerceResult into the place
that needs it and remove getCoerceResult.

llvm-svn: 109807
2010-07-29 21:42:50 +00:00
Chris Lattner 60fbd7744f now that direct and coerce are merged, getCoerceResult gets simpler.
llvm-svn: 109805
2010-07-29 21:29:53 +00:00
Chris Lattner 09794695ef now that GetSSETypeAtOffset handles passing SSE class values as
float, the special case hack in getCoerceResult can go away.

llvm-svn: 109804
2010-07-29 21:22:50 +00:00
Argyrios Kyrtzidis c904933aac Change the name to something less terrible; suggestion by Doug. No functionality change.
llvm-svn: 109797
2010-07-29 20:08:05 +00:00
Chris Lattner e556a71859 Implement the clang-side of detection for when to pass as
<2 x float> instead of double.  This works but can't be turned
on until I teach codegen to pass <2 x float> as one XMM register
instead of two.

llvm-svn: 109790
2010-07-29 18:39:32 +00:00
Chris Lattner 50a357e962 Look at me, I can count!
llvm-svn: 109786
2010-07-29 18:19:50 +00:00
Argyrios Kyrtzidis c81af03fb3 Merge PCHWriterDecl.cpp's isRequiredDecl and CodeGenModule::MayDeferGeneration into a new function,
DeclIsRequiredFunctionOrFileScopedVar.

This is essentially a CodeGen predicate that is also needed by the PCH mechanism to determine whether a decl
needs to be deserialized during PCH loading for codegen purposes.
Since this logic is shared by CodeGen and the PCH mechanism, move it to the ASTContext,
thus CodeGenModule's GetLinkageForFunction/GetLinkageForVariable and the GVALinkage enum is moved out of CodeGen.

This fixes current (and avoids future) codegen-from-PCH bugs.

llvm-svn: 109784
2010-07-29 18:15:58 +00:00
Chris Lattner 7f4b81af7a fix rdar://8251384, another case where we could access beyond the
end of a struct.  This improves the case when the struct being passed
contains 3 floats, either due to a struct or array of 3 things.  Before
we'd generate this IR for the testcase:

define float @bar(double %X.coerce0, double %X.coerce1) nounwind {
entry:
  %X = alloca %struct.foof, align 8               ; <%struct.foof*> [#uses=2]
  %0 = bitcast %struct.foof* %X to %1*            ; <%1*> [#uses=2]
  %1 = getelementptr %1* %0, i32 0, i32 0         ; <double*> [#uses=1]
  store double %X.coerce0, double* %1
  %2 = getelementptr %1* %0, i32 0, i32 1         ; <double*> [#uses=1]
  store double %X.coerce1, double* %2
  %tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
  %tmp1 = load float* %tmp                        ; <float> [#uses=1]
  ret float %tmp1
}

which compiled (with optimization) to:

_bar:                                   ## @bar
## BB#0:                                ## %entry
	movd	%xmm1, %rax
	movd	%eax, %xmm0
	ret

Now we produce:

define float @bar(double %X.coerce0, float %X.coerce1) nounwind {
entry:
  %X = alloca %struct.foof, align 8               ; <%struct.foof*> [#uses=2]
  %0 = bitcast %struct.foof* %X to %0*            ; <%0*> [#uses=2]
  %1 = getelementptr %0* %0, i32 0, i32 0         ; <double*> [#uses=1]
  store double %X.coerce0, double* %1
  %2 = getelementptr %0* %0, i32 0, i32 1         ; <float*> [#uses=1]
  store float %X.coerce1, float* %2
  %tmp = getelementptr inbounds %struct.foof* %X, i32 0, i32 2 ; <float*> [#uses=1]
  %tmp1 = load float* %tmp                        ; <float> [#uses=1]
  ret float %tmp1
}

and:

_bar:                                   ## @bar
## BB#0:                                ## %entry
	movaps	%xmm1, %xmm0
	ret

llvm-svn: 109776
2010-07-29 18:13:09 +00:00
Chris Lattner c95a398947 start setting up infrastructure for passing multi-floats
as <2 x float> instead of as double.  The backend isn't ready
yet, but infrastructure in the frontend can come up.

llvm-svn: 109768
2010-07-29 17:49:08 +00:00
Chris Lattner 1c56d9ab56 rename Get8ByteTypeAtOffset -> GetINTEGERTypeAtOffset to
make it clear that this function should only return a type
that the codegen will classify the same as an INTEGER type.

llvm-svn: 109763
2010-07-29 17:40:35 +00:00
Chris Lattner 3f76342cfc handle a case where we could access off the end of a function
that Eli pointed out, rdar://8249586

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

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

llvm-svn: 109759
2010-07-29 17:04:54 +00:00
Chris Lattner 98076a25ce This is a little bit far, but optimize cases like:
struct a {
  struct c {
    double x;
    int y;
  } x[1];
};

void foo(struct a A) {
}

into:

define void @foo(double %A.coerce0, i32 %A.coerce1) nounwind {
entry:
  %A = alloca %struct.a, align 8                  ; <%struct.a*> [#uses=1]
  %0 = bitcast %struct.a* %A to %struct.c*        ; <%struct.c*> [#uses=2]
  %1 = getelementptr %struct.c* %0, i32 0, i32 0  ; <double*> [#uses=1]
  store double %A.coerce0, double* %1
  %2 = getelementptr %struct.c* %0, i32 0, i32 1  ; <i32*> [#uses=1]
  store i32 %A.coerce1, i32* %2

instead of:

define void @foo(double %A.coerce0, i64 %A.coerce1) nounwind {
entry:
  %A = alloca %struct.a, align 8                  ; <%struct.a*> [#uses=1]
  %0 = bitcast %struct.a* %A to %0*               ; <%0*> [#uses=2]
  %1 = getelementptr %0* %0, i32 0, i32 0         ; <double*> [#uses=1]
  store double %A.coerce0, double* %1
  %2 = getelementptr %0* %0, i32 0, i32 1         ; <i64*> [#uses=1]
  store i64 %A.coerce1, i64* %2

I only do this now because I never want to look at this code again :)
 

llvm-svn: 109738
2010-07-29 07:43:55 +00:00
Chris Lattner c8b7b53a1e implement a todo: pass a eight-byte that consists of a
small integer + padding as that small integer.  On code
like:

struct c { double x; int y; };
void bar(struct c C) { }

This means that we compile to:

define void @bar(double %C.coerce0, i32 %C.coerce1) nounwind {
entry:
  %C = alloca %struct.c, align 8                  ; <%struct.c*> [#uses=2]
  %0 = getelementptr %struct.c* %C, i32 0, i32 0  ; <double*> [#uses=1]
  store double %C.coerce0, double* %0
  %1 = getelementptr %struct.c* %C, i32 0, i32 1  ; <i32*> [#uses=1]
  store i32 %C.coerce1, i32* %1

instead of:

define void @bar(double %C.coerce0, i64 %C.coerce1) nounwind {
entry:
  %C = alloca %struct.c, align 8                  ; <%struct.c*> [#uses=3]
  %0 = bitcast %struct.c* %C to %0*               ; <%0*> [#uses=2]
  %1 = getelementptr %0* %0, i32 0, i32 0         ; <double*> [#uses=1]
  store double %C.coerce0, double* %1
  %2 = getelementptr %0* %0, i32 0, i32 1         ; <i64*> [#uses=1]
  store i64 %C.coerce1, i64* %2

which gives SRoA heartburn.

This implements rdar://5711709, a nice low number :)

llvm-svn: 109737
2010-07-29 07:30:00 +00:00
Chris Lattner 2cdfda44a1 fix a builder, why didn't clang++ catch this?
llvm-svn: 109735
2010-07-29 06:44:09 +00:00
Chris Lattner fe34c1d53e Kill off the 'coerce' ABI passing form. Now 'direct' and 'extend' always
have a "coerce to" type which often matches the default lowering of Clang
type to LLVM IR type, but the coerce case can be handled by making them
not be the same.

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

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

into this code at -O0:

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

Now we get:

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

This implements rdar://8248065

llvm-svn: 109733
2010-07-29 06:26:06 +00:00
Chris Lattner 9fa15c3608 ignore structs that wrap vectors in IR, the abstraction shouldn't add penalty.
Before we'd compile the example into something like:

  %coerce.dive2 = getelementptr %struct.v4f32wrapper* %retval, i32 0, i32 0 ; <<4 x float>*> [#uses=1]
  %1 = bitcast <4 x float>* %coerce.dive2 to <2 x double>* ; <<2 x double>*> [#uses=1]
  %2 = load <2 x double>* %1, align 1             ; <<2 x double>> [#uses=1]
  ret <2 x double> %2

Now we produce:

  %coerce.dive2 = getelementptr %struct.v4f32wrapper* %retval, i32 0, i32 0 ; <<4 x float>*> [#uses=1]
  %0 = load <4 x float>* %coerce.dive2, align 1   ; <<4 x float>> [#uses=1]
  ret <4 x float> %0

llvm-svn: 109732
2010-07-29 05:02:29 +00:00
Chris Lattner 4200fe4e50 move the 'pretty 16-byte vector' inferring code up to be shared
with return values, improving stuff that returns __m128 etc.

llvm-svn: 109731
2010-07-29 04:56:46 +00:00
Chris Lattner ce1bd754d8 simplify code by eliminating a premature optimization.
llvm-svn: 109730
2010-07-29 04:51:12 +00:00
Chris Lattner 3a44c7e55d now that we have CGT around, we can start using preferred types
for return values too.  Instead of compiling something like:

struct foo {
  int *X;
  float *Y;
};

struct foo test(struct foo *P) { return *P; }

to:

%1 = type { i64, i64 }

define %1 @test(%struct.foo* %P) nounwind {
entry:
  %retval = alloca %struct.foo, align 8           ; <%struct.foo*> [#uses=2]
  %P.addr = alloca %struct.foo*, align 8          ; <%struct.foo**> [#uses=2]
  store %struct.foo* %P, %struct.foo** %P.addr
  %tmp = load %struct.foo** %P.addr               ; <%struct.foo*> [#uses=1]
  %tmp1 = bitcast %struct.foo* %retval to i8*     ; <i8*> [#uses=1]
  %tmp2 = bitcast %struct.foo* %tmp to i8*        ; <i8*> [#uses=1]
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 16, i32 8, i1 false)
  %0 = bitcast %struct.foo* %retval to %1*        ; <%1*> [#uses=1]
  %1 = load %1* %0, align 1                       ; <%1> [#uses=1]
  ret %1 %1
}

We now get the result more type safe, with:

define %struct.foo @test(%struct.foo* %P) nounwind {
entry:
  %retval = alloca %struct.foo, align 8           ; <%struct.foo*> [#uses=2]
  %P.addr = alloca %struct.foo*, align 8          ; <%struct.foo**> [#uses=2]
  store %struct.foo* %P, %struct.foo** %P.addr
  %tmp = load %struct.foo** %P.addr               ; <%struct.foo*> [#uses=1]
  %tmp1 = bitcast %struct.foo* %retval to i8*     ; <i8*> [#uses=1]
  %tmp2 = bitcast %struct.foo* %tmp to i8*        ; <i8*> [#uses=1]
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 16, i32 8, i1 false)
  %0 = load %struct.foo* %retval                  ; <%struct.foo> [#uses=1]
  ret %struct.foo %0
}

That memcpy is completely terrible, but I don't know how to fix it.

llvm-svn: 109729
2010-07-29 04:46:19 +00:00
Chris Lattner 029c0f1681 sink preferred type stuff lower. It's possible that this might
improve codegen for vaarg or something, because its codepath is
getting preferred types now.

llvm-svn: 109728
2010-07-29 04:41:05 +00:00
Chris Lattner 22326a10a7 dissolve some more complexity: make the x86-64 abi lowering code
compute its own preferred types instead of having CGT compute
them then pass them (circuituously) down into ABIInfo.

llvm-svn: 109726
2010-07-29 02:31:05 +00:00
Chris Lattner c11301c76e simplify Get8ByteTypeAtOffset by making it a member of X86_64ABIInfo
llvm-svn: 109724
2010-07-29 02:20:19 +00:00
Chris Lattner 458b2aaee0 now that ABIInfo depends on CGT, it has trivial access to such
things as TargetData, ASTContext, LLVMContext etc.  Stop passing
them through so many APIs.

llvm-svn: 109723
2010-07-29 02:16:43 +00:00
Chris Lattner 2b03797222 cave in to reality and make ABIInfo depend on CodeGenTypes.
This will simplify a bunch of code, coming up next.

llvm-svn: 109722
2010-07-29 02:01:43 +00:00
Chris Lattner f4ba08aeaf pass argument vectors in a type that corresponds to the user type if
possible.  This improves the example to pass <4 x float> instead of
<2 x double> but we still get awful code, and still don't get the
return value right.

llvm-svn: 109700
2010-07-28 23:47:21 +00:00
Chris Lattner 4b8585ef6a tidy up
llvm-svn: 109699
2010-07-28 23:46:15 +00:00
Devang Patel c7f16ab3e3 Override selected builtin names (e.g. "long int" instead of "long") to match names used by gcc in debug info. This makes gdb testsuite happy.
llvm-svn: 109694
2010-07-28 23:23:29 +00:00
Chris Lattner fa560fedb7 fix some break statements to be formatted more consistently,
remove some now-dead code.

llvm-svn: 109690
2010-07-28 23:12:33 +00:00
Chris Lattner 31faff5d58 use Get8ByteTypeAtOffset for the return value path as well so we
don't get errors similar to PR7714 on the return path.

llvm-svn: 109689
2010-07-28 23:06:14 +00:00
Chris Lattner b22f1c8bf7 refactor the autosizing code, eliminating duplication
and making Get8ByteTypeAtOffset always succeed and documented.

llvm-svn: 109685
2010-07-28 22:44:07 +00:00
Chris Lattner 4c1e484f39 fix PR7714 by not referencing off the end of a struct when passed by value in
x86-64 abi.  This also improves codegen as well.  Some refactoring is needed of
this code.

llvm-svn: 109681
2010-07-28 22:15:08 +00:00
Fariborz Jahanian d5010898ab Fix flags in global block descriptor when
block returns structs. Fies radar 8241648.
Executable test added to llvm test suite.

llvm-svn: 109620
2010-07-28 19:07:18 +00:00
Chris Lattner ff941a666a some cleanups and get alignments correct for various coerce cases.
llvm-svn: 109607
2010-07-28 18:24:28 +00:00
Gabor Greif 79ac9ed7ac we are not supposed to create an improper callsite using a CallInstr; leave a fixme mentioning the simplification when CallSite can clone itself
llvm-svn: 109575
2010-07-28 09:19:33 +00:00
Devang Patel a652fab052 construct debug info for "id" by hand.
Tested by mi1-var-obj.exp in gdb testsuite.

llvm-svn: 109571
2010-07-28 01:33:15 +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
Argyrios Kyrtzidis c0279a9826 Revert r109546, it broke linux build.
llvm-svn: 109550
2010-07-27 22:37:14 +00:00
Argyrios Kyrtzidis 4fac280618 Merge PCHWriterDecl.cpp's isRequiredDecl and CodeGenModule::MayDeferGeneration into a new function,
DeclIsRequiredFunctionOrFileScopedVar.

This function is part of the public CodeGen interface since it's essentially a CodeGen predicate that is also
needed by the PCH mechanism to determine whether a decl needs to be deserialized during PCH loading for codegen purposes.
This fixes current (and avoids future) codegen-from-PCH bugs.

llvm-svn: 109546
2010-07-27 22:01:17 +00:00
Devang Patel 4f6e73b168 Always use current working directory for DW_AT_comp_dir.
llvm-svn: 109535
2010-07-27 20:49:59 +00:00
Devang Patel 6014edd117 Reapply 109303.
llvm-svn: 109507
2010-07-27 15:17:16 +00:00
Fariborz Jahanian 0ebca28f1d 2nd argument of __builtin_expect must be evaluated
if it hs side-effect to matchgcc's behaviour.
Addresses radar 8172109.

llvm-svn: 109467
2010-07-26 23:11:03 +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
Devang Patel 6005082354 Revert 109303.
llvm-svn: 109426
2010-07-26 18:49:27 +00:00
Douglas Gregor b412e174db Remove the vast majority of the Destroy methods from the AST library,
since we aren't going to be calling them ever.

llvm-svn: 109377
2010-07-25 18:17:45 +00:00
John McCall 268b576b72 Mangle enum constant expressions. Fixes rdar://problem/8204122
llvm-svn: 109315
2010-07-24 01:17:35 +00:00
Devang Patel 268ad093a7 Untangle filename/dirname confusion. Store constructed strings on the side. Avoid use of Path.makeAbsolute().
DW_TAG_compile_unit uses two attributes DW_AT_name and DW_AT_comp_dir. Their expected values are:

$ clang foo.c -g
  DW_AT_name - foo.c
  DW_AT_comp_dir - `pwd`

$ clang one/two/foo.c -g
  DW_AT_name - one/two/foo.c
  DW_AT_comp_dir - `pwd`

$ clang /tmp/one/foo.c -g
  DW_AT_name - /tmp/one/foo.c
  DW_AT_comp_dir - empty

llvm-svn: 109303
2010-07-24 00:59:16 +00:00
John McCall 2ca705eb13 Support catching Objective C pointers in C++ under the non-fragile NeXT runtime.
Diagnose attempts to do this under the GNU or fragile NeXT runtimes.

llvm-svn: 109298
2010-07-24 00:37:23 +00:00
Fariborz Jahanian 72cdffa401 Return type of a setter call caused by
use of property-dot syntax using 'super' as receiver
is 'void'. This fixes a bug in generating correct
API for setter call. Fixes radar 8203426.

llvm-svn: 109297
2010-07-24 00:34:08 +00:00
Devang Patel cb9fe9ec16 Revert r109263.
llvm-svn: 109284
2010-07-23 23:04:28 +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
Devang Patel 28f167699a There is no need to use separate dir name for AT_comp_dir attribute. Using absolute path for filename allows clients to query complete file location info from gdb breakpoints. Save constructed full file name.
llvm-svn: 109263
2010-07-23 20:38:37 +00:00
Douglas Gregor 5cc2c8b9c3 Vectors are not integer types, so the type system should not classify
them as such. Type::is(Signed|Unsigned|)IntegerType() now return false
for vector types, and new functions
has(Signed|Unsigned|)IntegerRepresentation() cover integer types and
vector-of-integer types. This fixes a bunch of latent bugs.

Patch from Anton Yartsev!

llvm-svn: 109229
2010-07-23 15:58:24 +00:00
Devang Patel 0884a60eb5 Keep track of artificial scopes introduced by line directives. For example,
#line 41 "bar.c"
  dummy (1, i);
#line 24 "bar.h"
  i = f2 (i);
#line 44 "bar.c"

This is tested by step-line.exp in gdb testsuite.

llvm-svn: 109189
2010-07-22 22:29:16 +00:00
John McCall 775f9f9919 Turn off EH cleanups for __block variables; they caused some internal buildbot
failures.  There's a radar tracking this.

llvm-svn: 109170
2010-07-22 21:25:44 +00:00
Fariborz Jahanian 6e7e8cc19d atch for implementation of objective-c's -Wselector
warning flag in clang. Little more to do
for a PCH issue. Radar 6507158.

llvm-svn: 109129
2010-07-22 18:24:20 +00:00
Devang Patel 222f4be834 ObjCId is special "struct objc_object". Make this explicit in debug info.
This is tested by objc-rbreak.exp in gdb testsuite.

llvm-svn: 109050
2010-07-21 22:41:25 +00:00
Devang Patel 65497583b5 Fix regression caused by r108911.
Do not override known debug loc with unknown debug loc.
This is tested by sections.exp in gdb testsuite.

llvm-svn: 109022
2010-07-21 18:08:50 +00:00
David Chisnall 4715d161c0 Don't crash when sending a message inside a block with the non-fragile ABI (GNU runtime).
llvm-svn: 109012
2010-07-21 15:28:28 +00:00
David Chisnall 7fa204edc7 Mark the load after calling objc_msg_lookup_sender() so that it doesn't get optimised away (GNU runtime).
llvm-svn: 109010
2010-07-21 12:55:25 +00:00
John McCall cda666ccd8 Rename LazyCleanup -> Cleanup. No functionality change for these last three
commits.

llvm-svn: 109000
2010-07-21 07:22:38 +00:00
John McCall 20141f2d8c Rip out EHCleanupScope.
llvm-svn: 108999
2010-07-21 07:11:21 +00:00
John McCall 7535ee0352 Kill the CleanupBlock API.
llvm-svn: 108998
2010-07-21 07:04:01 +00:00
John McCall 65bea08879 Switch the fragile-ABI @finally/@synchronized cleanup over to using a lazy
cleanup.

llvm-svn: 108997
2010-07-21 06:59:36 +00:00
John McCall 0d42a41a63 Code simplification.
llvm-svn: 108996
2010-07-21 06:45:54 +00:00
John McCall fb442ae7b9 Switch the main possibly-conditional temporary cleanup over to being lazy.
llvm-svn: 108995
2010-07-21 06:44:28 +00:00
John McCall 8680f87d99 Switch the destructor for a temporary arising from a reference binding over to
using a lazy cleanup.

llvm-svn: 108994
2010-07-21 06:29:51 +00:00
John McCall da650e091f Switch the __cxa_guard_abort cleanup to being a lazy cleanup.
llvm-svn: 108993
2010-07-21 06:20:50 +00:00
John McCall a464ff9d15 Switch some random local-decl cleanups over to using lazy cleanups. Turn on
the block-release unwind cleanup:  we're never going to test it if we don't turn
it on.

llvm-svn: 108992
2010-07-21 06:13:08 +00:00
John McCall 906da4bb52 Switch finally cleanups over to being lazy cleanups. We get basically nothing
from the laziness features here except better block ordering, but it removes yet
another CleanupBlock use.

llvm-svn: 108990
2010-07-21 05:47:49 +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 53cad2ef04 Change PushDestructorCleanup to use lazy cleanups.
llvm-svn: 108979
2010-07-21 01:41:18 +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 1e67040fb7 Convert the end-catch call for finally blocks to a lazy cleanup. This kills off
the last of the shared-code cleanups.

llvm-svn: 108975
2010-07-21 00:52:03 +00:00
John McCall c20acd31f7 Convert the ObjC @synchronized cleanups to laziness. This is not actually
a big deal, except that I want to eliminate the shared-code EH cleanups
in preparation for a significant algorithmic fix.

llvm-svn: 108973
2010-07-21 00:41:47 +00:00
John McCall 8f51041184 Add a little helper method which will be useful soon.
llvm-svn: 108972
2010-07-21 00:40:03 +00:00
Devang Patel 0043977f09 Remove unintended code that was checked in as part of r108916.
llvm-svn: 108951
2010-07-20 22:32:37 +00:00
Devang Patel 11a42a4655 Remove unused argument.
llvm-svn: 108946
2010-07-20 22:20:10 +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 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
Fariborz Jahanian 217af240b5 Adopt objc_assign_threadlocal() for __thread variables of GC types.
Implements radar 8203301.

llvm-svn: 108917
2010-07-20 20:30:03 +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
Dan Gohman 481e40c681 Use getDebugLoc and setDebugLoc instead of getDbgMetadata and setDbgMetadata,
avoiding MDNode overhead.

llvm-svn: 108911
2010-07-20 20:13:52 +00:00
Chris Lattner b7a95cf165 delete a loop that just generates dead code. In an example
like this:

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

the loop generates two dead mul instructions:

  %tmp = load i64* %N.addr                        ; <i64> [#uses=2]
  %0 = mul i64 %tmp, 7056                         ; <i64> [#uses=1]
  %1 = mul i64 %tmp, 42                           ; <i64> [#uses=1]
  %2 = mul i64 %1, 42                             ; <i64> [#uses=0]
  %call = call noalias i8* @_Znam(i64 %0)         ; <i8*> [#uses=1]

The scale of these multiplies is already handled by the typesize stuff.

llvm-svn: 108884
2010-07-20 18:49:33 +00:00
Chris Lattner cb46bdc34f remove the special case for constant array sizes from
EmitCXXNewAllocSize.  This code uses IRBuilder, which does
constant folding already.

llvm-svn: 108882
2010-07-20 18:45:57 +00:00
Jim Grosbach 71d963e954 Re-apply fixed version of 108749, correctly conditionalizing the new sections on
ObjC ABI version 2 this time.

llvm-svn: 108847
2010-07-20 16:20:26 +00:00
Sebastian Redl c57d34bc35 Update ImplicitCastExpr to be able to represent an XValue.
llvm-svn: 108807
2010-07-20 04:20:21 +00:00
Stuart Hastings 7d7bc561bf Correct line info for declarations/definitions. Radar 8063111.
llvm-svn: 108785
2010-07-19 23:56:31 +00:00
Jim Grosbach 50c63168ed Temporarily revert. Some odd internal breakage is likely related.
llvm-svn: 108764
2010-07-19 22:43:34 +00:00
Jim Grosbach f699594de8 Put ObjC method names, method types and class names in separate string literal
sections. rdar://8207705

llvm-svn: 108749
2010-07-19 20:54:43 +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
Chandler Carruth bc8cab16c5 Improve the representation of the atomic builtins in a few ways. First, we make
their call expressions synthetically have the "deduced" types based on their
first argument. We only insert conversions in the AST for arguments whose
values require conversion to match the value type expected. This keeps PR7600
closed by maintaining the return type, but avoids assertions due to unexpected
implicit casts making the type unsigned (test case added from Daniel).

The magic is moved into the codegen for the atomic builtin which inserts the
casts as needed at the IR level to raise the type to an integer suitable for
the LLVM intrinsic. This shouldn't cause any real change in functionality, but
now we can make the builtin be more truly polymorphic.

llvm-svn: 108638
2010-07-18 07:23:17 +00:00
Chris Lattner ad4f38b1a9 BUILD_ARCHIVE is the default for libraries, no need to set it.
llvm-svn: 108633
2010-07-18 00:14:47 +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 36ea3723c0 The GNU-runtime ObjC personality function doesn't let us rethrow with URR for
multiple reasons.  Rethrow with _objc_exception_throw instead.  Fixes PR7656.

llvm-svn: 108595
2010-07-17 00:43:08 +00:00
Eli Friedman eca55afea3 Fix for PR3800: make sure not to evaluate the expression for a read-write
asm operand twice.

llvm-svn: 108489
2010-07-16 00:55:21 +00:00
Daniel Dunbar 3348e2d175 IRgen: Support user defined attributes on block runtime functions.
- This issue here is that /usr/include/Blocks.h wants to define some of the
   block runtime globals as weak, depending on the target. This doesn't work in
   Clang because we aren't using the AST decl for these globals.

 - The fix is a pretty gross hack which just watches all the decls for the
   specific blocks globals we need to know about; if we see one we use it,
   otherwise we use the hand coded type.

   In time, I would like to clean this up by changing IRgen to ask Sema/AST for
   the decl, which would then be lazily loaded from the builtin table if
   necessary. This could be used in a whole host of places in IRgen and would
   get rid of a lot of grotty hand coding of LLVM IR; however, we need some
   extra Sema support for this as well as support for builtin global variables.

llvm-svn: 108482
2010-07-16 00:00:19 +00:00
Daniel Dunbar 900546d2e3 IRgen: Move blocks runtime interfaces to CodeGenModule.
llvm-svn: 108481
2010-07-16 00:00:15 +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
Devang Patel 8fd6499a97 Set "optimization is ON" and supply other optional parameters. This helps codegenerator preserve info in case the symbol is deleted.
llvm-svn: 108471
2010-07-15 23:09:46 +00:00
Douglas Gregor 8997690ff1 Don't suppress the emission of available_externally functions marked
with always_inline attribute. Thanks to Howard for the tip.

llvm-svn: 108469
2010-07-15 22:58:18 +00:00
Devang Patel b3026df9fa Mark implementation generated methods as artificial.
Tested by namespace.exp and virtfunc.exp from gdb testsuite.

llvm-svn: 108468
2010-07-15 22:57:00 +00:00
John McCall ec624b2d19 After some discussion, the ABI list settled on a much more sensible mangling
for string literals.

llvm-svn: 108464
2010-07-15 21:53:03 +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 6744cbda03 Spell isPRValue() properly.
llvm-svn: 108433
2010-07-15 18:12:28 +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 cee039093a CK_BitCast is not an lvalue bitcast any longer
llvm-svn: 108428
2010-07-15 16:39:55 +00:00
Daniel Dunbar 1d14dd1dc6 CodeGen: Tweak ABI handling for Minix, patch by Kees van Reeuwijk!
llvm-svn: 108423
2010-07-15 15:02:28 +00:00
Daniel Dunbar 6f2e839693 CodeGen/ObjC/NeXT: Fix Obj-C message send to match llvm-gcc when choosing
whether to use objc_msgSend_fpret; the choice is target dependent, not Obj-C ABI
dependent.
 - <rdar://problem/8139758> arm objc _objc_msgSend_fpret bug

llvm-svn: 108379
2010-07-14 23:39:36 +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
John McCall afe20780ee Remove a few mangling FIXMEs:
- TSTs whose template is a template template parameter already work
 - we don't provide an imaginary type, so we can't mangle one
 - we don't need a generic FIXME for vendor type qualifiers

llvm-svn: 108317
2010-07-14 04:38:21 +00:00
John McCall 05ddbb80d2 Implement the standard mangling for array-subscript expressions, and implement
the current proposals from David Vandervoorde for new, delete, throw, typeid,
imaginary literals, string literals, and null literals.

llvm-svn: 108315
2010-07-14 04:20:34 +00:00
John McCall 11e577b99a Work around an obnoxious GCC warning by changing semantics in a hopefully-
harmless way.

llvm-svn: 108295
2010-07-13 23:19:49 +00:00
Douglas Gregor 51954276cc Introduce a new cast kind for an "lvalue bitcast", which handles
reinterpret_casts (possibly indirectly via C-style/functional casts)
on values, e.g., 

  int i;
  reinterpret_cast<short&>(i);

The IR generated for this is essentially the same as for

  *reinterpret_cast<short*>(&i).

Fixes PR6437, PR7593, and PR7344. 

llvm-svn: 108294
2010-07-13 23:17:26 +00:00
John McCall 5c0e69ef0e Switch the __cxa_rethrow cleanup to be lazy.
llvm-svn: 108288
2010-07-13 22:24:23 +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
Douglas Gregor a8a089bfd5 Whenever we're creating an expression that is typically an rvalue
(e.g., a call, cast, etc.), immediately adjust the expression's type
to strip cv-qualifiers off of all non-class types (in C++) or all
types (in C). This effectively extends my previous fix for PR7463,
which was restricted to calls, to other kinds of expressions within
similar characteristics. I've audited every use of
getNonReferenceType() in the code base, switching to the newly-renamed
getNonLValueExprType() where necessary. 

Big thanks to Eli for pointing out just how incomplete my original fix
for PR7463 actually was. We've been handling cv-qualifiers on rvalues
wrong for a very, very long time. Fixes PR7463.

llvm-svn: 108253
2010-07-13 18:40:04 +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
Devang Patel 0a34e31d81 const qualify debug info for "this" for const methods.
llvm-svn: 108220
2010-07-13 00:24:30 +00:00
Devang Patel 0aabb1200f While collecting members for a class, always create delcaration entry for methods. Debug info for method definition will be generated while generating code for method body.
Tested by classes.exp in gdb testsuite.

llvm-svn: 108205
2010-07-12 22:54:41 +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
Devang Patel 8f3f76f991 Handle forward declarations properly in debug info.
Patch by Alexander Kabaev.
PR 7595.

llvm-svn: 107900
2010-07-08 19:56:29 +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
Chris Lattner cb7696cf35 fix the clang side of PR7437: EmitAggregateCopy
was not producing a memcpy with the right address
spaces because of two places in it doing casts of
the arguments to i8, one of which that didn't
preserve the address space.

There is also an optimizer bug here.

llvm-svn: 107842
2010-07-08 00:07:45 +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 6df2b8c3ac Rename CXXZeroInitValueExpr to CXXScalarValueInitExpr, to reflect its
newly-narrowed scope. No functionality change.

llvm-svn: 107828
2010-07-07 22:43:56 +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
Chris Lattner 3e2ee147d0 add driver support for minix, patch by Kees van Reeuwijk
from PR7583

llvm-svn: 107788
2010-07-07 16:01:42 +00:00
Argyrios Kyrtzidis 54fcbc7345 getBody() -> hasBody()
llvm-svn: 107773
2010-07-07 12:24:18 +00:00
Argyrios Kyrtzidis 36ea322579 Introduce Decl::hasBody() and FunctionDecl::hasBody() and use them instead of getBody() when we are just checking the existence of a body, to avoid de-serialization of the body from PCH.
Makes de-serialization of the function body even more "lazier".

llvm-svn: 107768
2010-07-07 11:31:19 +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 09ae03299a Provide a hook for the benefit of clients using clang IR gen as a subroutine:
emit metadata associating allocas and global values with a Decl*.  This feature
is controlled by an option that (intentionally) cannot be enabled on the command
line.

To use this feature, simply set
  CodeGenOptions.EmitDeclMetadata = true;
and then interpret the completely underspecified metadata. :)

llvm-svn: 107739
2010-07-06 23:57:41 +00:00
John McCall 189223e222 Make CGBuilderTy a typedef again; its functionality has been rolled back
into IRBuilder.

llvm-svn: 107687
2010-07-06 18:43:48 +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 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
Chris Lattner ceddafb846 Generate fewer first class aggregate values for other
coerce cases (e.g. {double,int}) which avoids fastisel
bailing out at -O0.

llvm-svn: 107628
2010-07-05 20:41:41 +00:00
Chris Lattner c401de9998 in the "coerce" case, the ABI handling code ends up making the
alloca for an argument.  Make sure the argument gets the proper
decl alignment, which may be different than the type alignment.

This fixes PR7567

llvm-svn: 107627
2010-07-05 20:21:00 +00:00
Chris Lattner 53b479ff6a fix PR7564 a cast where the bitfield struct init code
wasn't handling array padding elements right.

llvm-svn: 107621
2010-07-05 18:03:30 +00:00