Commit Graph

1338 Commits

Author SHA1 Message Date
Eli Friedman 9d155aa061 Fix typo in test.
llvm-svn: 136251
2011-07-27 20:09:36 +00:00
Eli Friedman b2f3695e9a Make CodeGen for array delete involving incomplete class work without crashing. Should fix regression on g++.dg/init/delete1.C.
llvm-svn: 136241
2011-07-27 18:54:57 +00:00
Douglas Gregor 8771796493 Disable the optimization that skips emission of complete, non-virtual
destructors of abstract classes. It's undefined behavior to actually
call the destructor (e.g., via delete), but the presence of code that
calls this destructor doesn't make the program
ill-formed. Fixes <rdar://problem/9819242>.

llvm-svn: 136180
2011-07-26 23:18:30 +00:00
Chris Lattner e135b089d8 fix PR10384: C++ allows external arrays of incomplete type as well.
Many thanks to Eli for reducing this great testcase.

llvm-svn: 135752
2011-07-22 06:27:26 +00:00
Chris Lattner 43cae02689 rename test.
llvm-svn: 135751
2011-07-22 06:26:12 +00:00
Chris Lattner 71bd0c3263 fix PR10395 - array decay can produce an interesting type when
decaying an array of incomplete type (which has type [0 x i8]*) to a
normal pointer (which has incompletetype*).

llvm-svn: 135565
2011-07-20 04:31:01 +00:00
Bruno Cardoso Lopes 98154a76fd Reapply r134946 with fixes. Tested on Benjamin testcase and other test-suite failures.
llvm-svn: 135091
2011-07-13 21:58:55 +00:00
John McCall 928a25714e Enforce access control for the destructor in a new[] expression and mark
it as used.  Otherwise, we can fail to instantiate or validate the destructor,
which can lead to crashes in IR gen like PR10351.

llvm-svn: 135073
2011-07-13 20:12:57 +00:00
John McCall 97eab0a271 Okay, that rule about zero-length arrays applies to destroying
them, too.

llvm-svn: 135038
2011-07-13 08:09:46 +00:00
John McCall 6549b31fe9 Arrays are permitted to be zero-length in some situations.
llvm-svn: 135036
2011-07-13 07:37:11 +00:00
John McCall f677a8e99e Convert the standard default-construction loops to use phis and
partial destruction.

