Commit graph

52 commits

Author SHA1 Message Date
Tim Schendekehl
845adf8e3c Fix bugzilla 24661 - wctype_t and wctrans_t are platform-dependent
The previous definitions are left as the default. They could still
be wrong on some other platforms.
2024-07-13 18:51:42 +02:00
Tim Schendekehl
5f4002ba5e
Fix bugzilla 24660 - atomic_wchar_t has wrong size on Posix (#16688) 2024-07-13 18:46:13 +02:00
Tim Schendekehl
67996abdc9
Compare type sizes in druntime with ImportC (#16571)
Types for bindings of C libraries in druntime need to match the
C headers. Small differences can result in hard to debug problems.

This test tries to automatically find types with a wrong size.
This is done by also getting type sizes from C headers using ImportC
and comparing them. Differences between the sizes can have different reasons:
* Bugs in ImportC (e.g. for bitfields) can result in a wrong size
* Type definitions in druntime can be wrong
* Different preprocessor options could be used, like _FILE_OFFSET_BITS
* Size differences can be fine, because some structs contain a member
    for the size or a version

Members of structs and unions with the same name are also compared.
For types with potential problems a comparison of the layout is printed.

The test contains a list of known problems, which are only treated as
warnings and not errors.
2024-07-08 10:39:36 +08:00
Iain Buclaw
9ca85e493d Merge remote-tracking branch 'upstream/stable' into merge_stable 2024-05-27 09:41:18 +00:00
Martin Kinkelin
801ad02294 druntime: Streamline make clean for integration tests
The 22 integration tests came with a mix of removing only ROOT
(generated/OS/BUILD/MODEL) or GENERATED (generated) subdirs as
part of their `make clean`.

And running `make clean` in the druntime dir only cleaned up the
default BUILD=release variant, while running `make unittest` without
explicit BUILD type includes running the integration tests in both
debug and release variants.

Streamline/fix this to always cleaning up ROOT, and running `make clean`
in both variants when running druntime's `make clean`.
2024-05-25 22:56:15 +02:00
Johan Engelen
673ddf38bc
Only test druntime exceptions gdb test case (rt_trap_exceptions_drt_gdb) when gdb is available. (#16513) 2024-05-20 06:17:23 +08:00
Steven Schveighoffer
aec16d889c
Remove the interface function fullCollectNoStack from the gcinterface (#16401)
* Remove the interface function fullCollectNoStack from the gcinterface

* Fix tests that depend on the GC not scanning the stack.

* Remove all nostack remnants

* Add changelog entry
2024-04-23 15:06:21 +08:00
Iain Buclaw
53cd4b7c30 Merge remote-tracking branch 'upstream/stable' into merge_stable 2024-03-01 23:11:59 +00:00
Iain Buclaw
6f2a6f919d Fix Bugzilla 23517 - dmd with -g flag fails to link on macOS with unaligned pointer 2024-02-22 14:52:34 +01:00
Rainer Schuetze
aca5ba63b0 pass -visibility=public for SHARED=1 2024-02-08 00:13:08 +01:00
Martin Kinkelin
29aecdd375 [nits after rebase] 2024-02-04 15:50:50 +01:00
Rainer Schuetze
e2a5c72a74 test/shared for windows:
- add -visibility=public when building DLLs
- use -dllimport=all to simplify building exe
- enable tests link linkD linkDR loadDR
2024-02-04 10:49:55 +01:00
Martin Kinkelin
2f8041fff5 druntime: Prepare test/shared/Makefile for broader Windows support 2024-02-04 10:49:54 +01:00
Martin Kinkelin
520240e312 druntime: Prepare test/shared source files for Windows support
Upstreaming from LDC.
2024-02-04 10:48:47 +01:00
Rainer Schuetze
eafad1d5ea shared runtime: basic exception support for Win64 2024-01-06 11:28:01 +01:00
Rainer Schuetze
2f9921d102 version shared runtime hooks on DigitalMars
add missing runtime termination of exe image
2024-01-05 17:26:34 +01:00
Rainer Schuetze
174f0cc0c3 fix link/lib test
- run checks in release builds, too
- side effects in assert() never executed in release builds
- respect different termination order on windows
2024-01-04 10:25:43 +01:00
Rainer Schuetze
1f4e7217e1 fix issue 4071: improve support for shared runtime
- register module info of clients and run module ctors/dtors
- register .data section of clients with the GC
2024-01-03 11:50:56 +01:00
Rainer Schuetze
95f4ad91a3 move PATH modification to makefile to allow running both debug and release unittests 2024-01-03 11:50:55 +01:00
Rainer Schuetze
f9a2557c72
fix issue 4071 and others: shared runtime DLL for Windows (#14849)
Allow exporting all generated symbols (including internal symbols).
Implement switch `-dllimport` ( windows only, not restricted to `extern(D)`)

Still to do:
* running shared module ctors
* running thread local module ctors
* registering DATA/TLS ranges with the GC
* exceptions
2023-12-31 05:26:57 +08:00
Tim Schendekehl
b53341ab91 Fix issue 24298 - cpp_delete should check for null
The delete operator in C++ can be called with a null pointer and
ignores it. This commit makes cpp_delete consistent with C++, so null
pointers are also ignored.
2023-12-22 22:45:08 +01:00
Martin Kinkelin
f3a0366f4f druntime: Avoid -run in Windows-specific additional tests
As temporary object files seem to collide for parallel runs in the
same working dir.
2023-12-18 07:29:32 +08:00
Martin Kinkelin
e030a5ff55 druntime: Slightly simplify test/{uuid,valgrind} Makefiles
By disabling them in druntime/Makefile on unsupported platforms.
2023-12-18 07:29:32 +08:00
Martin Kinkelin
ef8db98dcd druntime: Merge test/shared/win64.mak into Makefile 2023-12-18 07:29:32 +08:00
Martin Kinkelin
28cbd2fe8f druntime: Merge test/stdcpp/win64.mak into Makefile 2023-12-18 07:29:32 +08:00
Martin Kinkelin
b99b9d2c20 druntime: Make most *test* Makefiles usable on Windows too
Still to do: `test/{shared,stdcpp}`.
2023-12-18 07:29:32 +08:00
Denis Feklushkin
554f822d4b
druntime/test/*.mak: replaces -Isrc by -Iimport (#15881)
* druntime/test/*.mak: Replace -Isrc by -Iimport

* Fix Windows tests build: rt/tlsgc.d is not in import/ dir

---------

Co-authored-by: Denis Feklushkin <feklushkin.denis@gmail.com>
2023-12-04 12:24:07 +02:00
Iain Buclaw
7afce7f466 Merge remote-tracking branch 'upstream/stable' into merge_stable 2023-11-20 10:03:05 +01:00
Teodor Dutu
055accfbe6
Translate _d_newarray{mTX, miTX, Op} to a single template (#15819)
- Move code for `_d_newarraymTX` to `core.internal.array.construction`
- Remove `_d_newarraymiTX` and `_d_newarraymOp`
- Add unittests for `_d_newarraymTX`
- Move lowering to `_d_newarraymTX` to the semantic phase
- Inline the lowering when inlining `NewExp`s
- Add changelog entry about the new hook

Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
2023-11-17 09:57:30 +02:00
Steven Schveighoffer
084eed696e
Fix static AA initialization (#15744)
* Fix static associative array initialization to always use hashOf at
runtime. We do this by storing the hash function in the Impl instead of
using the passed-in TypeInfo for the key.
2023-11-02 18:41:35 +08:00
Teodor Dutu
fcff1b51ba
Translate _d_newarray{U,iT,T} to a single template (#15299)
* druntime: Copy array allocation functions to `core.internal.array.utils`

This copies `__setArrayAllocLength()`, `__arrayAlloc()` and moves
`__arrayStart()` and `__arrayClearPad()` to
`core.internal.array.utils.d`. This is needed because `_d_newarrayT()`
calls these functions from `rt.lifetime.d`, but the file cannot be
imported from `core.internal.array.creation.d`.

Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>

* Translate `_d_newarray{U,iT,T}` to a single template

This achieves the following:
- Convert `_d_newarray{U,iT,T}` to a single template `_d_newarrayT` that
handles arrays of elements that either have an init symbol or are
zero-initialised.
- Move compiler lowering to the semantic phase
- Store lowered expression in `NewExp.lowering`

Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>

---------

Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
2023-10-24 10:44:55 +03:00
Iain Buclaw
cd1bbd4733 Fix broken tests caused by merge conflicts 2023-07-15 14:21:45 +00:00
Iain Buclaw
4dccb4aa5d Merge remote-tracking branch 'upstream/stable' into merge_stable 2023-07-15 13:45:11 +00:00
Vladimir Panteleev
aef22a7b22
Fix Issue 23890 - "Warning: cannot inline function" in core.lifetime (#15186)
* Fix Issue 23890 - "Warning: cannot inline function" in core.lifetime

* druntime/test/profile: Divorce test from exact Druntime source numbers

Allow lines to move around in core/lifetime without affecting this test.
2023-07-06 12:20:15 +03:00
Vladimir Panteleev
7cdae6e3bb
Add Valgrind GC integration (#15304)
* rt.minfo: Avoid calling realloc with size 0

This is not portable, and memcheck complains about this.

* Add C Valgrind API

Add the BSD-licensed C header files which provide the API for
controlling Valgrind from within programs executed under it.

The files are from Valgrind v3.21.0.

* Add some D bindings for the Valgrind C API

We will use these in the GC implementation to tell Valgrind which
memory operations are OK or not.

* Silence Valgrind warnings caused by GC marking

Allow the conservative GC to scan memory, whether it has been
initialized by the application or not.

* Add test suite for Valgrind

* Unify VALGRIND with MEMSTOMP

The two share the same goal: mark memory which should not be accessed
any more.

* Mask "invalid" access to free lists

The GC stores free lists in the cells of the objects on the list.

We would like to allow the GC to work with these lists, but still
raise a warning if application code attempts to access them.

* Distinguish between writable and unwritable invalidation

Freshly allocated memory should be writable but not readable.

Explicitly deallocated or GC-ed memory should be neither readable or
writable.

* Add use-after-free test

* Invalidate freshly-allocated memory

* Integrate VALGRIND with SENTINEL

* Fix reporting of arrays of structs with destructors

* Re-invalidate reused blocks during malloc/calloc

* Add Changelog entry

* .pre-commit-config.yaml: Exempt vendored files

* etc.valgrind.valgrind: Propagate return values of the vbits functions

* etc.valgrind.valgrind: Add documentation for functions

Copy/adapt the documentation in memcheck.h.

* druntime/test/valgrind: Add no_use_after_gc test

* ci/cirrusci.sh: Install Valgrind on Linux

Run the Druntime Valgrind integration tests.

libc6-dbg is needed to allow Valgrind to redirect certain functions.

* etc.valgrind.valgrind: Add @nogc

Although the GC is the primary user, this is not a restriction of
these Valgrind API wrappers.

* druntime/test/valgrind: Fix no_use_after_gc test with -release

Trick the optimizer to pretend we're doing something with the result
of those invalid memory accesses.
2023-06-15 01:01:42 -07:00
Teodor Dutu
159a8801a0
Translate _d_newitem{U,T,iT} to a single template (#14664)
This makes the following changes:
- Replace `_d_newitem{U,T,iT}` with a template `_d_newitemT` that
allocates memory for the new `struct` and performs the required
initialisation
- Move lowering call to `_d_newitemT` from e2ir.d to expressionsem.d
- Add `lowering` field to `NewExp` that contains the lowered call and
use it in e2ir.d
- Remove `_d_newitem{,i}T` from rt.lifetime

Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
2023-05-12 11:29:10 +03:00
Rainer Schuetze
ca016bd979
fix issue 23859 - [REG 2.103] Throwing while in a deep callstack causes memory corruption (#15127)
avoid writing beyond the end of the trace buffer
2023-04-25 22:32:16 +03:00
Iain Buclaw
bee392689d Fix tests broken by divergent changes in stable 2023-03-01 19:02:48 +00:00
Iain Buclaw
a2157f073c Merge remote-tracking branch 'upstream/stable' into merge_stable 2023-03-01 18:01:11 +00:00
Martin Kinkelin
a54fbab882
[stable] druntime: Fix InvalidMemoryOperation error on Windows when throwing exceptions from finalizers (#14901)
* Fix Issue 23731 - InvalidMemoryOperation error on Windows when throwing exceptions from finalizers

A v2.102 regression, which newly enabled `StackTrace` constructions
from within GC finalizers. The construction is `@nogc`, but
apparently depends on the `typeid(StackTrace)` monitor having been
allocated already, i.e., a previous `StackTrace` construction.

So pre-allocate a dedicated `Mutex` in the module constructor to
make the `StackTrace` construction really `@nogc`.
`druntime/test/allocations/src/alloc_from_assert.d` then passes on
Windows again (not tested by DMD, but by LDC).

While at it, also prevent `InvalidMemoryOperation` errors when trying
to print exceptions within finalizers - by not resolving anything
(=> empty printed trace), as resolving currently heavily depends on
the GC.

* [work around cyclic modules dependency...]

* druntime: Test test/allocations/src/alloc_from_assert.d on Windows too

As it regressed with v2.102.
2023-02-22 11:17:24 +02:00
Iain Buclaw
29b1efa0c4 Merge remote-tracking branch 'upstream/stable' into merge_stable 2023-02-21 23:52:41 +00:00
Martin Kinkelin
a9eedfe405
druntime: Fix up cpp_demangle subtest of exceptions integration tests (#14894)
* Don't run the test in release mode on Linux; just like for the other
  Posix targets.
* Include `-L--export-dynamic` as required dflag (added implicitly to cc
  linker cmdline by DMD, but not by LDC), which is required for symbol
  resolution in druntime exception backtraces.
2023-02-19 17:56:30 +08:00
Iain Buclaw
a59e38a7bd druntime: Match either _Dmain or D main 2023-01-30 00:15:07 +01:00
Teodor Dutu
276ef2145b
Translate _d_newclass to a template (#14837)
This makes the following changes:
- Add template `_d_newclassT` to `druntime.src.core.lifetime.d`
- Replace lowering of `new C()` to `_d_newclassT!C()`
- Add `lowering` member to `NewExp`. This field stores the above
lowering to be used by e2ir.d
- Keep the old `_d_newclass` hook because it's used by
`TypeInfo_Class.create()`
- Add dummy `_d_newclassT` hook to tests that redefine the `object`
module
- Remove `new MinHeap!(TestType)()` from `fail308.d`. Otherwise the
errror was changed and printed the local path to druntime
- Move `err` to global scope in rt.sections.d to avoid the frontend
lowering
- Account for the `GC.malloc()` called by the template hook in the
`-profile=gc` tests

Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>

Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
2023-01-27 10:02:10 +02:00
Iain Buclaw
aa19d8a145 ci: Update cirrus macOS image to M1-based runners (#14772)
* druntime/test: Force makefile to x86 on Apple ARM cpu (dmd does not support ARM)

* ci: Update cirrus macOS image to M1-based runners

* compiler/test/Makefile: Workaround issue 23517
2023-01-03 01:23:03 +02:00
Iain Buclaw
2549fe3a64
ci: Update cirrus macOS image to M1-based runners (#14772)
* druntime/test: Force makefile to x86 on Apple ARM cpu (dmd does not support ARM)

* ci: Update cirrus macOS image to M1-based runners

* compiler/test/Makefile: Workaround issue 23517
2023-01-02 20:15:23 +01:00
Iain Buclaw
7560d12914 fix Issue 23593 - core.thread: suspendAll doesn't wait for all if current thread has detached itself.
Don't subtract suspend counter if thread has detached itself.
2022-12-31 02:12:56 +01:00
Iain Buclaw
45ca8e001e Fix FreeBSD failing test suite in master 2022-12-29 15:38:05 +01:00
Nicholas Wilson
d494932ca6 Fix rt_trap_exceptions_drt_gdb in the presence of optimisations
The test checks the stack frame of `_Dmain` is in the backtrace, however if unused locals are optimised out and`test` is inlined into `main` 
```d
void test()
{
    int innerLocal = 20;
    throw new Exception("foo");
}
void main(string[] args)
{
    string myLocal = "bar";
    test();
}
```
then the point at which the untapped exception is thrown is at the start of D main - not somewhere in the middle of it - and so GDB prints 
```
...
#4 D main (args=...)
```
rather than 
```
...
#4 0xSOMEADDRESS in D main (args=...)
```
2022-11-02 04:17:26 +01:00
Ömer Faruk IRMAK
fabd06214e druntime: Demangle C++ symbols if a standard library is already loaded 2022-10-29 10:59:46 +01:00