Commit Graph

226 Commits

Author SHA1 Message Date
Richard Smith caf3390d44 Constant expression evaluation refactoring:
- Remodel Expr::EvaluateAsInt to behave like the other EvaluateAs* functions,
   and add Expr::EvaluateKnownConstInt to capture the current fold-or-assert
   behaviour.
 - Factor out evaluation of bitfield bit widths.
 - Fix a few places which would evaluate an expression twice: once to determine
   whether it is a constant expression, then again to get the value.

llvm-svn: 141561
2011-10-10 18:28:20 +00:00
John McCall f937c023bf Rename TagDecl::isDefinition -> isCompleteDefinition
for better self-documenting code, since the semantics
are subtly different from getDefinition().

llvm-svn: 141355
2011-10-07 06:10:15 +00:00
John McCall 0710e551ef Record layout requires not just a definition, but a complete
definition.  Assert this.  Change IR generation to not try to
aggressively emit the IR translation of a record during its
own definition.  Fixes PR10912.

llvm-svn: 141350
2011-10-07 02:39:22 +00:00
Daniel Dunbar 096ed290a1 Driver & AST: Implement support for -fpack-struct and -fpack-struct= command
line options.
 - <rdar://problem/10120602>, PR9631

llvm-svn: 141211
2011-10-05 21:04:55 +00:00
Eric Christopher 8a39a01a10 Fix doxygen comment.
llvm-svn: 141165
2011-10-05 06:00:51 +00:00
Eli Friedman 84d2d3a90e Some changes to improve compatibility for MSVC-style C++ struct layout. Patch from r4start at gmail.com (with some minor modifications by me).
llvm-svn: 140623
2011-09-27 19:12:27 +00:00
Ted Kremenek fed48af3de Don't emit -Wpadded warnings without a valid SourceLocation. This can happen when RecordLayoutBuilder is used by Codegen, not Sema.
llvm-svn: 139162
2011-09-06 19:40:45 +00:00
Douglas Gregor e8bbc12152 Extend the ASTContext constructor to delay the initialization of
builtin types (When requested). This is another step toward making
ASTUnit build the ASTContext as needed when loading an AST file,
rather than doing so after the fact. No actual functionality change (yet).

llvm-svn: 138985
2011-09-02 00:18:52 +00:00
Chad Rosier e1a6a0e05c Add support for using anonymous bitfields (e.g., int : 0) to enforce alignment.
This fixes cases where the anonymous bitfield is followed by a bitfield member.
E.g.,
struct t4
{
 char foo;
 long : 0;
 char bar : 1;
};

rdar://9859156

llvm-svn: 136991
2011-08-05 22:38:04 +00:00
Chad Rosier f01a7ddcd6 More whitespace and naming fixup. No functionality change.
llvm-svn: 136944
2011-08-04 23:34:15 +00:00
Chad Rosier 64b18eebc6 Fix style and remove obviously redundant code.
llvm-svn: 136907
2011-08-04 19:25:14 +00:00
Chad Rosier a336c6f380 Additional comments and whitespace.
llvm-svn: 136892
2011-08-04 17:52:43 +00:00
Chad Rosier 18903ee2d3 Add partial support for using anonymous bitfields (e.g., int : 0) to enforce
alignment.  This fixes cases where the anonymous bitfield is followed by a 
non-bitfield member.  E.g.,

struct t4
{
  int foo : 1;
  long : 0;
  char bar;
};

Part of rdar://9859156

llvm-svn: 136858
2011-08-04 01:21:14 +00:00
Chris Lattner 0e62c1cc0b remove unneeded llvm:: namespace qualifiers on some core types now that LLVM.h imports
them into the clang namespace.

llvm-svn: 135852
2011-07-23 10:55:15 +00:00
Jordy Rose a91768e569 Add a const overload for ObjCInterfaceDecl::all_declared_ivar_begin.
This was previously not-const only because it has to lazily construct a chain
of ivars the first time it is called (and after the chain is invalidated).
In practice, all the clients were just const_casting their const Decls;
all those now-unnecessary const_casts have been removed.