llvm-svn: 135033
2011-07-13 06:10:41 +00:00
Douglas Gregor d29fde248e Eliminate an incomplete/incorrect attempt to provide support for C++0x
unrestricted unions, which ended up attempting to initialize objects
in a union (which CodeGen isn't prepared for). Fixes PR9683.

llvm-svn: 135027
2011-07-13 02:14:02 +00:00
John McCall ca2c56f20b Switch delete[] IR-generation over to the destroy framework,
which implicitly makes it EH-safe as well.

llvm-svn: 135025
2011-07-13 01:41:37 +00:00
Douglas Gregor 1c2e20d73d When compiling ::delete for a class with a virtual destructor, call
the complete destructor and then invoke the global delete
operator. Previously, we would invoke the deleting destructor, which
calls the wrong delete operator. Fixes PR10341.

llvm-svn: 135021
2011-07-13 00:54:47 +00:00
Douglas Gregor 2207ec273a Improve name mangling for instantiation-dependent types that are not
dependent. This covers an odd class of types such as

  int (&)[sizeof(sizeof(T() + T()))];

which involve template parameters but, because of some trick typically
involving a form of expression that is never type-dependent, resolve
down to a non-dependent type. Such types need to be mangled
essentially as they were written in the source code (involving
template parameters), rather than via their canonical type.

In general, instantiation-dependent types should be mangled as
they were written in the source. However, since we can't do that now
without non-trivial refactoring of the AST (see the new FIXME), I've
gone for this partial solution: only use the as-written-in-the-source
mangling for these strange types that are instantiation-dependent but
not dependent. This provides better compatibility with previous
incarnations of Clang and with GCC. In the future, we'd like to get
this right.

Fixes <rdar://problem/9663282>.

llvm-svn: 134984
2011-07-12 15:18:55 +00:00
Douglas Gregor e5802234f9 Implement name mangling for sizeof...(function parameter pack).
llvm-svn: 134974
2011-07-12 07:03:48 +00:00
Chris Lattner 3f32d69699 Fix a problem Eli ran into where we now reject incomplete arrays of
uncompleted struct types.  We now do what llvm-gcc does and compile
them into [i8 x 0].  If the type is later completed, we make sure that
it is appropriately cast.

We compile the terrible example to something like this now:

%struct.A = type { i32, i32, i32 }

@g = external global [0 x i8]

define void @_Z1fv() nounwind {
entry:
  call void @_Z3fooP1A(%struct.A* bitcast ([0 x i8]* @g to %struct.A*))
  ret void
}

declare void @_Z3fooP1A(%struct.A*)

define %struct.A* @_Z2f2v() nounwind {
entry:
  ret %struct.A* getelementptr inbounds ([0 x %struct.A]* bitcast ([0 x i8]* @g to [0 x %struct.A]*), i32 0, i64 1)
}

llvm-svn: 134972
2011-07-12 06:52:18 +00:00
Chris Lattner 73e3004e75 fix an unintended behavior change in the type system rewrite, which caused us to compile
stuff like this:

typedef struct {
 int x, y, z; 
} foo_t;

foo_t g;

into:
%"struct.<anonymous>" = type { i32, i32, i32 }
we now get:
%struct.foo_t = type { i32, i32, i32 }

This doesn't change the behavior of the compiler, but makes the IR much easier to read.

llvm-svn: 134969
2011-07-12 05:53:08 +00:00
Douglas Gregor 1cf9dd21dc Mangle dependent template names of unknown arity
llvm-svn: 134967
2011-07-12 05:06:05 +00:00
Douglas Gregor 6ef06cc48d Implement the Itanium C++ ABI's mangling rule for
non-instantiation-dependent sizeof and alignof expressions.

llvm-svn: 134963
2011-07-12 04:47:20 +00:00
Douglas Gregor 2e12550e37 Allow us to compute linkage et al for instantiation-dependent types.
llvm-svn: 134932
2011-07-11 22:38:07 +00:00
John McCall 3b935d33a1 Emit partial destruction of structs with initializer lists.
llvm-svn: 134913
2011-07-11 19:35:02 +00:00
John McCall 178360e1cd Fix a lot of problems with the partial destruction of arrays:
- an off-by-one error in emission of irregular array limits for
   InitListExprs
 - use an EH partial-destruction cleanup within the normal
   array-destruction cleanup
 - get the branch destinations right for the empty check
Also some refactoring which unfortunately obscures these changes.

llvm-svn: 134890
2011-07-11 08:38:19 +00:00
Chris Lattner 709af79e0a relax this test a bit to hopefully work with VC++
llvm-svn: 134870
2011-07-10 14:52:52 +00:00
Chris Lattner 18ca0475d7 implement a nice new optimization: CodeGenTypes::UpdateCompletedType
is called whenever a tag type is completed.  We previously used that
as the sign to layout the codegen representation for the tag type,
which worked but meant that we laid out *every* completed type, whether
it was used or not.

Now we just lay out the type if we've already seen it somehow else.
This means that we lay out types we've used but haven't seen a body
for, but we don't lay out tons of stuff that noone cares about.

llvm-svn: 134866
2011-07-10 06:03:22 +00:00
Chris Lattner 117b724b59 keep track of whether being in a RS_StructPointer state
caused us to skip layout out a function accurately.  If
so, flush the type cache for both the function and struct
case to ensure that any pointers to the functions get
recomputed.  This is overconservative, but with this patch
clang can build itself again.

llvm-svn: 134863
2011-07-10 05:39:13 +00:00
Chris Lattner d1f1158203 Fix the clang bootstrap and Jay's testcase from llvm-dev by being completely
conservative when converting a functiontype to IR when in a "pointer within
a struct" context.  This has the unfortunate sideeffect of compiling all 
function pointers inside of structs into "{}*" which, though correct, is
ugly.  This has the positive side effect of being correct, and it is pretty
straight-forward to improve on this.

llvm-svn: 134861
2011-07-10 03:47:27 +00:00
Chris Lattner f5926b460b fix this on 32-bit hosts.
llvm-svn: 134840
2011-07-09 18:33:01 +00:00
Chris Lattner a5f58b05e8 clang side to match the LLVM IR type system rewrite patch.
llvm-svn: 134831
2011-07-09 17:41:47 +00:00
John McCall 82fe67bb82 A number of array-related IR-gen cleanups.
- Emit default-initialization of arrays that were partially initialized
    with initializer lists with a loop, rather than emitting the default
    initializer N times;
  - support destroying VLAs of non-trivial type, although this is not
    yet exposed to users; and
  - support the partial destruction of arrays initialized with
    initializer lists when an initializer throws an exception.

llvm-svn: 134784
2011-07-09 01:37:26 +00:00
Rafael Espindola ba195cff81 Use attributes from the definition (if available) when
instantiating functions.

Fixes PR10272.

llvm-svn: 134491
2011-07-06 15:46:09 +00:00
John McCall 542e7c6f64 When tree-transforming an expression sequence, always flag expanded
variadic argument pack expansions as having changed, rather than doing
it for each changed expansion, which leaves out zero-argument packs
with catastrophic consequences.

Fixes PR10260.

llvm-svn: 134483
2011-07-06 07:30:07 +00:00
Douglas Gregor fa918f69f6 Emit guard variables for any weak global that has a run-time
initializer. Previously, we only used guard variables for weak static
data members. Fixes <rdar://problem/9692249>.

llvm-svn: 134266
2011-07-01 21:54:36 +00:00
Douglas Gregor c063ac20d8 Fix testcase
llvm-svn: 134262
2011-07-01 21:19:15 +00:00
Douglas Gregor 82e1af20cb Don't zero-initialize default-initialized local variables that have
trivial default constructors. This generated-code regression was
caused by r131796, which had simplified the handling of default
initialization in Sema. Fixes <rdar://problem/9694300>.

llvm-svn: 134260
2011-07-01 21:08:19 +00:00
John McCall 2de1c33f77 Just mangle substituted template parameter types as unresolved types.
This is kindof questionable but seems to do more-or-less the right thing.
This is not a particularly friendly part of the ABI.

llvm-svn: 134227
2011-07-01 02:19:08 +00:00
Douglas Gregor 678d76c026 Introduce the notion of instantiation dependence into Clang's AST. A
type/expression/template argument/etc. is instantiation-dependent if
it somehow involves a template parameter, even if it doesn't meet the
requirements for the more common kinds of dependence (dependent type,
type-dependent expression, value-dependent expression).

When we see an instantiation-dependent type, we know we always need to
perform substitution into that instantiation-dependent type. This
keeps us from short-circuiting evaluation in places where we
shouldn't, and lets us properly implement C++0x [temp.type]p2.

In theory, this would also allow us to properly mangle
instantiation-dependent-but-not-dependent decltype types per the
Itanium C++ ABI, but we aren't quite there because we still mangle
based on the canonical type in cases like, e.g.,

  template<unsigned> struct A { };
  template<typename T>
    void f(A<sizeof(sizeof(decltype(T() + T())))>) { }
  template void f<int>(A<sizeof(sizeof(int))>);

and therefore get the wrong answer.

llvm-svn: 134225
2011-07-01 01:22:09 +00:00
John McCall 3a4a4c5228 Change the mangling of enclosing template template parameters
that serve as the base template name of an unresolved-name to
be mangled as a substitution.

llvm-svn: 134213
2011-07-01 00:04:39 +00:00
Eli Friedman 4774b7e456 We don't pass classes with a copy-constructor or destructor byval, so the address takes up an integer register (if one is available). Make sure the x86-64 ABI implementation takes that into account properly.
The fixed implementation is compatible with the implementation both gcc and llvm-gcc use.

rdar://9686430 . (This is the issue that was reported in the thread "[LLVMdev] Segfault calling LLVM libs from a clang-compiled executable".)

llvm-svn: 134059
2011-06-29 07:04:55 +00:00
John McCall 15547bbdd1 Be more thorough about mangling unresolved types.
llvm-svn: 134011
2011-06-28 16:49:23 +00:00
John McCall b8c604abfd Don't factor in visibility for templates and template arguments
for explicit specializations with their own explicit visibility.

llvm-svn: 133958
2011-06-27 23:06:04 +00:00
Douglas Gregor 3bdcff5866 When instantiating a C++ "new" expression, don't fake source locations
for the '(' and ')' around the initializer unless we actually have an
initializer. Fixes PR10197, an issue where we were value-initializing
rather than default-initializing.

llvm-svn: 133913
2011-06-27 16:55:54 +00:00
John McCall 77527a8e65 Mark the multiply which occurs as part of performing pointer
arithmetic on a VLA as 'nsw', per discussion with djg, and
implement pointer arithmetic (other than array accesses) and
pointer subtraction for VLA types.

llvm-svn: 133855
2011-06-25 01:32:37 +00:00
John McCall 8766a83a2f Two more test cases which have been long uncommitted.
llvm-svn: 133842
2011-06-24 23:30:52 +00:00
John McCall 23c29fea92 Change the IR-generation of VLAs so that we capture bounds,
not sizes;  so that we use well-typed allocas;  and so that we
properly recurse through the full set of variably-modified types.

llvm-svn: 133827
2011-06-24 21:55:10 +00:00
John McCall 575fda19b3 Fix the mangling of dependent-scope decl ref expressions so that they
use the unresolved-name production correctly.

llvm-svn: 133554
2011-06-21 22:12:46 +00:00
Douglas Gregor fe31481f68 Introduce a new AST node describing reference binding to temporaries.
MaterializeTemporaryExpr captures a reference binding to a temporary
value, making explicit that the temporary value (a prvalue) needs to
be materialized into memory so that its address can be used. The
intended AST invariant here is that a reference will always bind to a
glvalue, and MaterializeTemporaryExpr will be used to convert prvalues
into glvalues for that binding to happen. For example, given

  const int& r = 1.0;

The initializer of "r" will be a MaterializeTemporaryExpr whose
subexpression is an implicit conversion from the double literal "1.0"
to an integer value. 

IR generation benefits most from this new node, since it was
previously guessing (badly) when to materialize temporaries for the
purposes of reference binding. There are likely more refactoring and
cleanups we could perform there, but the introduction of
MaterializeTemporaryExpr fixes PR9565, a case where IR generation
would effectively bind a const reference directly to a bitfield in a
struct. Addresses <rdar://problem/9552231>.

llvm-svn: 133521
2011-06-21 17:03:29 +00:00
Chris Lattner e64d7ba153 Update to match mainline ConstantStruct::get API change. Also, use
ConvertType on InitListExprs as they are being converted.  This is
needed for a forthcoming patch, and improves the IR generated anyway
(see additional type names in testcases). 

This patch also converts a bunch of std::vector's in CGObjCMac to use
C arrays.  There are a ton more that should be converted as well.

llvm-svn: 133413
2011-06-20 04:01:35 +00:00
John McCall 5aa5259f5e Perform an acquire memory barrier on the fast path of a thread-safe
static initializer check, as required by the Itanium ABI.

llvm-svn: 133250
2011-06-17 07:33:57 +00:00
Douglas Gregor 9b71f0cfac Implement proper support for generating code for compound literals in
C++, which means:
  - binding the temporary as needed in Sema, so that we generate the
  appropriate call to the destructor, and
  - emitting the compound literal into the appropriate location for
  the aggregate, rather than trying to emit it as a temporary and
  memcpy() it.

Fixes PR10138 / <rdar://problem/9615901>.

llvm-svn: 133235
2011-06-17 04:59:12 +00:00