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.
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`.
* 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
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
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.
* 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>
- 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>
* 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.
* 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>
* 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.
* 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.
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>
* 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.
* 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.
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>
* 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
* 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
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=...)
```