llvm-svn: 135741
2011-07-22 02:08:32 +00:00
Fariborz Jahanian b26d578b41 Eliminate most uses of ShallowCollectObjCIvars which requires
a vector for collection. Use iterators where needed instead.
// rdar://6817577

llvm-svn: 134015
2011-06-28 18:05:25 +00:00
Eli Friedman 300f55dcad PR10120: Make CodeGenModule::getVTableLinkage use NamedDecl::getLinkage to determine whether the vtable should be externally visible, instead of a rough approximation of it which messes up with templates.
While I'm here, zap the other user of isInAnonymousNamespace outside of Decl.cpp.

llvm-svn: 132861
2011-06-10 21:53:06 +00:00
Fariborz Jahanian 783243b3ca Implenment #pack pragma and ms_struct attribute layout.
Concludes // radar://8823265.

llvm-svn: 131188
2011-05-11 16:58:31 +00:00
Fariborz Jahanian 07ceb0a1a4 Support pack pragma and ms_struct attributes. // rdar://8823265
llvm-svn: 131142
2011-05-10 19:00:50 +00:00
Fariborz Jahanian 7adbed6b4d 'long long' requires special treatment in ms_struct
structs (impacts 32-bit only though).

llvm-svn: 131103
2011-05-09 22:03:17 +00:00
Fariborz Jahanian 307eace474 In ms_struct structs, Establish a new alignment for a
non-bitfield following a bitfield if size of their types differ.

llvm-svn: 131032
2011-05-06 22:42:22 +00:00
Fariborz Jahanian b7a2879677 Establish a new alignment for an ms_struct bitfield following
a non-bitfield if size of their types differ.

llvm-svn: 131023
2011-05-06 21:56:12 +00:00
Fariborz Jahanian 84335f7c8e More ms_struct bitfield stuff:
Adjacent bit fields are packed into the same 1-, 2-, or
4-byte allocation unit if the integral types are the same
size. // rdar://8823265.

llvm-svn: 130851
2011-05-04 18:51:37 +00:00
Fariborz Jahanian 759e4a1add Only the first zero-length bitfield decides alignment of
the followup data member in an ms_struct struct.
// rdar:// 8823265

llvm-svn: 130795
2011-05-03 22:07:14 +00:00
Fariborz Jahanian fc0fe6eb52 Finish off rules for z-length bitfields in ms_struct
structs. // rdar://8823265

llvm-svn: 130783
2011-05-03 20:21:04 +00:00
Fariborz Jahanian eb39741c0b More rule enforcement of zero bitfields for ms_struct.
llvm-svn: 130696
2011-05-02 17:20:56 +00:00
Fariborz Jahanian 595ec5d43c Some refactoring of my ms_struct patch.
// rdar://8823265 related.

llvm-svn: 130311
2011-04-27 17:14:21 +00:00
Fariborz Jahanian bcb23a180b With ms_struct attribut, Zero-length bitfields following
non-bitfield members are ignore. // rdar://8823265 wip

llvm-svn: 130257
2011-04-26 23:52:16 +00:00
Ted Kremenek 022dbc1672 Simplify crash recovery cleanup registration.
llvm-svn: 128057
2011-03-22 01:15:19 +00:00
Ted Kremenek f75d089679 Recover memory from RecordLayoutBuilders during crashes.
llvm-svn: 127931
2011-03-19 01:00:36 +00:00
Ken Dyck a1a2e8decb Instead of round up sizes to '8', round them up to the alignment of the char
type.

llvm-svn: 127391
2011-03-10 02:00:35 +00:00
Ken Dyck e73807538a Round up the non-virtual size to the next char instead of rounding down.
llvm-svn: 127390
2011-03-10 01:53:59 +00:00
Ken Dyck dbe37f38d0 Use CharUnits for TypeAlign variable in LayoutWideBitField(). No change in
functionality intended.

