Commit Graph

485 Commits

Author SHA1 Message Date
Anders Carlsson 9ff22483fd Add types and functions related to exceptions.
llvm-svn: 55984
2008-09-09 10:10:21 +00:00
Anders Carlsson 1963b0c38f Move handling of @try and @throw to the runtime class.
llvm-svn: 55983
2008-09-09 10:04:29 +00:00
Daniel Dunbar 41cf9dedc6 Change CodeGen to emit calls using (RValue,Type) list:
- Add CodeGenFunction::EmitAnyExprToTemp
   o Like EmitAnyExpr, but emits aggregates to a temporary location if
     none is available. Seems like this should be simpler (even aside
     from using first class aggregates).

 - Killed CodeGenFunction::EmitCallArg (just append the pair)

 - Conversion of RValues to actual call arguments is now isolated in
   CodeGenFunction::EmitCall.

llvm-svn: 55970
2008-09-09 01:06:48 +00:00
Daniel Dunbar 0beedc1684 Fix a number of issues w.r.t. emission of global for functions and
aliases.
 - Attributes specific to a definition are only set when the
   definition is seen.
 - Alias generation is delayed until the end of the module; necessary
   since the alias may reference forward.
 - Fixes: PR2743, <rdr://6140807&6094512>
 - Improves: <rdr://6095112> (added XFAIL)

Also, print module on verification failures.

llvm-svn: 55966
2008-09-08 23:44:31 +00:00
Daniel Dunbar 3d7c90b8ec Refactor parameter attribute handling:
- Add CGCall.h for dealing with ABI issues related to calls.
  - Add CGFunctionInfo and CGCallInfo for capturing ABI relevant
    information about functions and calls.
  - Isolate LLVM parameter attribute handling inside CGCall.cpp

llvm-svn: 55963
2008-09-08 21:33:45 +00:00
Daniel Dunbar a46348c51b Key LLVM types for TagDecl's off of the clang Type, since there is now
a many-to-one relationship between TagDecl's and types.

llvm-svn: 55870
2008-09-06 02:26:43 +00:00
Ted Kremenek 2147570258 Change struct forward declarations and definitions to use unique RecordDecls, as opposed to creating a single RecordDecl and reusing it.
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).

The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.

- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
  addition of DeclGroups.

Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
  referenced by the AST.  For example:

    typedef struct { ... } x;  

  The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
  refer to it.  This will be solved with DeclGroups.
  
- This patch also (temporarily) breaks CodeGen.  More below.

High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it.  When
  a struct/union/class is first referenced, a RecordType and RecordDecl are
  created for it, and the RecordType refers to that RecordDecl.  Later, if
  a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
  updated to point to the RecordDecl that defines the struct/union/class.

- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
  TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
  enum/struct/class/union. This is useful from going from a RecordDecl* that
  defines a forward declaration to the RecordDecl* that provides the actual
  definition. Note that this also works for EnumDecls, except that in this case
  there is no distinction between forward declarations and definitions (yet).

- Clients should no longer assume that 'isDefinition()' returns true from a
  RecordDecl if the corresponding struct/union/class has been defined.
  isDefinition() only returns true if a particular RecordDecl is the defining
  Decl. Use 'getDefinition()' instead to determine if a struct has been defined.

- The main changes to Sema happen in ActOnTag. To make the changes more
  incremental, I split off the processing of enums and structs et al into two
  code paths. Enums use the original code path (which is in ActOnTag) and
  structs use the ActOnTagStruct. Eventually the two code paths will be merged,
  but the idea was to preserve the original logic both for comparison and not to
  change the logic for both enums and structs all at once.

- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
  that correspond to the same type simply have a pointer to that type. If we
  need to figure out what are all the RecordDecls for a given type we can build
  a backmap.

- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
  changes to RecordDecl. For some reason 'svn' marks the entire file as changed.

Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
  RecordType*. This was true before because we only created one RecordDecl* for
  a given RecordType*, but it is no longer true. I believe this shouldn't be too
  hard to change, but the patch was big enough as it is.
  
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).  

llvm-svn: 55839
2008-09-05 17:16:31 +00:00
Ted Kremenek 47923c7e59 Remove "NextDecl" from RecordDecl. This change touches many files that where RecordDecl or CXXRecordDecl was constructed, always with an argument of 'NULL' for the previous declaration.
The motivation behind this change is that chaining the RecordDecls is simply unnecessary.  Once we create multiple RecordDecls for the same struct/union/class, clients that care about all the declarations of the same struct can build a back map by seeing which Decls refer to the same RecordType.

llvm-svn: 55821
2008-09-05 01:34:33 +00:00
Daniel Dunbar 2ffee610da Set sext/zext on function result.
- <rdar://problem/6156739>

llvm-svn: 55815
2008-09-05 00:57:45 +00:00
Daniel Dunbar 449a339ffd Set function attributes (sext, zext, etc.) on Objective-C methods.
llvm-svn: 55812
2008-09-04 23:41:35 +00:00
Daniel Dunbar 56b936ba32 Fix infinite loop in for ... in code generation.
- Patch via Thomas Clement, thanks!

llvm-svn: 55804
2008-09-04 21:54:37 +00:00
Daniel Dunbar 7050c55415 NeXT: Emit lazy reference to Protocol class for forward protocol
references (to match gcc).

llvm-svn: 55760
2008-09-04 04:33:15 +00:00
Daniel Dunbar f2cf6d16e6 Avoid superfluous errors regarding variable-length arrays (casts).
llvm-svn: 55759
2008-09-04 03:43:08 +00:00
Daniel Dunbar 8cde00a510 Implement codegen of aggregates as lvalues in binary expressions,
e.g. "(a = b).somefield".

llvm-svn: 55758
2008-09-04 03:20:13 +00:00
Daniel Dunbar b0d34c8e4a Add __builtin_object_size support.
- Currently CodeGen always returns a conservative value for this (-1
   or 0 depending on the context).

llvm-svn: 55735
2008-09-03 21:13:56 +00:00
Daniel Dunbar c5d330400f Fix ObjCPropertRefExpr to be able to encode all the information for
uses which refer to methods not properties.
 - Not yet wired in Sema.

llvm-svn: 55681
2008-09-03 00:27:26 +00:00
Nuno Lopes f380a0de07 codegen constant data as such. add QualType::isConstant()
llvm-svn: 55603
2008-09-01 11:33:04 +00:00
Anders Carlsson 3f35a266da Handle mutation while enumerating correctly. Fix some bugs.
llvm-svn: 55583
2008-08-31 04:05:03 +00:00
Anders Carlsson 756585963b Initial support for CodeGen of for ... in statements.
llvm-svn: 55580
2008-08-31 02:33:12 +00:00
Anders Carlsson 2e744e8aa6 Stub out CodeGenFunction::EmitObjCForCollectionStmt.
Add CodeGenFunction::EmitMemSetToZero and make AggExprEmitter::EmitAggregateClear use it.

llvm-svn: 55573
2008-08-30 19:51:14 +00:00
Anders Carlsson 7e1e57103e Simplify some calls to Builder.CreateCall
llvm-svn: 55567
2008-08-30 16:17:45 +00:00
Daniel Dunbar 4b8c6db927 Add Objective-C property setter support.
- Change Obj-C runtime message API, drop the ObjCMessageExpr arg in
   favor of just result type and selector. Necessary so it can be
   reused in situations where we don't want to cons up an
   ObjCMessageExpr.
 - Update aggregate binary assignment to know about special property
   ref lvalues.
 - Add CodeGenFunction::EmitCallArg overload which takes an already
   emitted rvalue.

Add CodeGenFunction::StoreComplexIntoAddr.

Disabled logic in Sema for parsing Objective-C dot-syntax that
accesses methods. This code does not search in the correct order and
the AST node has no way of properly representing its results.

Updated StmtDumper to print a bit more information about
ObjCPropertyRefExprs.

llvm-svn: 55561
2008-08-30 05:35:15 +00:00
Daniel Dunbar c722b8565c Refactor handling of calls:
- Added CodeGenFunction::EmitCall which just takes the callee, return
   type, and a list of (Value*,QualType) pairs.
 - Added CodeGenFunction::EmitCallArg which handles emitting code for
   a call argument and turning it into an appropriate
   (Value*,QualType) pair.
 - Changed Objective-C runtime interface so that the actual emission
   of arguments for message sends is (once again) done in the code to
   emit a message send.

No intended functionality change, this is prep work for better ABI
support and for Objective-C property setter support.

