diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-06-11 12:40:00 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-06-13 16:37:13 +0200 |
commit | 77718f38f896191e39b1e14c66ed990f0fff391b (patch) | |
tree | 12501410623ab6c27871a8584af8d38f9b7d0928 /gcc/testsuite/gdc.dg | |
parent | f8baf4004ef965ce7a9edf6d2f5eb99adb15803a (diff) | |
download | gcc-77718f38f896191e39b1e14c66ed990f0fff391b.zip gcc-77718f38f896191e39b1e14c66ed990f0fff391b.tar.gz gcc-77718f38f896191e39b1e14c66ed990f0fff391b.tar.bz2 |
d: Match function declarations of gcc built-ins from any module.
Declarations of recognised gcc built-in functions are now matched from
any module. Previously, only the `core.stdc' package was scanned.
In addition to matching of the symbol, any user-applied `@attributes' or
`pragma(mangle)' name will be applied to the built-in decl as well.
Because there would now be no control over where built-in declarations
are coming from, the warning option `-Wbuiltin-declaration-mismatch' has
been implemented in the D front-end too.
gcc/d/ChangeLog:
* d-builtins.cc: Include builtins.h.
(gcc_builtins_libfuncs): Remove.
(strip_type_modifiers): New function.
(matches_builtin_type): New function.
(covariant_with_builtin_type_p): New function.
(maybe_set_builtin_1): Set front-end built-in if identifier matches
gcc built-in name. Apply user-specified attributes and assembler name
overrides to the built-in. Warn about built-in declaration mismatches.
(d_builtin_function): Set IDENTIFIER_DECL_TREE of built-in functions.
* d-compiler.cc (Compiler::onParseModule): Scan all modules for any
identifiers that match built-in function names.
* lang.opt (Wbuiltin-declaration-mismatch): New option.
gcc/testsuite/ChangeLog:
* gdc.dg/Wbuiltin_declaration_mismatch.d: New test.
* gdc.dg/builtins.d: New test.
Diffstat (limited to 'gcc/testsuite/gdc.dg')
-rw-r--r-- | gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch.d | 37 | ||||
-rw-r--r-- | gcc/testsuite/gdc.dg/builtins.d | 17 |
2 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch.d b/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch.d new file mode 100644 index 0000000..5340647 --- /dev/null +++ b/gcc/testsuite/gdc.dg/Wbuiltin_declaration_mismatch.d @@ -0,0 +1,37 @@ +// { dg-do compile } +// { dg-options "-Wbuiltin-declaration-mismatch" } + +extern(C): + +// Mismatched parameter lengths +double tan(); // { dg-warning "\\\[-Wbuiltin-declaration-mismatch]" } + +// Mismatched variadic arguments +int printf(const(char)*); // { dg-warning "\\\[-Wbuiltin-declaration-mismatch]" } + +// Mismatched return type +void puts(char*); // { dg-warning "\\\[-Wbuiltin-declaration-mismatch]" } + +// Mismatched return storage class +ref int isalnum(int); // { dg-warning "\\\[-Wbuiltin-declaration-mismatch]" } + +// Mismatched parameter type +double sin(long); // { dg-warning "\\\[-Wbuiltin-declaration-mismatch]" } + +// Mismatched parameter storage class +double frexp(double, lazy int*); // { dg-warning "\\\[-Wbuiltin-declaration-mismatch]" } +double log(ref double); // { dg-warning "\\\[-Wbuiltin-declaration-mismatch]" } + +// Verify that storage classes don't affect covariance matching +@trusted nothrow @nogc pure double fabs(double); + +// Verify inout is allowed instead of const +inout(char)* strstr(return scope inout(char)*, scope const char*) pure; + +// Verify that FILE* is allowed as it is implicitly convertable to void* +struct _IO_FILE{} +alias FILE = shared(_IO_FILE); +int fprintf(FILE*, scope const char*, scope const ...); + +// Verify integral types with same size are treated as if equivalent +int putchar(dchar); diff --git a/gcc/testsuite/gdc.dg/builtins.d b/gcc/testsuite/gdc.dg/builtins.d new file mode 100644 index 0000000..21e3a1e --- /dev/null +++ b/gcc/testsuite/gdc.dg/builtins.d @@ -0,0 +1,17 @@ +// { dg-do compile } +// { dg-options "-fdump-tree-original" } + +// { dg-final { scan-tree-dump " __builtin_sqrt " "original" } } +extern(C) double sqrt(double); +double test_sqrt(double a) { return sqrt(a); } + +// { dg-final { scan-tree-dump-not " __builtin_tan " "original" } } +pragma(mangle, "tan") +extern(C) double libc_tan(double); +double test_tan(double a) { return libc_tan(a); } + +// { dg-final { scan-tree-dump " __builtin_malloc " "original" } } +// { dg-final { scan-assembler "mangle_override" } } +pragma(mangle, "mangle_override") +extern(C) void *malloc(size_t); +void* test_malloc(size_t a) { return malloc(a); } |