Commit Graph

67 Commits

Author SHA1 Message Date
Douglas Gregor 6ec47f0d59 Silence a warning about an unused variable in -Asserts builds
llvm-svn: 64306
2009-02-11 16:17:49 +00:00
Eli Friedman 1f90fe17f9 Fix for PR3447: use padded sizes for computations on struct/union
constants.

llvm-svn: 63491
2009-02-01 08:12:19 +00:00
Anders Carlsson 02714ed353 Implement constant generation of ImplicitValueInitExprs.
llvm-svn: 63379
2009-01-30 06:13:25 +00:00
Douglas Gregor 0202cb406e Introduce a new expression node, ImplicitValueInitExpr, that
represents an implicit value-initialization of a subobject of a
particular type. This replaces the (ab)use of CXXZeroValueInitExpr
within initializer lists for the "holes" that occur due to the use of
C99 designated initializers.

The new test case is currently XFAIL'd, because CodeGen's
ConstExprEmitter (in lib/CodeGen/CGExprConstant.cpp) needs to be
taught to value-initialize when it sees ImplicitValueInitExprs.

llvm-svn: 63317
2009-01-29 17:44:32 +00:00
Douglas Gregor 5169570e28 Clean up designated initialization of unions, so that CodeGen doesn't
have to try to guess which member is being initialized.

llvm-svn: 63315
2009-01-29 16:53:55 +00:00
Douglas Gregor 17bd094a6b Improvements to code-generation and semantic analysis of designated
initializers.

  - We now initialize unions properly when a member other than the
    first is named by a designated initializer.
  - We now provide proper semantic analysis and code generation for
    GNU array-range designators *except* that side effects will occur
    more than once. We warn about this.

llvm-svn: 63253
2009-01-28 23:36:17 +00:00
Daniel Dunbar f50e60b23a Implement basic _Complex integer constant folding.
- Merged into single ComplexEvaluator, these share too much logic to
   be worth splitting for float/int (IMHO). Will split on request.

llvm-svn: 63248
2009-01-28 22:24:07 +00:00
Douglas Gregor 347f7eabb9 Code generation support for C99 designated initializers.
The approach I've taken in this patch is relatively straightforward,
although the code itself is non-trivial. Essentially, as we process
an initializer list we build up a fully-explicit representation of the
initializer list, where each of the subobject initializations occurs
in order. Designators serve to "fill in" subobject initializations in
a non-linear way. The fully-explicit representation makes initializer
lists (both with and without designators) easy to grok for codegen and
later semantic analyses. We keep the syntactic form of the initializer
list linked into the AST for those clients interested in exactly what
the user wrote.

Known limitations:
  - Designating a member of a union that isn't the first member may
    result in bogus initialization (we warn about this)
  - GNU array-range designators are not supported (we warn about this)

llvm-svn: 63242
2009-01-28 21:54:33 +00:00
Eli Friedman cf2b7ba4a7 Get rid of some code that should be unnecessary.
llvm-svn: 62950
2009-01-25 02:10:46 +00:00
Eli Friedman c69d454d5a Make the constant folder aware of
__builtin___CFStringMakeConstantString.  (We get into trouble in 
GenerateStaticBlockVarDecl if the constant folder isn't accurate.)

llvm-svn: 62949
2009-01-25 01:54:01 +00:00
Eli Friedman 529a99bcf4 Fix the address of a label to be properly considered and emitted as a
constant.

llvm-svn: 62948
2009-01-25 01:21:06 +00:00
Chris Lattner 096d3ecb51 remove dead code.
llvm-svn: 62930
2009-01-24 20:24:49 +00:00
Nate Begeman 1e31b168fa Add support for vectors to APValue. Vector constant evaluator and tests coming.
llvm-svn: 62438
2009-01-18 01:01:34 +00:00
Nuno Lopes 4d78cf0fa7 add support for usage of cast to union thing with static vars
llvm-svn: 62387
2009-01-17 00:48:48 +00:00
Daniel Dunbar 62db95e891 (LLVM up) Match TargetData API change in LLVM TOT.
llvm-svn: 62101
2009-01-12 21:08:18 +00:00
Douglas Gregor c7acfdfe9a Add QualifiedDeclRefExpr, which retains additional source-location
information for declarations that were referenced via a qualified-id,
e.g., N::C::value. We keep track of the location of the start of the
nested-name-specifier. Note that the difference between
QualifiedDeclRefExpr and DeclRefExpr does have an effect on the
semantics of function calls in two ways:
  1) The use of a qualified-id instead of an unqualified-id suppresses
     argument-dependent lookup
  2) If the name refers to a virtual function, the qualified-id
  version will call the function determined statically while the
  unqualified-id version will call the function determined dynamically
  (by looking up the appropriate function in the vtable).

Neither of these features is implemented yet, but we do print out
qualified names for QualifiedDeclRefExprs as part of the AST printing.