llvm-svn: 55560
2008-08-30 03:02:31 +00:00
Daniel Dunbar a799807dea Downgrade a number of FIXME asserts to ErrorUnsupported.
- Notably VLAs

llvm-svn: 55544
2008-08-29 17:28:43 +00:00
Daniel Dunbar 9e22c0d317 Add special "property reference" CodeGen::LValue type for emitting
Objective-C property references.
 - This handles property references "more correctly" but setters still
   don't work.

llvm-svn: 55534
2008-08-29 08:11:39 +00:00
Daniel Dunbar 3e1888e8bd Fix double-free error with sizeof applied to VLA types.
- PR2727.

Also, fix warning in CodeGenTypes for new BlockPointer type.

llvm-svn: 55479
2008-08-28 18:02:04 +00:00
Daniel Dunbar 4932b36f54 NeXT: Emit mostly-correct property type encoding.
- Added ASTContext::getObjCEncodingForPropertyDecl.

llvm-svn: 55461
2008-08-28 04:38:10 +00:00
Daniel Dunbar 55310df79c Initial support for Obj-C dot-syntax for getters.
llvm-svn: 55410
2008-08-27 06:57:25 +00:00
Daniel Dunbar eb1f9a2566 NeXT: Refactor protocol method metadata emission.
Also, fix category protocol list metadata.

llvm-svn: 55405
2008-08-27 02:31:56 +00:00
Daniel Dunbar 28e76caea1 NeXT: Emit correct properties for category.
- Was emitting duplicates of class properties instead of the category
   properties.

llvm-svn: 55395
2008-08-26 23:03:11 +00:00
Daniel Dunbar 3c76cb5cad NeXT: Emit metadata for synthetsized properties.
Also, fix method lookup to not use LLVM module symbol table.

llvm-svn: 55390
2008-08-26 21:51:14 +00:00
Daniel Dunbar 89654eef3a Objective-C @synthesize support.
- Only supports simple assignment and atomic semantics are ignored.
 - Not quite usable yet because the methods do not actually get added
   to the class metadata.
 - Added ObjCPropertyDecl::getSetterKind (one of Assign, Copy, Retain).
 - Rearrange CodeGenFunction so synthesis can reuse function prolog /
   epilog code.

llvm-svn: 55365
2008-08-26 08:29:31 +00:00
Eli Friedman 3d421e190a Do typechecking and codegen for K&R-style function declarations
correctly.  Not a regression, but made more obvious by my recent fix 
which made function type compatibility checking a bit more strict.

llvm-svn: 55339
2008-08-25 21:31:01 +00:00
Daniel Dunbar f2e69888c5 Support __PRETTY_FUNCTION__ and friends in Obj-C methods.
Add CodeGenFunction::EmitUnsupportedLValue 
 - Gives error and returns undef value.

Swap some asserts() over to using EmitUnsupportedLValue
 - Rumor has it users (and even some developers) prefer carat
   diagnostics to backtraces.
 - Works better in Release-Asserts to boot.

llvm-svn: 55328
2008-08-25 20:45:57 +00:00
Daniel Dunbar ef957f3489 Change another is-a-pointer check to check in terms of LLVM type.
llvm-svn: 55312
2008-08-25 10:38:11 +00:00
Daniel Dunbar 427f873196 Do is-a-pointer checks in terms of LLVM types in
EmitScalarConversion().
 - Important for allowing Obj-C void * to id<X> casts and so on.
 - Not sure about this fix however, perhaps Type should understand
   that id is effectively a pointer type.

llvm-svn: 55311
2008-08-25 09:51:32 +00:00
Daniel Dunbar ca8531a2d7 Fix Obj-C super sends inside class methods.
- NeXT loads the super class at runtime; this required changing the
   runtime interface to pass more information down.

llvm-svn: 55307
2008-08-25 08:19:24 +00:00
Daniel Dunbar 236e02c62c Name struct types generated for Obj-C classes.
llvm-svn: 55304
2008-08-25 06:28:15 +00:00
Daniel Dunbar eb99810502 Use DenseMap on IdentifierInfo instead of StringMap.
llvm-svn: 55303
2008-08-25 06:18:57 +00:00
Daniel Dunbar c61d0e9ee9 NeXT: Emit symbols used to manage linking of Obj-C classes.
- This ensures that references to undefined classes cause link
   errors.
 - NOTE: This relies on platform specific asm directives currently,
   this should be factored out.

Also, don't emit a SYMBOLS metadata entry if there are no symbols.

llvm-svn: 55302
2008-08-25 06:02:07 +00:00
Anders Carlsson ab55d9cd74 Handle emitting __builtin_huge_valf as a constant expr.
llvm-svn: 55299
2008-08-25 03:27:15 +00:00
Anders Carlsson c13b85a6b8 Make code generation of ivar ref exprs more like member exprs.
llvm-svn: 55298
2008-08-25 01:53:23 +00:00
Anders Carlsson 4c03d98e45 Handle static variables inside obj-c methods.
llvm-svn: 55297
2008-08-25 01:38:19 +00:00
Anders Carlsson 88e89a5a5d Convert qualified interface types correctly.
llvm-svn: 55287
2008-08-24 18:05:19 +00:00
Anders Carlsson 131be8b4f4 Handle static initializers in Objective-C++ methods.
llvm-svn: 55250
2008-08-23 19:42:54 +00:00
Argyrios Kyrtzidis ce4528f008 Add CodeGen support for CXXZeroInitValueExpr.
llvm-svn: 55249
2008-08-23 19:35:47 +00:00
Daniel Dunbar 28ff072b70 Drop a dead call to isConstantExpr()
llvm-svn: 55244
2008-08-23 18:44:10 +00:00
Daniel Dunbar d644ad61e9 NeXT: Clean up constant CFString handling.
- Use CodeGenModule::GetAddrOfConstantCFString

Some tweaks of CodeGenModule::GetAddrOfConstantCFString

llvm-svn: 55243
2008-08-23 18:37:06 +00:00
Daniel Dunbar c8317a44cf Implement Obj-C ivar references to aggregates.
Implement Obj-C lvalue message sends (aggregate returns).

Update several places to emit more precise ErrorUnsupported warnings
  for currently unimplemented Obj-C features (main missing chunks are
  property references, Obj-C exception handling, and the for ... in
  syntax).

llvm-svn: 55234
2008-08-23 10:51:21 +00:00
Daniel Dunbar 97ff50dd6e NeXT: Fix message sends which return structures.
- Simplify the sending code a bit.

llvm-svn: 55232
2008-08-23 09:25:55 +00:00
Daniel Dunbar f6397fed10 NeXT: Implement super message sends.
llvm-svn: 55225
2008-08-23 04:28:29 +00:00
Daniel Dunbar 97db84ce6d Trim CGObjCRuntime::GenerateMessageSend[Super]
- Returns an RValue.
 - Reduced to only taking the CodeGenFunction, Expr, and Receiver.
 - Becomes responsible for emitting the arguments.

Add CodeGenFunction::EmitCallExprExt
 - Takes optional extra arguments to insert at the head of the call.
 - This allows the Obj-C runtimes to call into this and isolates the
   argument and call instruction generation code to one place. Upshot
   is that we now pass structures (more) correctly.

Also, fix one aspect of generating methods which take structure
arguments (for NeXT). This probably needs to be merged with the
SetFunctionAttributes code in CodeGenModule.cpp

llvm-svn: 55223
2008-08-23 03:46:30 +00:00
Daniel Dunbar d4f616b853 Move [LR]Value into CGValue.h
- No (intended) functional change.

llvm-svn: 55221
2008-08-23 03:10:25 +00:00
Daniel Dunbar 80a840bc70 NeXT: Emit property metadata (classes, protocols, categories).
llvm-svn: 55209
2008-08-23 00:19:03 +00:00
Daniel Dunbar 938a77f4c9 NeXT: Emit category metadata.
llvm-svn: 55197
2008-08-22 20:34:54 +00:00
Anders Carlsson 87fc5a5e6b Add preliminary (and probably broken) codegen support for C++ static initializers.
llvm-svn: 55180
2008-08-22 16:00:37 +00:00
Daniel Dunbar dec75f895e NeXT: Emit [meta]class protocol references.
Updated ObjCProtocolDecl::protocol_iterator to match that of
ObjCInterfaceDecl.

llvm-svn: 55143
2008-08-21 21:57:41 +00:00
Daniel Dunbar 22d82ed0e2 Preliminary support for Obj-C classes in NeXT runtime.
- Functional for simple cases but there are some glaring omissions
   (protocols, properties, and other language extensions).
 - The code needs a fair bit of cleaning.

