Commit graph

57 commits

Author SHA1 Message Date
Luna
82878ef32c
Improve Objective-C support (#4777)
* WIP: Objective-C support

* Further work on implementation

* ObjC dynamic cast

* Add swift stub class attribute

* Classes, protocols and ivars

* Fix compilation issues

* Fix objc ir codegen

* Add objc linker option

* Add swift stub classref get ir gen

* Minor cleanup

* Fix objc link flag being added on non-darwin platforms

* Refactor objc gen

* remove use of std::nullopt

* Emit protocol tables

* Remove unused variable

* Formatting

* Fix build in release mode. Thanks for nothing, c++.

* Fix consistency

* Fix dynamic casts

* Fix tocall parentfd ref and arm msgsend call

* Make instance variables work

* Implicitly add isa pointer to objc classes.

* Fix protocol referencing & allow pragma mangle

* Fix protocol linkage

* Fix direct call support

* always generate var type for methods

* Fix test 16096a

* Fix extern ivar symbol gen, retain method decls

* Remove arm32 and x86 support

* Check method and ivar info before pushing to member list

* Make ObjcMethod info untyped.

* Make ivar and method gen more robust

* Generate optional protocol symbols

* Use bitcasting instead of creating multiple type defs

* Fix invalid protocol list struct gen

* More codegen robustness

* emit protocol table as const

* Make protocol table anon struct

* Fix callable type, generate protocol_list_t properly.

* Cast vthis to argtype

* Handle protorefs and classrefs properly

* seperate label ref and deref

* Fix method lookup

* Enable objective-c tests

* Enable objc_call_static test

* Scan both classes and protocols for method ref

* Enable objective-c tests on arm as well.

* supress objc linker warning in tests

* Fix class and protocol gen structure

* Fix objc_protocol_sections test

* ObjcMethod only get callee for functions with bodies

* Fix protocol class method gen

* Make ObjcMethod anon again

* Fix missing emit calls

* Fix classref gen

* Implement some of the requested changes

* Enable compilable tests

* Fix property selector gen, ugly hack for final funcs.

* Fix segfault in referencing fd->type

* Refactor implementation

* Fix null references in class and method lookup

* include unordered_map

* Get functionality on-par with prev impl.

* Fix super context calls

* Move -L-w flag to d_do_test and use IN_LLVM in objc.d/h

* add LDC version tag to -L-w flag

* Update CHANGELOG.md
2024-12-03 04:26:27 +01:00
Martin Kinkelin
b27a1e0076 Lazily define class *memory* IR type
To break remaining cycles in DtoType() - a class *ref* is an opaque
IR pointer nowadays.
2024-08-18 19:34:28 +02:00
Martin Kinkelin
3305549796 Get rid of cycles in DtoType()
Fixes #4734.
2024-08-18 19:34:28 +02:00
Martin Kinkelin
2c889146c3 Merge remote-tracking branch 'origin/master' into merge-2.110 2024-08-10 18:12:53 +02:00
Johan Engelen
74861179c5
AggrTypeBuilder: mark aggregate as packed when field offset is not naturally aligned, to fix #4719 (#4722) 2024-08-05 22:45:21 +00:00
Martin Kinkelin
c271cf9fae Merge remote-tracking branch 'origin/master' into merge-2.110 2024-07-19 17:54:45 +02:00
Martin Kinkelin
866be1e8cb
Fix bit field IR storage from weird integer to i8 array (#4708)
Fixes #4646.
2024-07-19 17:53:32 +02:00
Martin Kinkelin
c9ac30c236 Adapt to free-standing size(Type*) function 2024-07-16 16:22:35 +02:00
Martin Kinkelin
d6d79187e6 Merge fix: Adapt to removed error/warning members 2023-11-06 01:10:16 +01:00
Martin Kinkelin
78fdc135e4 Merge remote-tracking branch 'origin/master' into bitfields
Conflicts:
	gen/dvalue.cpp
	gen/llvmhelpers.cpp
	gen/structs.cpp
	gen/toir.cpp
	ir/irtypeaggr.cpp
2022-09-10 16:25:59 +02:00
Nicholas Wilson
78c37450d6
Change IrTypeAggr::getMemberLocation to indicate field of byte offest (#4110)
The previous API of returning two `unsigned`s was ambiguous when accessing the second member of a union that is the first member of a struct, where both output were set to zero.

It now returns one `unsigned` and an output `bool` to determine if it should be used as either a field or byte offset.
2022-09-04 16:02:00 +08:00
Martin Kinkelin
5f1f3ecc3b Support 'elaborate' bit fields
By merging consecutive bit fields to a group for as long as they share
storage bytes. This means that the new groups can contain members of
diverging byte offsets, requiring extra care.
2022-08-14 22:23:18 +02:00
Martin Kinkelin
d16fba3030 Rework packed-ness of IR aggregates
Base it on the IR alignments of the fields only.

Also fix the alignment of variables captured by ref (=> pointer
alignment, not the pointee's) and captured lazy params (=>
delegate alignment) in nested frames, something that cropped up with
a new assertion.
2022-08-14 14:54:27 +02:00
Martin Kinkelin
9dd4d5a2ab [assert that IR aggregate type sizes match the D size] 2022-08-06 15:11:48 +02:00
Martin Kinkelin
da4659386b Refactor & fix mapping of bit fields to IR types 2022-08-05 19:36:25 +02:00
Martin Kinkelin
91ab504554 Support bit fields in DtoIndexAggregate()
For read access only (returning an rvalue).
2022-08-04 15:04:44 +02:00
Martin Kinkelin
372d6b4983 [fix: handle unsized IR field types] 2022-08-04 00:29:25 +02:00
Martin Kinkelin
bd5fab1f06 WIP: Towards 'proper' IR field types for bit fields 2022-08-03 18:31:12 +02:00
Martin Kinkelin
aee1bedacb WIP: Bit fields 2022-08-01 20:25:39 +02:00
Martin Kinkelin
b7b8e59043 Upgrade frontend & libs to v2.100.0-beta.1+ (dlang/dmd@c0cff59c79) 2022-04-26 23:01:13 +02:00
Martin Kinkelin
8325df2035 [handle overlapping explicit initializers]
As the frontend unfortunately may generate those, e.g., for
compilable/interpret3.d.
2022-02-06 18:48:01 +01:00
Martin Kinkelin
183312a7b1 Simplify selection of IR fields for unions 2022-02-06 17:44:48 +01:00
Martin Kinkelin
65fe0cb9f2 Merge upstream stable (dlang/dmd@58e4db9880) 2021-10-18 17:50:28 +02:00
Martin Kinkelin
cb4104fc3e ImportC: Gracefully terminate when encountering C bit fields
Instead of ICE'ing; e.g., for dmd-testsuite's runnable/bitfields*.c.
See #3825.
2021-09-10 22:32:25 +02:00
Martin Kinkelin
079858f3b2 Upgrade frontend & libs to early v2.095.0 (dlang/dmd@a4274b3c39) 2020-11-27 17:45:13 +01:00
Martin Kinkelin
4ac7f0554b Adapt to frontend refactorings 2019-12-22 16:29:45 +01:00
Martin Kinkelin
4a23399236 Aim for consistent #includes (order + dir prefix)
I surely missed a few.
2018-10-20 16:19:46 +02:00
Martin
1822d54934 Fix packed struct layout regression (issue #2346)
I probably introduced this regression lately. Back then, I didn't
account for container aggregates, which require that the LL struct is
packed if the overall D aggregate alignment is lower than a field's
natural alignment.
2017-09-28 17:14:37 +01:00
kinke
ab37d5ba99 Fix issue #2235 - IR struct packedness (#2247)
Unnaturally aligned aggregates were potentially not marked as packed,
leading to LLVM inserting additional padding and screwing up the memory
layout.
2017-08-11 19:05:09 +02:00
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