llvm-svn: 61789
2009-01-06 05:10:23 +00:00
Douglas Gregor 2eedc3aa1c Add support for member references (E1.E2, E1->E2) with C++ semantics,
which can refer to static data members, enumerators, and member
functions as well as to non-static data members.

Implement correct lvalue computation for member references in C++. 
Compute the result type of non-static data members of reference type properly.

llvm-svn: 61294
2008-12-20 23:49:58 +00:00
Chris Lattner b4396f40a0 add codegen support for __func__ and friends, producing the same
output that GCC does.  rdar://6440297

llvm-svn: 60922
2008-12-12 05:18:02 +00:00
Douglas Gregor 91f84216f7 Unifies the name-lookup mechanisms used in various parts of the AST
and separates lexical name lookup from qualified name lookup. In
particular:
  * Make DeclContext the central data structure for storing and
    looking up declarations within existing declarations, e.g., members
    of structs/unions/classes, enumerators in C++0x enums, members of
    C++ namespaces, and (later) members of Objective-C
    interfaces/implementations. DeclContext uses a lazily-constructed
    data structure optimized for fast lookup (array for small contexts,
    hash table for larger contexts). 

  * Implement C++ qualified name lookup in terms of lookup into
    DeclContext.

  * Implement C++ unqualified name lookup in terms of
    qualified+unqualified name lookup (since unqualified lookup is not
    purely lexical in C++!)

  * Limit the use of the chains of declarations stored in
    IdentifierInfo to those names declared lexically.

  * Eliminate CXXFieldDecl, collapsing its behavior into
    FieldDecl. (FieldDecl is now a ScopedDecl).

  * Make RecordDecl into a DeclContext and eliminates its
    Members/NumMembers fields (since one can just iterate through the
    DeclContext to get the fields).

llvm-svn: 60878
2008-12-11 16:49:14 +00:00
Anders Carlsson 38eef1de6c Change more code over to using the new Expr::Evaluate
llvm-svn: 60323
2008-12-01 02:42:14 +00:00
Anders Carlsson 9f77f60620 Remove the #ifdeffed out code.
llvm-svn: 60032
2008-11-25 17:10:10 +00:00
Anders Carlsson 20e11f8fc8 Use tryEvaluate for constant exprs.
llvm-svn: 59857
2008-11-22 02:34:39 +00:00
Eli Friedman dcbcbb827d A few corrections to the expr constant work. Not enabled at the
moment.

llvm-svn: 59435
2008-11-17 03:57:28 +00:00
Anders Carlsson 4425d8e37b More expr constant work. (Off by default).
llvm-svn: 59433
2008-11-17 01:58:55 +00:00
Chris Lattner 67d7b9204c rename Expr::tryEvaluate to Expr::Evaluate.
llvm-svn: 59426
2008-11-16 21:24:15 +00:00
Anders Carlsson 430887742e More constant expr work.
llvm-svn: 59405
2008-11-16 06:23:45 +00:00
Anders Carlsson ee0d90fe30 Check in code that uses tryEvaluate for emitting constant exprs (not used yet).
llvm-svn: 59375
2008-11-15 20:45:50 +00:00
Anders Carlsson c9dacf4fdd Use IgnoreParenCasts. No functionality change.
llvm-svn: 59371
2008-11-15 18:52:06 +00:00
Sebastian Redl 6f28289aca Introduce a single AST node SizeOfAlignOfExpr for all sizeof and alignof expressions, both of values and types.
llvm-svn: 59057
2008-11-11 17:56:53 +00:00
Chris Lattner 084bc32e0d make codegen reject initializes with designators, like this:
t.c:1:13: error: cannot codegen this designators yet
int a[10] = {2, 4, [8]=9, 10};
            ^~~~~~~~~~~~~~~~~

llvm-svn: 58220
2008-10-26 23:53:12 +00:00
Douglas Gregor 5251f1b283 Preliminary support for function overloading
llvm-svn: 57909
2008-10-21 16:13:35 +00:00
Chris Lattner 5d3e26a4f6 silence release-assert warnings.
llvm-svn: 57392
2008-10-12 00:31:50 +00:00
Chris Lattner a97132a9c4 Make sema and codegen allow __builtin___CFStringMakeConstantString as a valid
constant lvalue.  Implement this in codegen by moving the code out of CGBuiltin
into EmitConstantExpr.

llvm-svn: 57163
2008-10-06 07:26:43 +00:00
Chris Lattner e50e90142e instead of making codegen try to know about all of the builtins to generate
constants for them, just use the constant evaluator to do the job.  This
also fixes crashes on 'unknown constant builtins'.

llvm-svn: 57155
2008-10-06 05:59:01 +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
Argyrios Kyrtzidis ce4528f008 Add CodeGen support for CXXZeroInitValueExpr.
llvm-svn: 55249
2008-08-23 19:35:47 +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 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 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 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 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
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 ad319a73f2 More #include cleaning
- Remove internal uses of AST.h

llvm-svn: 54628
2008-08-11 05:00:27 +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
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 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
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