llvm-svn: 55108
2008-08-21 04:36:09 +00:00
Daniel Dunbar 66912a1a6d Move all Obj-C runtime interaction into CodeGenFunction.
- Drop duplicate (and broken) code for sending messages.
 - Add EmitObjCProtocolExpr to CodeGenFunction.

llvm-svn: 55024
2008-08-20 00:28:19 +00:00
Argyrios Kyrtzidis 3bab3d21f9 Add ExplicitCastExpr to replace the current CastExpr, and have ImplicitCastExpr and ExplicitCastExpr derive from a common base class (CastExpr):
Expr
  -> CastExpr
     -> ExplicitCastExpr
     -> ImplicitCastExpr 

llvm-svn: 54955
2008-08-18 23:01:59 +00:00
Daniel Dunbar a94ecd2a0b Add NeXT runtime support for generating methods.
Change CodeGenFunction::EmitParmDecl to take either a ParmVarDecl or an
  ImplicitParamDecl.

Drop hasAggregateLLVMType from CodeGenModule.cpp (use version in
  CodeGenFunction).

Change the Objective-C method generation to use EmitParmDecl for
  implicit parameters.

llvm-svn: 54838
2008-08-16 03:19:19 +00:00
Daniel Dunbar 8bc821ae7c Add CodeGen support for AddrLabelExpr in initializers.
llvm-svn: 54837
2008-08-16 01:41:47 +00:00
Daniel Dunbar a7c8cf6200 Change WarnUnsupported to ErrorUnsupported (in name and in practice).
- We are beyond the point where this shows up often and when it does
   generating miscompiled files is bad.

llvm-svn: 54836
2008-08-16 00:56:44 +00:00
Daniel Dunbar 7c6d3a7c50 Change ObjCRuntime::LookupClass -> GetClass, and now takes the
ObjCInterfaceDecl.

Change ObjCRuntime::GenerateMessageSendSuper to take the
  ObjCInterfaceDecl for the super class, instead of just its name.

Change EmitObjCMessageExpr to make the right runtime calls for super
  sends in class methods (i.e. a super send with the class object as
  the receiver).

llvm-svn: 54833
2008-08-16 00:25:02 +00:00
Daniel Dunbar fce4be843e Clean up CodeGenModule interface.
- Add CodeGenModule::EmitTopLevelDecl which uses switch on kind
   instead of ugly & slow dyn_cast chains.

 - Drop some simple forwarding methods into the ObjC runtime.

 - Privatize appropriate methods.

llvm-svn: 54827
2008-08-15 23:26:23 +00:00
Daniel Dunbar 9299250939 Change CGObjCRuntime methods to take appropriate clang Decls.
- This is in prep for implementation class support for the NeXT
   runtime, for which the existing methods don't provide enough
   information (and additionally make too many assumptions about how
   things should be emitted).

llvm-svn: 54824
2008-08-15 22:20:32 +00:00
Daniel Dunbar 2617a3abe6 Infinite loops considered harmful.
- Thanks Thomas

llvm-svn: 54818
2008-08-15 18:29:12 +00:00
Daniel Dunbar 7da1b82f56 Update some isIntegerConstantExpr uses to use
getIntegerConstantExprValue where appropriate.

llvm-svn: 54771
2008-08-13 23:47:13 +00:00
Daniel Dunbar c4baa06d15 Add GetAddrOfConstantCString method
- Returns addr of constant for argument + '\0'.
 - I couldn't think of a better name.
 - Move appropriate users of GetAddrOfConstantString to this.

Rename getStringForStringLiteral to GetStringForStringLiteral.

Add GetAddrOfConstantStringFromLiteral
 - This combines GetAddrOfConstantString and
   GetStringForStringLiteral. This method can be, but is not yet, more
   efficient.

Change GetAddrOfConstantString to not add terminating '\0'
 - <rdar://problem/6140956>

llvm-svn: 54768
2008-08-13 23:20:05 +00:00
Daniel Dunbar b036db8e66 Implement Obj-C protocol metadata generation for NeXT.
- Near complete, only properties are missing.

llvm-svn: 54715
2008-08-13 03:21:16 +00:00
Daniel Dunbar 89da6ad1db Change ObjCRuntime GenerateProtocol[Ref] methods to take
ObjCProtocolDecl directly.

Implement CodeGen support for forward protocol decls (no-ops are so
    nice to implement).

Also moved CGObjCRuntime.h out of CodeGenModule.h

llvm-svn: 54709
2008-08-13 00:59:25 +00:00
Daniel Dunbar 7bd00bda05 Emit OBJC_MODULE_INFO and OBJC_SYMBOLS metadata
- Matches llvm-gcc and seem to be expected by otool.

llvm-svn: 54669
2008-08-12 06:48:42 +00:00
Daniel Dunbar d627c85f43 Drop Sender from GenerateMessageSend*
- Was unused and generated a unnecessary load of self
(missed file)

llvm-svn: 54668
2008-08-12 05:40:10 +00:00
Daniel Dunbar 5d71559c01 Drop Sender from GenerateMessageSend*
- Was unused and generated a unnecessary load of self

Update NeXT runtime to get proper object & selector types from
       ASTContext.

llvm-svn: 54667
2008-08-12 05:28:47 +00:00
Daniel Dunbar 6630e10ccc Protocol related tweaks
- Implement type conversion of ObjCQualifiedIdType
 - Wire @protocol(...) to GenerateProtocolRef in ScalarExprEmitter

llvm-svn: 54666
2008-08-12 05:08:18 +00:00
Daniel Dunbar bceb904f91 Add @selector(...) codegen support.
llvm-svn: 54665
2008-08-12 03:55:34 +00:00
Daniel Dunbar cb515c8b0a Add NeXT support for (simple) message sends.
llvm-svn: 54664
2008-08-12 03:39:23 +00:00
Daniel Dunbar 8b8683f9f6 Add ObjC constant string support for NeXT.
Changed CGObjCRuntime::GenerateConstantString interface to take
       std::string instead of char* and size.

Change ObjC functions which call on GenerateConstantString to bitcast
       result to appropriate type.

llvm-svn: 54659
2008-08-12 00:12:39 +00:00
Mike Stump 52f0260582 Fix compilation warning with help from David Chisnall.
llvm-svn: 54654
2008-08-11 23:16:18 +00:00
Daniel Dunbar 3ad53483fb Add LangOptions::NeXTRuntime.
- Wired to -fnext-runtime and -fgnu-runtime options.
 - Defaults to GNU, no autoselection for NeXT.

Emit NeXT OBJC_IMAGE_INFO marker.

llvm-svn: 54651
2008-08-11 21:35:06 +00:00
Daniel Dunbar 8d480594cf Change CodeGenModule to only create ObjC runtime for ObjC files
- Changed CodeGenModule::getObjCRuntime to return reference.
 - Added CodeGenModule::hasObjCRuntime predicate.

llvm-svn: 54645
2008-08-11 18:12:00 +00:00
Daniel Dunbar fb3043d627 Add -fexceptions to Driver
- Maps to LangOptions.Exceptions
 - Currently always off, should autoselect based on language.

Update CodeGen to set unwind attribute on functions definitions based
       on LangOptions.Exceptions.
 - Still need to set attributes appropriately on calls.

llvm-svn: 54643
2008-08-11 17:36:14 +00:00
Daniel Dunbar 48595de697 Update for IRBuilder template change (update LLVM!)
llvm-svn: 54642
2008-08-11 16:50:21 +00:00
Daniel Dunbar 56fdb6ae69 More #include cleaning
- Kill unnecessary #includes in .cpp files. This is an automatic
   sweep so some things removed are actually used, but happen to be
   included by a previous header. I tried to get rid of the obvious
   examples and this was the easiest way to trim the #includes in one
   fell swoop.
 - We now return to regularly scheduled development.

llvm-svn: 54632
2008-08-11 06:23:49 +00:00
Daniel Dunbar 6e8aa537f8 More #include cleaning
- Drop {Decl.h,DeclObjC.h,IdentifierTable.h} from Expr.h
 - Moved Sema::getCurMethodDecl() out of line (dependent on
   ObjCMethodDecl via dyn_cast).

llvm-svn: 54629
2008-08-11 05:35:13 +00:00
Daniel Dunbar ad319a73f2 More #include cleaning
- Remove internal uses of AST.h

