Skip to content

Commit

Permalink
Compare type sizes in druntime with ImportC (#16571)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tim-dlang authored Jul 8, 2024
1 parent 1417180 commit 67996ab
Show file tree
Hide file tree
Showing 4 changed files with 635 additions and 1 deletion.
2 changes: 1 addition & 1 deletion druntime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ HAS_ADDITIONAL_TESTS:=$(shell test -d test && echo 1)
ifeq ($(HAS_ADDITIONAL_TESTS),1)
ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage test/profile test/cycles test/allocations test/typeinfo \
test/aa test/cpuid test/gc test/hash test/lifetime test/shared \
test/thread test/unittest test/imports test/betterc test/stdcpp test/config test/traits
test/thread test/unittest test/imports test/betterc test/stdcpp test/config test/traits test/importc_compare
ifeq (windows,$(OS))
ADDITIONAL_TESTS+=test/uuid
else
Expand Down
19 changes: 19 additions & 0 deletions druntime/test/importc_compare/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include ../common.mak

TESTS:=importc_compare

.PHONY: all clean
all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS)))

DFLAGS+=-d

$(ROOT)/%.done: $(ROOT)/%$(DOTEXE)
@echo Testing $*
$(QUIET)$(TIMELIMIT)$(ROOT)/$* $(RUN_ARGS)
@touch $@

$(ROOT)/%$(DOTEXE): $(SRC)/%.d
$(QUIET)$(DMD) $(DFLAGS) -of$@ $<

clean:
rm -rf $(ROOT)
Loading

0 comments on commit 67996ab

Please sign in to comment.