llvm-svn: 126730
2011-03-01 01:36:00 +00:00
Ken Dyck aab635e67a Change the return type of GetVirtualPointersSize() to CharUnits. No change
in functionality intended.

llvm-svn: 126727
2011-03-01 01:22:45 +00:00
Ken Dyck 1b4420ed42 Retry r126357. Use CharUnits for the Size and DataSize calculations when
they are known to be exact multiples of the width of the char type. Add a
test case to CodeGen/union.c that would have caught the problem with the
previous attempt. No change in functionality intended.

llvm-svn: 126628
2011-02-28 02:01:38 +00:00
Daniel Dunbar 30cdc7022b Revert "Use CharUnits values for Size and DataSize outside of the bitfield
layout", it broke some GCC tests.

llvm-svn: 126386
2011-02-24 16:40:53 +00:00
Ken Dyck 8e74e79145 Use CharUnits values for Size and DataSize outside of the bitfield layout
methods, when they are known to be exact multiples of the width of the char
type. 

llvm-svn: 126357
2011-02-24 02:12:14 +00:00
Ken Dyck 3c215f2fd1 Use Context.getCharWidth() in place of literal '8's in assertions.
llvm-svn: 126356
2011-02-24 01:33:05 +00:00
Ken Dyck ecfc75529f Make the Size and DataSize members more CharUnits-friendly by wrapping them
with getter and setter methods in both bit units and CharUnits. This will help
simplify some of the unit mismatch in the parts of the code where sizes are
known to be exact multiples of the width of the char type.

Assertions in the getters help guard against accidentally converting to
CharUnits when sizes are not exact multiples of the char width.

llvm-svn: 126354
2011-02-24 01:13:28 +00:00
Ken Dyck 6d90e8937c Expand use of CharUnits in LayoutField(). No change in functionality
intended.

llvm-svn: 126066
2011-02-20 02:06:09 +00:00
Ken Dyck 85ef0431a7 Expand use of CharUnits for alignments further. No change in functionality
intended.

llvm-svn: 126034
2011-02-19 18:58:07 +00:00
Ken Dyck 02ced6fd19 Convert MaxFieldAlignment to CharUnits from bits. No change in functionality
intended.

llvm-svn: 125704
2011-02-17 01:49:42 +00:00
Ken Dyck 1300b3b357 Convert the UnpackedAlignment field to CharUnits from bits. No change in
functionality intended.

llvm-svn: 125643
2011-02-16 02:11:31 +00:00
Ken Dyck 4731d5b65a Convert Alignment member to CharUnits from bits. No change in functionality
intended.

llvm-svn: 125641
2011-02-16 02:05:21 +00:00
Ken Dyck af1c83fbe7 Convert NonVirtualSize to CharUnits from bits. No change in functionality
intended.

llvm-svn: 125639
2011-02-16 01:52:01 +00:00
Ken Dyck a2d3dda041 Convert NonVirtualAlignment to CharUnits. No change in functionality
intended.

llvm-svn: 125638
2011-02-16 01:43:15 +00:00
Ken Dyck 7ad11e70b6 Convert RecordLayout::Alignment to CharUnits from bit units. No change in
functionality intended. 

llvm-svn: 125549
2011-02-15 02:32:40 +00:00
Ken Dyck d5090c16f8 Convert RecordLayout::DataSize to CharUnits from bits, eliminating two
unnecessary calls to RoundUpToAlignment. No changes to functionality
intended.

llvm-svn: 125356
2011-02-11 02:20:09 +00:00
Ken Dyck b0fcc59e19 Add a helper function, ASTContext::toBits(), that converts sizes in
CharUnits to sizes in bits, and use it to tidy up the places where the
conversion was done explicitly.

llvm-svn: 125332
2011-02-11 01:54:29 +00:00
Ken Dyck c8ae55050d Convert RecordLayout::Size to CharUnits from bits. No changes to
functionality intended.

llvm-svn: 125156
2011-02-09 01:59:34 +00:00