llvm-svn: 54628
2008-08-11 05:00:27 +00:00
Daniel Dunbar 221fa94e40 More #include cleaning
- Drop Expr.h,RecordLayout.h from ASTContext.h (for DeclBase.h and
   SourceLocation.h)
 - Move ASTContext constructor into implementation

llvm-svn: 54627
2008-08-11 04:54:23 +00:00
Daniel Dunbar 303e2c2f1f Add dummy Mac Objective-C runtime interface.
- Not currently accessible and completely non-functional.

llvm-svn: 54624
2008-08-11 02:45:11 +00:00
Daniel Dunbar 6dfdf8c97a Back out r54608 (inline string literals were getting an extra '\0')
temporarily, I assumed GetAddrForConstantString literal was being
  used consistently but it doesn't look like it is.

Factored out a CodeGenModule::getStringForStringLiteral which handles
  extracting a std::string for the bytes of a StringLiteral, padded to
  match the type.

Update EmitLValue to use getStringForStringLiteral, this was
  previously not padding strings correctly. Good thing we only emit
  strings in 4 different places!

llvm-svn: 54621
2008-08-10 20:25:57 +00:00
Daniel Dunbar 07bb087ac1 Fix crash during initialization of a bitfield which followed a zero
length element.

Fix some 80-col violations.

llvm-svn: 54610
2008-08-10 07:00:24 +00:00
Daniel Dunbar 9a8d07321a Bug fix, inline string literals were getting an extra '\0'.
llvm-svn: 54608
2008-08-10 06:27:44 +00:00
Chris Lattner 6307f19726 rename PreDefinedExpr -> PredefinedExpr
llvm-svn: 54605
2008-08-10 01:53:14 +00:00
Nico Weber 53c362e34e 80 cols
llvm-svn: 54599
2008-08-09 23:08:17 +00:00
Argyrios Kyrtzidis dfaf82ac2d Handle BuiltinType::WChar inside CodeGenTypes::ConvertNewType().
llvm-svn: 54593
2008-08-09 22:01:55 +00:00
Chris Lattner c893a67fe3 update to make IRBuilder API change.
llvm-svn: 54548
2008-08-08 19:57:58 +00:00
Ted Kremenek 7db4f60b26 ParseAST now conditionally deletes the passed ASTConsumer.
ModuleBuilder now performs llvmgen in HandleTranslationUnit.

This patch follows from the discussion on the following thread on cfe-commits:

http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20080804/006849.html

llvm-svn: 54486
2008-08-07 19:47:41 +00:00
Daniel Dunbar e8bdce441b Fix EmitNullInitializationToLValue for bitfield lvalues.
- PR2643

llvm-svn: 54397
2008-08-06 05:32:55 +00:00
Daniel Dunbar ead7c91240 Fix bitfield accesses which straddle the boundary of the underlying
type.

 - This generates somewhat less optimal code than before but this is
   not hard to rectify once stable (at the cost of slightly more
   complex code).

 - This currently always uses little-endian ordering of the bitfield. 

 - This breaks the CodeGen/bitfield.c test because it was grepping for
   hard-coded assembly instructions. Will fix once a better test case
   is constructed (hard to do without execution).

 - This fixes SingleSource/UnitTests/2006-01-23-InitializedBitField.c
   and Regression/C/PR1386.c from the test suite.

 - <rdar://problem/6085090>, <rdar://problem/6094169>

llvm-svn: 54395
2008-08-06 05:08:45 +00:00
Daniel Dunbar bfb1cd7454 Fix CodeGen of pointer arithmetic in compound assignment statements.
- Changed EmitSub to work on all cases (arithmetic, ptr - int, ptr -
   ptr) so that implementation matches that of other operators.

 - Modify EmitCompoundAssign to compute and perform the appropriate
   casts of left, right, and result types for the assorted pointer
   arithmetic cases.

 - Fix EmitSub (ptr - int) case to negate the rhs *after*
   extension. This is critical when the rhs is unsigned (and needs
   extension).

 - This fixes cfrac.

 - <rdr://6115726>

llvm-svn: 54392
2008-08-06 02:00:38 +00:00
Daniel Dunbar ffc29be83f Implement GNU asm-label extension support in CodeGen. This fixes
scimark2 on Darwin.

 - Added Sema support for asm-label on variables, which I forgot before.

 - Update CodeGen to use GlobalDeclMap to determine if static Decls
   require emission (instead of LLVM module name lookup). Important
   since the Decl name and the LLVM module name can differ.

 - <rdar://problem/6116729>

llvm-svn: 54388
2008-08-06 00:03:29 +00:00
Daniel Dunbar 829e988899 Change CodeGen of global decls to key off of the name (instead of
having multiple bindings from all the possible decls which
  conceptually map to the same global).

 - This eliminates CodeGen depending on the LLVM module for name
   lookup.

 - This also eliminates the need for ReplaceMapValuesWith (hurrah).

 - This handles lookups for FunctionDecls correctly in the presence of
   aliases, this was previously broken.

 - WIP: Can still clean up & unify variable and function emission.

llvm-svn: 54382
2008-08-05 23:31:02 +00:00
Ted Kremenek 9f6112c4e6 Remove excess #include.
llvm-svn: 54366
2008-08-05 19:56:24 +00:00
Ted Kremenek 2c674f6dbb Refactored driver logic for CodeGen into LLVMCodeGenWriter. This ASTConsumer layers on top of LLVMCodeGen (another existing ASTConsumer) to emit bitcode files to disk. This layering takes this logic out of clang.cpp and puts it directly into the ASTConsumer interface. The benefit is that now --emit-llvm works with both serialized ASTs and regular source files.
llvm-svn: 54364
2008-08-05 18:50:11 +00:00
Daniel Dunbar 5aa55d51ca Bug fix, CodeGen of (void*) - (void*) was broken.
- <rdar://problem/6122967>

llvm-svn: 54338
2008-08-05 00:47:03 +00:00
Daniel Dunbar d27262f369 Avoid creating dummy block when no indirect gotos are present.
llvm-svn: 54322
2008-08-04 17:24:44 +00:00
Daniel Dunbar 88402ce8d0 Add CodeGen support for indirect goto.
- Follows emission scheme used by llvm-gcc, i.e. invent an id for
   each label whose address is taken and replace each indirect goto by
   a switch to each possible target.
 - Currently we emit a switch for each indirect goto instead of
   merging them as llvm-gcc does.

llvm-svn: 54318
2008-08-04 16:51:22 +00:00
Chris Lattner 7adf076088 Finally fix PR2189. This makes a fairly invasive but important change to
move getAsArrayType into ASTContext instead of being a method on type.
This is required because getAsArrayType(const AT), where AT is a typedef
for "int[10]" needs to return ArrayType(const int, 10).

Fixing this greatly simplifies getArrayDecayedType, which is a good sign.

llvm-svn: 54317
2008-08-04 07:31:14 +00:00
Daniel Dunbar 74aa7e1eae Support constructor and destructor attributes in CodeGen
- There is an miscompilation issue remaining due to a poor
   interaction between the delayed emission of static functions and
   the emission of constructors, but that already existed prior to
   this change.

llvm-svn: 54258
2008-08-01 00:01:51 +00:00
Chris Lattner 330f0f2567 Fix a regression I introduced in r54107:
http://llvm.org/viewvc/llvm-project?view=rev&revision=54107

llvm-svn: 54242
2008-07-31 04:58:58 +00:00
Mon P Wang b160a0d78d Updated to match new atomic names (to enable overloading for pointers to
different address spaces) for llvm r54195.

llvm-svn: 54241
2008-07-31 03:28:23 +00:00
Daniel Dunbar b39b1cd7c3 Fix implicit initialization of structures.
<rdar://problem/6113085>

llvm-svn: 54237
2008-07-30 21:00:24 +00:00
Daniel Dunbar e49df9b58f Change CodeGenModule GlobalDeclMap to directly reference globals
instead of mapping the decl to a bitcast of the global to the correct
type.
 
 - GetAddrOf{Function,GlobalVar} introduce the bitcast on every use now.

 - This solves a problem where a dangling pointer could be introduced
   by the RAUW done when replacing a forward or tentative
   definition. See testcase for more details.

 - Fixes <rdar://problem/6108358>

llvm-svn: 54211
2008-07-30 16:32:24 +00:00
Daniel Dunbar 9c426524f8 Rework codegen emission of globals
- No (intended) functionality change.

 - Primary purpose is to clearly separate (lazy) construction of
   globals that are a forward declaration or tentative definition from
   those that are the final definition.

 - Lazy construction is now encapsulated in
   GetAddrOf{Function,GlobalVar} while final definitions are
   constructed in EmitGlobal{Function,Var}Definition.
 
 - External interface for dealing with globals is now limited to
   EmitGlobal and GetAddrOf{Function,GlobalVar}.

 - Also updated helper functions dealing with statics, annotations,
   and ctors to be private.

