Commit graph

28 commits

Author SHA1 Message Date
Johan Engelen
c1b08f1fe6 Order initializations according to how they will happen at runtime. [NFC] 2016-11-08 11:30:22 +01:00
Martin
0fda2d271f Fix dynamic initialization of unions
The front-end fills in missing init expressions (except for the nested
context pointer in most cases), so there are no implicitly initialized
fields for dynamically initialized struct literals.

The front-end is also supposed to make sure there are no overlapping
initializers by using null-expressions for overridden fields, but doesn't
in some cases (DMD issue 16471).
Instead of preferring the first one in lexical field order, now use the
lexically last one to mimic DMD.

The previous code iterated over the fields in lexical order and ignored
the initializer for a field if there were earlier declared fields with
greater offset (and an initializer expression), which is wrong for
anonymous structs inside a union:

union {
  struct { int i1;            long l = 123; }
  struct { int i2; int x = 1;               }
}

`x` was previously initialized with 0 (treated as padding).
2016-10-25 01:06:44 +02:00
Martin
e6537ba4dc Fix union layout and initialization
By refactoring IrAggr::addFieldInitializers() and making it use an
extended and refactored AggrTypeBuilder::addAggregate().

AggrTypeBuilder::addAggregate() can now optionally detect alias fields
in unions (same offset and LL type as a dominant union field) and add
those to the variable-to-GEP-index mapping.
These alias fields can then be indexed directly with a GEP instead of
resorting to casting the pointer and applying the byte offset.
2016-10-22 01:40:54 +02:00
Johan Engelen
29ce4012af dmd2 --> ddmd. Merge (almost all of) our changes to dmd source into the new D source of dmd 2.069.2.
Also adds the CMake infrastructure to compile and link the D source files.

The build is partially broken:
- A few files in Phobos and druntime do not build
- MSVC build is broken because of unresolved symbols involving reals
2016-01-28 19:03:58 +01:00
David Nadlinger
9df487edff gen/ir: clang-tidy the world 2015-11-02 11:30:40 +02:00
David Nadlinger
44b0f7b615 driver/gen/ir: clang-format the world
This uses the LLVM style, which makes sense for sharing code
with other LLVM projects. The DMD code we use will soon all
be in D anyway.
2015-11-02 00:28:01 +02:00
Martin
52532985a9 IR source directory: use C++11 inline-initialization in headers 2015-11-01 19:30:04 +01:00
Martin
60d676e2a1 Drop support for LLVM < 3.5
This allows to clean up the code a little.
2015-10-30 22:24:05 +01:00
Martin
310ad102d7 Don't use DtoAlignment() when determining if a struct is packed
We need the type's natural alignment for that.
2015-10-19 21:21:00 +02:00
Martin
93158caca8 Respect alignments of captured variables when building nested context LL struct 2015-10-18 23:25:37 +02:00
Martin
05c10d9107 Introduce DtoAlignment() and overload DtoAlloca() for VarDeclarations
Trying to get the alignment right by using the first non-default one
in the following order of descending priority:

VarDeclaration::alignment [variables only of course]
Type::alignment()
Type::alignsize()

This fixes `align(x) struct S { ... }`.
2015-10-18 14:38:09 +02:00
Martin
b13565c17e Refactor common i1ToI8(voidToI8(DtoType(...))) code occurrences 2015-10-03 22:58:00 +02:00
David Nadlinger
ffb88adf93 Removed another (benign?) instance of storing an i1 as i8 2015-09-14 12:53:02 +02:00
David Nadlinger
613781b13f Fix alignment of interface info in class with align(1) members
GitHub: Fix #1058.
2015-09-02 19:14:14 +03:00
David Nadlinger
63ca3c7eb4 Always zero struct padding as required by TDPL
We already generated the memsets for zeroing the padding,
but because we relied on the native LLVM type allignment
where possible instead of generating explicit padding
values, LLVM did not always copy those bytes around (e.g.
when spilling/reloading registers).
2015-08-10 20:49:30 +02:00
Kai Nacke
cf1d792582 Use a byte array for padding of unions/structs.
The previous approach was to add i64, i32, i16, i8 members depending
on alignment and required space. This seems to cause several problems.
Solution is to use a byte array. This makes to code more compact, too.

Fixes issue #989.
2015-07-12 12:52:14 +02:00
David Nadlinger
c65faeabaf Fix struct alignment padding type selection
GitHub: Fixes #944.
2015-05-29 01:11:58 +02:00
kai
ed6e0a4ac7 LLVM 3.7: Fix IrTypeAggr() constructor. 2015-03-06 21:24:49 +01:00
kai
0449b26744 Fix for issue #841.
The `union` is not created as packed type. This seems to create problems with the default initializer:

    struct Foo
    {
        static union Bar
        {
            bool b;
            ulong l;
        }

        Bar bar;
    }

    static this()
    {
        Foo foo = Foo();
    }

creates an error. If you change the order inside the union

        static union Bar
        {
            ulong l;
            bool b;
        }

then the code works.

Also cleans up the creation of the additonal zeroes for the initializer.
2015-02-28 18:52:56 +01:00
kai
024b14cd7f Fix some warnings.
These are easy to solve and reduce the noise in the Travis build.
2014-12-26 15:59:23 +01:00
kai
1c18d5825e Fix for issue #809.
If there are gagged errors then `fatal()` is called in `irtypeaggr.cpp/AggrTypeBuilder::addAggregate()`.
In this case `fatal()` should only be called is there is no error gagging and an overlapping initialization
has been detected.
2014-12-16 21:09:01 +01:00
Alexey Prokhin
9314fc1c1c Fix issue 726: Wrong alignment for struct fields on x86_64/amd64 2014-10-11 18:12:11 +04:00
Alexey Prokhin
0b180be099 [cleanup] Merge common code in IrTypeStruct::get() and IrTypeClass::addBaseClassData() 2014-10-11 17:58:18 +04:00
David Nadlinger
bff766b379 Track member field index in IrTypeAggr, not IrField.
This fixes a regression introduced in caa2f15c8a. The IrDsymbol
metadata is obviously reset in between modules, while IrTypes
are not. Thus, we can never set symbol metadata when resolving
types, as the symbol data will be wrong in all modules following
the one where the type was first resolved.

GitHub: Fixes #739.
2014-10-11 03:28:49 +02:00
David Nadlinger
9700d84132 Initialize IrTypeAggr members in order to silence warning. 2013-06-17 02:38:38 +02:00
David Nadlinger
a0ffaf56bf Do not codegen aggregate types from within debug info generation.
This avoids problems where we would codegen children of an
"inner" template instantiation (i.e. a member of a non-template
aggregate in another module) because we have no way to know the
outer (declare-only) entity exists in the respective
mustDefineSymbol invocation.

An example for this are the std.typecons.RefCounted internals of
std.file.DirIterator, as used from std.datetime and other modules.
This is not only inefficient, but also causes linking issues due
to attribute inference for these functions not having run yet
(and consequently the mangled name being different from the
actual definition).
2013-06-16 19:33:04 +02:00
David Nadlinger
9a016a1002 Refactor struct initializers codegen.
This not only reduces code duplication, but the unification
also enables code a la StructLiteralExp to handle classes
(for CTFE class constant support in 2.063).
2013-06-12 20:16:05 +02:00
David Nadlinger
2cebe6408c Divided ir/irtypestruct.* in general aggregate and struct specific part.
This is just to improve clarity, as it was rather non-obvious
what of the code also applied to classes before.

IrTypeAggr::createInitializerConstant would currently belong in
IrTypeStruct, but this will be refactored anyway.
2013-06-12 17:17:09 +02:00