llvm-svn: 54179
2008-07-29 23:18:29 +00:00
Daniel Dunbar 837fd272f8 Fix codegen of chained declarations
- Killed useless CodeGenModule::EmitGlobalVarDeclarator, instead just
   recurse on any ScopedDecl.
 - Fix for <rdar://problem/6093838>

llvm-svn: 54162
2008-07-29 17:47:36 +00:00
Chris Lattner d9fa5d6a23 Fix a bug in my previous patch, CGF is not valid for constants outside a function
llvm-svn: 54108
2008-07-26 22:39:33 +00:00
Chris Lattner 0f398c4472 remove uses of QualType::getCanonicalType() from codegen for PR2189
llvm-svn: 54107
2008-07-26 22:37:01 +00:00
Chris Lattner 574dee6cac change more instances of QualType::getCanonicalType to call
ASTContext::getCanonicalType instead (PR2189)

llvm-svn: 54105
2008-07-26 22:17:49 +00:00
Chris Lattner 7e80097f6e implement codegen support for labels at the end of stmtexprs.
llvm-svn: 54100
2008-07-26 20:23:23 +00:00
Chris Lattner 6284378fcd minor tidying, no functionality change.
llvm-svn: 54099
2008-07-26 20:15:14 +00:00
Chris Lattner 4591fd0aac Fix rdar://6103124, the only dummy blocks are ones without names. Named blocks
are important part of control flow structures.

llvm-svn: 54078
2008-07-25 23:40:10 +00:00
Nate Begeman 448b0cb033 X86 builtin fixes
llvm-svn: 54049
2008-07-25 20:17:24 +00:00
Nate Begeman fe79ca2ab9 Generate vector compares in codegen
llvm-svn: 54048
2008-07-25 20:16:05 +00:00
Nate Begeman e7f45b2977 Move comment to match style
llvm-svn: 54047
2008-07-25 20:15:41 +00:00
Daniel Dunbar 0e5845c13a Rework codegen of case ranges
- Fix multiple issues with the way case ranges were emitted, see test
   cases details about the specific issues.

 - The root issue was not being careful about how basic blocks were
   emitted which led to them being chained together incorrectly,
   resulting in improper control flow.

 - Fixes <rdar://problem/6098585>

llvm-svn: 54006
2008-07-25 01:11:38 +00:00
Daniel Dunbar 2e0f1cd00c Fix EmitCaseStmtRange to ignore empty ranges
- Also cleaned up emission slightly 
 - Inspection of the code revealed several other bugs, however. Case
   ranges are not properly wired and can result in switch cases being
   dropped or even infinite loops. See: <rdar://problem/6098585>

Completes: <rdar://problem/6094119>
llvm-svn: 53975
2008-07-24 01:18:41 +00:00
Chris Lattner 28ee5b3d29 don't depend on the result of CreateNeg to be a binop
llvm-svn: 53948
2008-07-23 06:53:34 +00:00
Chris Lattner d258325c2b Fix a codegen crash on:
int foo(void) {
  float x[2];
  return x;
}

rdar://6093986

llvm-svn: 53946
2008-07-23 06:31:27 +00:00
Daniel Dunbar a2fbefc159 Add note to check what __alignof__ a function type should be.
llvm-svn: 53928
2008-07-22 19:44:18 +00:00
Daniel Dunbar ee8bbb3ccc Prevent codegen crash on sizeof(<function type>), a gcc extension.
llvm-svn: 53899
2008-07-22 01:35:47 +00:00
Daniel Dunbar 327acd7a6c Implement bzero, memset, memmove builtins.
This subsumes Nico Weber's patch and implements bzero in terms
of llvm.memset to match llvm-gcc.

llvm-svn: 53888
2008-07-22 00:26:45 +00:00
Daniel Dunbar b725726c29 Implement nans, prefetch, and trap builtins.
This closes <rdar://problem/6080720>, support for __builtin_constant_p
has been filed separately.

llvm-svn: 53885
2008-07-21 22:59:13 +00:00
Daniel Dunbar 7ed03c4cdd Kill an unused variable warning
llvm-svn: 53878
2008-07-21 21:43:28 +00:00
Chris Lattner 390d39ac7e move two more lists of protocols over to use ObjCList<ObjCProtocolDecl>,
simplifying code along the way and fixing a problem and memory leak or two.

llvm-svn: 53876
2008-07-21 21:32:27 +00:00
Daniel Dunbar c2f67966f4 Add __builtin_powi[fl] support
llvm-svn: 53866
2008-07-21 18:44:41 +00:00
Chris Lattner d004505b74 introduce a new ObjCList templated class and start moving
various objc lists over to it.  First up, the protocol list 
on ObjCInterfaceDecl.

llvm-svn: 53856
2008-07-21 18:19:38 +00:00
Daniel Dunbar d93abc3bb0 Implement ffs, parity, and popcount builtins.
+ test case

llvm-svn: 53851
2008-07-21 17:19:41 +00:00
Chris Lattner f1c149db9f don't pass in null as the Name for GenerateClassStructure,
it goes and makes std::strings out of them, which is not 
defined.

llvm-svn: 53843
2008-07-21 06:31:05 +00:00
Mon P Wang 194c58f56d Add support shufpd
llvm-svn: 53747
2008-07-18 00:14:09 +00:00
Daniel Dunbar 1f32c759dc Fix for codegen crash on multibit bool bitfield initialization
<rdar://problem/6078606>

llvm-svn: 53737
2008-07-17 21:07:48 +00:00
Chris Lattner 6d1a3c2e2b remove CGObjCEtoile until it compiles.
llvm-svn: 53552
2008-07-14 16:54:05 +00:00
Chris Lattner 0bf679180c Codegen support for __builtin_stdarg_start
llvm-svn: 53329
2008-07-09 17:28:44 +00:00
Sanjiv Gupta 1e8b608751 Fixed bugzilla bug# 2489.
This was broken when the GenerateCode function was splitted to use GenerateFunction.

llvm-svn: 53136
2008-07-04 11:04:26 +00:00
Bill Wendling e7264ec999 Remove removed header.
llvm-svn: 53121
2008-07-03 22:54:30 +00:00
Chris Lattner 9a8d1d9e56 Make a few related changes:
1) add a new ASTContext::getFloatTypeSemantics method.
2) Use it from SemaExpr.cpp, CodeGenTypes.cpp and other places.
3) Change the TargetInfo.h get*Format methods to return their 
   fltSemantics byref instead of by pointer.
4) Change CodeGenFunction::EmitBuiltinExpr to allow builtins which
   sometimes expand specially and othertimes fall back to libm.
5) Add support for __builtin_nan("") to codegen, cases that don't pass
   in an empty string are currently lowered to libm calls.
6) Fix codegen of __builtin_infl.

llvm-svn: 52914
2008-06-30 18:32:54 +00:00
Cedric Venet 3903908794 Add missing include file (due to a file splitting in llvm).
Add new file to Sema Project for VS.
this unbreak the build for VS2005 (with the associated patch on llvm).

llvm-svn: 52830
2008-06-27 17:53:02 +00:00
Chris Lattner bf231a61fd refactor more objc codegen interfaces to pass around selectors so
we don't push strings into LLVM IR and then have to read them back out.

llvm-svn: 52765
2008-06-26 05:08:00 +00:00
Chris Lattner 882034dd99 indenting and other minor things.
llvm-svn: 52764
2008-06-26 04:52:29 +00:00
Chris Lattner da35bc8e53 refactor interface to GenerateClassStructure to avoid converting a
string to LLVM IR and then regenerating the string from IR.

llvm-svn: 52762
2008-06-26 04:47:04 +00:00
Chris Lattner d9b98863c4 remove the old getSelector implementation, which removes some
calls to getStringValue

llvm-svn: 52761
2008-06-26 04:44:19 +00:00
Chris Lattner 6cfec78e48 avoid a lot of unneeded selector processing work by passing around
selectors instead of Value*'s.

llvm-svn: 52760
2008-06-26 04:42:20 +00:00
Chris Lattner 9a05d04a0d use cheaper/simpler getselector call for @selector exprs.
llvm-svn: 52759
2008-06-26 04:38:58 +00:00
Chris Lattner 6d522c0133 start avoid doing lots of unneeded work handling selectors
llvm-svn: 52758
2008-06-26 04:37:12 +00:00
Chris Lattner 42587147d4 improve indentation, avoid thrashing on maps and recalculating strings as much.
llvm-svn: 52757
2008-06-26 04:24:57 +00:00
Chris Lattner 87ab27d42f give CreateObjCRuntime a full CGM so it can get whatever state it needs,
instead of passing in just a couple random things it currently 
happens to use.

llvm-svn: 52756
2008-06-26 04:19:03 +00:00
Chris Lattner 63dd337fc2 Fix 80 col violations, assert on assumptions.
llvm-svn: 52755
2008-06-26 04:10:42 +00:00
Chris Lattner d46944d639 a temporary minimal hack to get clang building after the getStringValue changes in llvm mainline.
llvm-svn: 52753
2008-06-26 04:05:20 +00:00
Mon P Wang 28898b2888 Updated atomic intrinsic name from llvm r52706. Fixed dropped bit in shufps.
llvm-svn: 52707
2008-06-25 08:21:36 +00:00
Chris Lattner b1d329da07 "Support for Objective-C message sends which return structures. Also includes a small fix for constant string handling that should have been in the last patch (sorry!) and a hook for generating selectors (rest of this implementation to follow in the next patch)."
Patch by David Chisnall!

llvm-svn: 52681
2008-06-24 17:04:18 +00:00
Chris Lattner 6447ed3a1f "This is a small fix for a bug where static object instances were being incorrectly generated. The bug was caused by my inability to read the GNU libobjc source and is only apparent when JITing code (static compilation does not expose the bug due to the data layout of other globals)."
Patch by David Chisnall!

llvm-svn: 52680
2008-06-24 17:01:28 +00:00
Chris Lattner 091f698d29 "this patch adds code generation hooks for Objective-C constant strings. It also modifies Sema so that Objective-C constant strings are treated as untyped objects if the interface for the constant string class can not be found. This is consistent with Apple GCC. I thought it was consistent with GNU GCC, since this was causing failures when trying to compile GNUstep with (GNU) GCC, but it appears that this is not the case when attempting to produce a simple test case to demonstrate it. Possibly there is a way of making the error go away, but I haven't found out what it is yet."
Patch by David Chisnall!

llvm-svn: 52599
2008-06-21 21:44:18 +00:00
Chris Lattner c4f38851e6 Don't add isa with @defs only to work around it in the code generator, patch
by David Chisnall. 

llvm-svn: 52597
2008-06-21 21:37:25 +00:00
Mike Stump d7667bd8e0 Remove tabs.
llvm-svn: 52507
2008-06-19 20:57:50 +00:00
Chris Lattner 5696e7badf Change self/_cmd to be instances of ImplicitParamDecl instead of ParmVarDecl.
Patch by David Chisnall!

llvm-svn: 52422
2008-06-17 18:05:57 +00:00
Ted Kremenek 08e171183f This patch is motivated by numerous strict-aliasing warnings when compiling
clang as a Release build.

The big change is that all AST nodes (subclasses of Stmt) whose children are
Expr* store their children as Stmt* or arrays of Stmt*. This is to remove
strict-aliasing warnings when using StmtIterator. None of the interfaces of any
of the classes have changed (except those with arg_iterators, see below), as the
accessor methods introduce the needed casts (via cast<>). While this extra
casting may seem cumbersome, it actually adds some important sanity checks
throughout the codebase, as clients using StmtIterator can potentially overwrite
children that are expected to be Expr* with Stmt* (that aren't Expr*). The casts
provide extra sanity checks that are operational in debug builds to catch
invariant violations such as these.

For classes that have arg_iterators (e.g., CallExpr), the definition of
arg_iterator has been replaced. Instead of it being Expr**, it is an actual
class (called ExprIterator) that wraps a Stmt**, and provides the necessary
operators for iteration. The nice thing about this class is that it also uses
cast<> to type-checking, which introduces extra sanity checks throughout the
codebase that are useful for debugging.

A few of the CodeGen functions that use arg_iterator (especially from
OverloadExpr) have been modified to take begin and end iterators instead of a
base Expr** and the number of arguments. This matches more with the abstraction
of iteration. This still needs to be cleaned up a little bit, as clients expect
that ExprIterator is a RandomAccessIterator (which we may or may not wish to
allow for efficiency of representation).

This is a fairly large patch. It passes the tests (except CodeGen/bitfield.c,
which was already broken) on both a Debug and Release build, but it should
obviously be reviewed.

llvm-svn: 52378
2008-06-17 02:43:46 +00:00
Chris Lattner 22b9ff4131 force size of alloca to i32, which is currently required by LLVM IR.
This fixes use of alloca on 64-bit systems.

llvm-svn: 52334
2008-06-16 17:15:14 +00:00
Eli Friedman 327944b343 Basic support for volatile loads and stores. Stores the volatile
qualifier in the lvalue, and changes lvalue loads/stores to honor 
the volatile flag.  Places which need some further attention are marked 
with FIXMEs.

Patch by Cédric Venet.

llvm-svn: 52264
2008-06-13 23:01:12 +00:00
Argyrios Kyrtzidis d0c1df4c84 Make CodeGenFunction::EmitDecl() recognise CXXClass/CXXStruct/CXXUnion.
llvm-svn: 52162
2008-06-09 23:42:47 +00:00
Argyrios Kyrtzidis 554a07bab3 -Changes to TagDecl:
Added TagKind enum.
  Added getTagKind() method.
  Added convenience methods: isEnum(), isStruct(), isUnion(), isClass().
-RecordDecl/CXXRecordDecl::Create() accept a TagKind enum instead of a DeclKind one.

llvm-svn: 52160
2008-06-09 23:19:58 +00:00
Sanjiv Gupta 224e8ea2bb Generate debug descriptors for array types while generating the debug info.
llvm-svn: 52140
2008-06-09 10:47:41 +00:00
Nuno Lopes b6f7953818 implement the alias attirbute (in both Sema and Codegen)
llvm-svn: 52092
2008-06-08 15:45:52 +00:00
Nuno Lopes cc041ea68e fix compiler warnings
llvm-svn: 52089
2008-06-08 10:16:34 +00:00
Eli Friedman c98a7add43 Don't crash emitting an initializer for a static local with union type.
This fix just makes sure to construct the global with the appropriate 
type, and fixes up the one user this affects to compensate.

llvm-svn: 52084
2008-06-08 01:23:18 +00:00
Eli Friedman 3ce7b20590 Fix crash with conversion to an address-space-qualified pointer. Bug
reported on cfe-dev by Cédric Venet.

Note that I seriously doubt that this perticular construct is useful, 
though: it's a pointer in an alternate address space pointing into 
unqualified address space.

llvm-svn: 52076
2008-06-07 17:27:51 +00:00
Sanjiv Gupta 1929242a94 Create debug type descriptors for aggregate/enum types.
llvm-svn: 52070
2008-06-07 04:46:53 +00:00
Eli Friedman fd1e32b1f3 Reorganize this loop a bit so it doesn't crash for empty unions. Fixes
PR2419.

llvm-svn: 52060
2008-06-06 20:12:37 +00:00
Nuno Lopes 9b07b7b099 implement constant expr. sub ptr ptr
llvm-svn: 52049
2008-06-06 16:41:08 +00:00
Sanjiv Gupta 158143ad54 Emit debug information for global and static variables when -g is specified.
llvm-svn: 51993
2008-06-05 08:59:10 +00:00
Eli Friedman 2425cd8158 For setting attributes, don't assume there are ParamVarDecls available,
because trying to access non-existent ParamVarDecls can crash. 
Testcase from the original source for PR2414.

llvm-svn: 51960
2008-06-04 19:41:28 +00:00
Nuno Lopes 7bd6e58ddc fix crash when codegening 'cond ? lhs : call-to-void-func()'
llvm-svn: 51958
2008-06-04 19:15:45 +00:00
Eli Friedman c0b54901f4 clang fix to parallel LLVM r51928
(http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20080602/063306.html).

llvm-svn: 51944
2008-06-04 16:13:19 +00:00
Argyrios Kyrtzidis 28172cb812 Include <string> header to allow compiling for MSVC.
llvm-svn: 51847
2008-06-01 21:23:24 +00:00
Eli Friedman 412c66839e Don't name the ObjC types if there aren't any ObjC objects in the file.
Patch by David Chisnall.

llvm-svn: 51840
2008-06-01 16:00:02 +00:00
Eli Friedman f6b091f73a First cut at setting attributes for functions and calls; this puts us
much closer to passing the gcc struct layout tests.

It might be possible to refactor this a bit, but I'm not sure there's 
actually enough common code for that to be useful.

To get the calling convention completely correct, a bit of 
platform-specific code is necessary even for x86-Linux. On x86-Linux, the
alignment of function parameters is extremely strange; as far as I can tell,
it's always 4 except for SSE vectors or structs containing SSE vectors.  I'm 
continuing to investigate this.

llvm-svn: 51839
2008-06-01 15:54:49 +00:00
Eli Friedman 10c2417570 Make sure _Bool globals have the correct type.
llvm-svn: 51838
2008-06-01 15:31:44 +00:00
Eli Friedman 149a57f7d4 Minor cleanup to use the ConvertTypeForMem helper.
llvm-svn: 51837
2008-06-01 15:16:01 +00:00
Anton Korobeynikov 3b6dd58ee7 Remove spurious == 0
llvm-svn: 51836
2008-06-01 15:14:46 +00:00
Anton Korobeynikov 1200aca763 Support for code generation of Objective-C top-level language constructs.
Implemented by David Chisnall!

llvm-svn: 51835
2008-06-01 14:13:53 +00:00
Eli Friedman 252e5f1b29 Calculate alignment for local variables.
llvm-svn: 51826
2008-05-31 21:20:41 +00:00
Eli Friedman 6859a1b961 PR1893: Fix up the type of tentative definitions of incomplete array
types so that they end up the correct size.

llvm-svn: 51787
2008-05-30 20:39:54 +00:00
Eli Friedman 34994cbcbf Fix and enable generating general union initializers. Essentially, what
this does is reconstruct the type for structs and arrays if the type 
wouldn't be compatible otherwise.

The assertion about packing in the struct type reconstruction code 
sucks, but I don't see any obvious way to fix it.  Maybe we need a general
utility method to take a list of types and alignments and try to construct an
unpacked type if possible?

llvm-svn: 51785
2008-05-30 19:58:50 +00:00
Eli Friedman c18d9d53bb Allow the type of a global to be different from the type of its
associated declaration. This is a prerequisite to handling
general union initializations; for example, an array of unions involving 
pointers has to be turned into a struct because the elements can have 
incompatible types.

I refactored the code a bit to make it more readable; now, the logic for 
definitions is all in EmitGlobalVarInit.

The second parameter for GetAddrOfGlobalVar is now dead; I'll remove it 
separately.

By itself, this patch should not cause any visible changes.

llvm-svn: 51783
2008-05-30 19:50:47 +00:00
Eli Friedman f7fe41656c Fix constant vector init for initializer lists with an incomplete list
of elements.

llvm-svn: 51769
2008-05-30 12:02:14 +00:00
Eli Friedman 617ba48fd5 Always check that the definition of a function has the correct type.
This fixes a crash on the included testcase (found in NetHack).

llvm-svn: 51767
2008-05-30 11:13:18 +00:00
Sanjiv Gupta 18de624ca0 Emit parameter and local variable debug information with -g.
llvm-svn: 51765
2008-05-30 10:30:31 +00:00
Eli Friedman 711665c309 Add FIXME to CodeGen struct layout.
llvm-svn: 51764
2008-05-30 10:29:32 +00:00
Eli Friedman a2eaffc747 Some additions to constant initializer generation code. Adds
bit-field initialization; ugly code, X86-only, but it works, at least 
for basic stuff.  Separates/adds union initialization; currently disabled,
though, because the struct/array code needs modifications to support 
elements of the wrong type.

Fixes PR2381 and PR2309 with the bit-field initialization.  And NetHack 
compiles and appears to work with a few tweaks (to work around the lack 
of transparent_union support, and clang being a bit strict about
conflicting declarations).

llvm-svn: 51763
2008-05-30 10:24:46 +00:00
Steve Naroff 021ca18bb5 - Move ObjC Expresssion AST's from Expr.h => ExprObjC.h
- #include ExprObjC.h in many places

llvm-svn: 51703
2008-05-29 21:12:08 +00:00
Eli Friedman 43a6d51494 More complete/correct implementation of the comparison operators for
constant expressions.

llvm-svn: 51682
2008-05-29 15:17:49 +00:00
Eli Friedman 3c28524632 Fix an extremely subtle bug with pointer comparisons: they have to be
unsigned because it's possible (at least in theory) to have
have both positive and negative pointers pointing to the same object.

llvm-svn: 51681
2008-05-29 15:09:15 +00:00
Eli Friedman 133e8040ca Rearrange EmitLValueForField a bit to work properly for _Bool bitfields
in unions (we don't want to do the union-specific bitcast for 
bit-fields).

llvm-svn: 51678
2008-05-29 11:33:25 +00:00
Eli Friedman 045bf4ff82 Add codegen support for a few more kinds of initializer constant
expressions.

llvm-svn: 51677
2008-05-29 11:22:45 +00:00
Eli Friedman 174d9c26f1 Add CodeGen support for alignment on globals, both for unusual natural
alignment and alignment attributes.

llvm-svn: 51676
2008-05-29 11:10:27 +00:00
Eli Friedman b65ff27f53 A couple minor fixes to make debug info usable for arbitrary code: don't
emit incomplete types, because they crash llc, and always use the 
logical location as the current location so we don't crash doing invalid 
queries on CurLoc.

llvm-svn: 51675
2008-05-29 11:08:17 +00:00
Eli Friedman d72a9624a1 Tentative declarations are supposed to have common linkage, not weak.
This change makes clang generate the same thing as llvm-gcc.

llvm-svn: 51674
2008-05-29 11:03:17 +00:00
Eli Friedman 5a6d0ede91 Always use packed structs. This isn't really very nice, but there's
nothing fundamentally wrong with it. Emitting unpacked structs where 
possible is more work for almost no practical benefit.  We'll probably 
want to fix it at some point anyway, but it's low priority.

The issue with long double in particular is that LLVM thinks an X86 long
double is 10 bytes, while clang considers it for all purposes to be
either 12 or 16 bytes, depending on the platform, even in a packed
struct.

llvm-svn: 51673
2008-05-29 10:58:49 +00:00
Devang Patel 1c56ace4df Check first member alignment and uses packed struct if required.
llvm-svn: 51619
2008-05-27 22:45:40 +00:00
Eli Friedman 21911e89d5 A few more cases for aggregate values.
llvm-svn: 51596
2008-05-27 15:51:49 +00:00
Eli Friedman 5e2281ede8 Implementation of __builtin_ctlz.
llvm-svn: 51595
2008-05-27 15:32:46 +00:00
Eli Friedman 70f5a921b7 The cache is working again; re-enable it.
llvm-svn: 51587
2008-05-27 08:43:22 +00:00
Eli Friedman 078c963a31 Add a more reliable check for whether a static declaration has already
been used.  In preparation for the fix to PR2360, but also a minor bug 
in its own right.

llvm-svn: 51583
2008-05-27 04:58:01 +00:00
Eli Friedman 3e1d35b92d Stop leaking the target data. (Leak found with valgrind.)
llvm-svn: 51579
2008-05-27 04:22:24 +00:00
Eli Friedman bdef5df44e Generalize the float type generation code, and specifically fix the
codegen of X86 long double.

llvm-svn: 51578
2008-05-27 04:20:05 +00:00
Eli Friedman 42ed07e10e Rewrite struct/union layout. This is mostly cleanup; this might also fix
a few bugs, but I don't know of any in particular. This has good effects 
besides cleanup, though: it also should make it easier to implement the 
aligned and packed attributes, and also target-specific struct layouts, 
because the code won't have to be duplicated in codegen.

llvm-svn: 51576
2008-05-27 03:14:44 +00:00
Eli Friedman df649f3da5 Emit memmove, not memcpy, for structure copies; this is unfortunately
required for correctness in cases of copying a struct to itself or to 
an overlapping struct (itself for cases like *a = *a, and overlapping 
is possible with unions).

Hopefully, this won't end up being a perf issue; LLVM *should* be able 
to optimize memmove to memcpy in a lot of cases, and for small copies 
the generated code *should* be mostly comparable. (In reality, LLVM 
is currently horrible at optimizing memmove, but that's a bug, not a 
fundamental issue.)

gcc currently generates wrong code; that's 
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32667.

llvm-svn: 51566
2008-05-26 12:59:39 +00:00
Eli Friedman 292e98cc18 Fix for PR2001. I'm not really fond of it, but it is correct (unless
someone tries to make a bitfield volatile?).

Not sure how to write a test; any suggestions?

llvm-svn: 51558
2008-05-25 14:13:57 +00:00
Sanjiv Gupta 98070578bf Generate subprogram debug info with -g.
Also take care of freeing memory at the right places.

llvm-svn: 51553
2008-05-25 05:15:42 +00:00
Dan Gohman 5d30975e5e Change uses of llvm::Type::isFirstClassType to use the new
llvm::Type::isSingleValueType. Currently these two functions have
the same behavior, but soon isFirstClassType will return true for
struct and array types.

Clang may some day want to use of isFirstClassType for some of
these some day as an optimization, but it'll require some
consideration.

llvm-svn: 51446
2008-05-22 22:12:56 +00:00
Eli Friedman 1763075b9c Make debugging information usable. This is barebones, but it makes -g
actually work (instead of crashing llc), and there's enough info emitted 
to get line number information in gdb. This should hopefully be helpful 
for debugging non-working programs.

I got rid of the begin/endregion calls because the implementation wasn't 
working; someone who knows the debugging info a bit better might try to 
add it. I really have no clue how a compiler is supposed to emit them.

This commit shouldn't have any effect without -g.

llvm-svn: 51404
2008-05-22 01:40:10 +00:00
Eli Friedman c7460b1011 Minor refactoring: compute the return value separately from emitting the
ret.

llvm-svn: 51403
2008-05-22 01:22:33 +00:00
Eli Friedman e53d15386f Make CurFuncDecl more specific; I have some code I'm going to land in a
bit that wants to use CurFuncDecl as a FunctionDecl.

llvm-svn: 51402
2008-05-22 01:16:59 +00:00
Dan Gohman 75d69da5ab Move getAccessedFieldNo out of lib/AST/Expr.cpp into
lib/CodeGen/CGExpr.cpp and to change include/clang/AST/Attr.h to
use its own enum for visibility types instead of using
llvm::GlobalValue::VisibilityTypes. These changes eliminate
dependencies in the AST library on LLVM's VMCore library.

llvm-svn: 51398
2008-05-22 00:50:06 +00:00
Eli Friedman 9a5ffcb14e Remove an unnecessary/buggy if check. Ran into this with some other
changes in my tree, so I don't have a testcase which affects trunk.

llvm-svn: 51371
2008-05-21 13:24:44 +00:00
Eli Friedman 3ed1d5f496 Disable the function address cache; this doesn't have any ill effects,
as far as I can tell, and it fixes code like test/CodeGen/functions.c.

(Whatever performance effect it might have, crashing on a 
construct like this isn't really acceptable; I've run into this 
multiple times.)

llvm-svn: 51312
2008-05-20 09:21:07 +00:00
Eli Friedman 53e38bd6b6 Add codegen support for stack address intrinsics.
llvm-svn: 51309
2008-05-20 08:59:34 +00:00
Eli Friedman 4b0e2a30e0 Implement codegen for comma operator for structs.
llvm-svn: 51304
2008-05-20 07:56:31 +00:00
Eli Friedman 247ee87e26 Restructure constant structure init codegen so that it's possible to
implement bitfield codegen (although I don't envy the person who 
implements it).  This also prevents a crash on code like that from PR2309
(it's still broken, but it fails more gracefully).

llvm-svn: 51285
2008-05-20 00:11:07 +00:00
Eli Friedman 8d0b976e7c Remove code that shouldn't have any effect anymore.
llvm-svn: 51284
2008-05-20 00:04:21 +00:00
Eli Friedman a3a4068949 Implement CodeGen for __builtin_memcpy.
llvm-svn: 51282
2008-05-19 23:27:48 +00:00
Eli Friedman f23b6fa41f Fix the emission of expressions like char a[10] = "asdf"; previously,
they were causing bad code to be emitted.  There are two fixes here: one 
makes sure we emit a string that is long enough, and one makes sure we 
properly handle string initialization in init lists.

llvm-svn: 51259
2008-05-19 17:51:16 +00:00
Eli Friedman f2442dcc8d Fix support for _Bool bitfields. The issue is that the bitfield width
used for _Bool is not the same as the primitive width (which for _Bool 
is 1 bit).  The load and store changes add some casts to make the 
types consistent.  The EmitLValue changes make sure that the pointer is 
of an appropriate type for loading the bitfield.

This isn't perfect, but it's an improvement, and getting everything 
right depends on actually laying out structs in an ABI-compliant way.

llvm-svn: 51224
2008-05-17 20:03:47 +00:00
Eli Friedman d5a4838e3d Backout of codegen-based fix to PR2334; this has been fixed differently
at the Sema layer.

llvm-svn: 51203
2008-05-16 20:38:39 +00:00
Nate Begeman 9800faa578 Fix some prototypes, and implement some builtins until we have our header files completed.
llvm-svn: 51199
2008-05-16 18:59:42 +00:00
Eli Friedman cb92a3f03b Patch for PR2334, and a similar ObjC bug.
llvm-svn: 51193
2008-05-16 17:37:11 +00:00
Nate Begeman 6c59132241 Handle a couple missing builtins that will go away eventually when the various
intrin.h files are finished

llvm-svn: 51137
2008-05-15 07:38:03 +00:00
Eli Friedman a1b4ed8003 Implementation of __builtin_shufflevector, a portable builtin capable of
expressing the full flexibility of the LLVM shufflevector instruction.  
The expected immediate usage is in *mmintrin.h, so that they don't 
depend on the mess of gcc-inherited (and not completely implemented)
shuffle builtins.

llvm-svn: 51113
2008-05-14 19:38:39 +00:00
Eli Friedman 9fd8b68568 Add codegen support for block-level compound literals.
llvm-svn: 51081
2008-05-13 23:18:27 +00:00
Eli Friedman dd7406e65c Add support for init lists for complex variables.
llvm-svn: 51080
2008-05-13 23:11:35 +00:00
Nate Begeman d386215916 Remove AST dependency on VMCore by switching ExtVectorElementExpr off Constant.
llvm-svn: 51068
2008-05-13 21:03:02 +00:00
Eli Friedman 1a5754a26a Detabify.
llvm-svn: 51042
2008-05-13 14:40:48 +00:00
Eli Friedman 6a7087e455 Emit basic block for switch body; fixes PR2307.
llvm-svn: 50968
2008-05-12 16:08:04 +00:00
Eli Friedman 6e31321043 Don't try to take the address of a bitfield; fixes PR2310.
llvm-svn: 50966
2008-05-12 15:06:05 +00:00
Mon P Wang b84407d6ec Added support to generate some atomic operators (add, sub, and, or etc..)
llvm-svn: 50919
2008-05-09 22:40:52 +00:00
Nate Begeman f322eabbce Extend vector member references to include {.hi, .lo, .e, .o} which return a
vector of the same element type and half the width, with the high, low, even,
and odd elements respectively.

Allow member references to member references, so that .hi.hi gives you the high
quarter of a vector.  This is fairly convenient syntax for some insert/extract
operations.

Remove some unnecessary methods/types in the ExtVectorElementExpr class.

llvm-svn: 50892
2008-05-09 06:41:27 +00:00
Sanjiv Gupta 15cb669039 Added -g command line options to clang for generating source level debug information. This patch currently enables generation of line number debug information (stoppoints) and region begin/end debug information. The new files CGDebugInfo.h and CGDebugInfo.cpp implements the debug info manager class CGDebugInfo.
llvm-svn: 50848
2008-05-08 08:54:20 +00:00
Chris Lattner b781dc79aa Add basic support for the pic-* target triples and add support for
targets that do not support recursion (and thus codegen stack variables
as globals).

Patch contributed by Alireza Moshtaghi!

llvm-svn: 50844
2008-05-08 05:58:21 +00:00
Devang Patel ac25fc6f2e Begin handling union bitfields.
Note, this is just beginning.

llvm-svn: 50835
2008-05-07 22:28:29 +00:00
Devang Patel 243d5cd283 Fix PR2101 - Codegen crash during bitfield initialization.
llvm-svn: 50769
2008-05-06 19:57:59 +00:00
Chris Lattner dbcc2ca6b2 simplify some builder calls.
llvm-svn: 50694
2008-05-06 00:56:42 +00:00
Chris Lattner 222c6123df remove a stray printout
llvm-svn: 50691
2008-05-06 00:44:00 +00:00
Chris Lattner 1e151816b2 use simplified API for making fp constants.
llvm-svn: 50623
2008-05-04 18:23:51 +00:00