d: Update language attribute support, and implement gcc.attributes
authorIain Buclaw <ibuclaw@gdcproject.org>
Tue, 14 Apr 2020 07:29:10 +0000 (09:29 +0200)
committerIain Buclaw <ibuclaw@gdcproject.org>
Thu, 8 Apr 2021 13:30:47 +0000 (15:30 +0200)
commit8e84a142913a1f3084d415462024964f97356bee
tree67a8e38717a38cc3572382c90fc9a1773bc1c84a
parent855ce475883c7a52112b9c110f998a49dd69caab
d: Update language attribute support, and implement gcc.attributes

D attribute support has been updated to have a baseline parity with the
LLVM D compiler's own `ldc.attributes'.

The handler that extracts GCC attributes from a list of UDAs has been
improved to take care of some mistakes that could have been warnings.
UDAs attached to field variables are also now processed for any GCC
attributes attached to them.

The following new attributes have been added to the D front-end:

 - @attribute("alloc_size")
 - @attribute("used")
 - @attribute("optimize")
 - @attribute("restrict")
 - @attribute("cold")
 - @attribute("noplt")
 - @attribute("target_clones")
 - @attribute("no_icf")
 - @attribute("noipa")
 - @attribute("symver")

With convenience aliases in a new `gcc.attributes' module to match
the same naming convention as `ldc.attributes':

 - @allocSize()
 - @assumeUsed
 - @fastmath
 - @naked
 - @restrict
 - @cold
 - @noplt
 - @optStrategy()
 - @polly
 - @section()
 - @target()
 - @weak

The old gcc.attribute module has been deprecated, along with the removal
of the following attribute handlers:

 - @attribute("alias"): Has been superseded by `pragma(mangle)'.
 - @attribute("forceinline"): Renamed to always_inline.

gcc/d/ChangeLog:

* d-attribs.cc: Include fold-const.h and opts.h.
(attr_noreturn_exclusions): Add alloc_size.
(attr_const_pure_exclusions): Likewise.
(attr_inline_exclusions): Add target_clones.
(attr_noinline_exclusions): Rename forceinline to always_inline.
(attr_target_exclusions): New array.
(attr_target_clones_exclusions): New array.
(attr_alloc_exclusions): New array.
(attr_cold_hot_exclusions): New array.
(d_langhook_common_attribute_table): Add new D attribute handlers.
(build_attributes): Update to look for gcc.attributes.  Issue warning
if not given a struct literal.  Handle void initialized arguments.
(handle_always_inline_attribute): Remove function.
(d_handle_noinline_attribute): Don't extract TYPE_LANG_FRONTEND.
(d_handle_forceinline_attribute): Rename to...
(d_handle_always_inline_attribute): ...this.  Remove special handling.
(d_handle_flatten_attribute): Don't extract TYPE_LANG_FRONTEND.
(d_handle_target_attribute): Likewise.  Warn about empty arguments.
(d_handle_target_clones_attribute): New function.
(optimize_args): New static variable.
(parse_optimize_options): New function.
(d_handle_optimize_attribute): New function.
(d_handle_noclone_attribute): Don't extract TYPE_LANG_FRONTEND.
(d_handle_alias_attribute): Remove function.
(d_handle_noicf_attribute): New function.
(d_handle_noipa_attribute): New function.
(d_handle_section_attribute): Call the handle_generic_attribute target
hook after performing target independent processing.
(d_handle_symver_attribute): New function.
(d_handle_noplt_attribute): New function.
(positional_argument): New function.
(d_handle_alloc_size_attribute): New function.
(d_handle_cold_attribute): New function.
(d_handle_restrict_attribute): New function.
(d_handle_used_attribute): New function.
* decl.cc (gcc_attribute_p): Update to look for gcc.attributes.
(get_symbol_decl): Update decl source location of old prototypes to
the new declaration being merged.
* types.cc (layout_aggregate_members): Apply user defined attributes
on fields.

libphobos/ChangeLog:

* libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add
  gcc/attributes.d.
* libdruntime/Makefile.in: Regenerate.
* libdruntime/gcc/attribute.d: Deprecate module, publicly import
gcc.attributes.
* libdruntime/gcc/deh.d: Update imports.
* libdruntime/gcc/attributes.d: New file.

gcc/testsuite/ChangeLog:

* gdc.dg/gdc108.d: Update test.
* gdc.dg/gdc142.d: Likewise.
* gdc.dg/pr90136a.d: Likewise.
* gdc.dg/pr90136b.d: Likewise.
* gdc.dg/pr90136c.d: Likewise.
* gdc.dg/pr95173.d: Likewise.
* gdc.dg/attr_allocsize1.d: New test.
* gdc.dg/attr_allocsize2.d: New test.
* gdc.dg/attr_alwaysinline1.d: New test.
* gdc.dg/attr_cold1.d: New test.
* gdc.dg/attr_exclusions1.d: New test.
* gdc.dg/attr_exclusions2.d: New test.
* gdc.dg/attr_flatten1.d: New test.
* gdc.dg/attr_module.d: New test.
* gdc.dg/attr_noclone1.d: New test.
* gdc.dg/attr_noicf1.d: New test.
* gdc.dg/attr_noinline1.d: New test.
* gdc.dg/attr_noipa1.d: New test.
* gdc.dg/attr_noplt1.d: New test.
* gdc.dg/attr_optimize1.d: New test.
* gdc.dg/attr_optimize2.d: New test.
* gdc.dg/attr_optimize3.d: New test.
* gdc.dg/attr_optimize4.d: New test.
* gdc.dg/attr_restrict1.d: New test.
* gdc.dg/attr_section1.d: New test.
* gdc.dg/attr_symver1.d: New test.
* gdc.dg/attr_target1.d: New test.
* gdc.dg/attr_targetclones1.d: New test.
* gdc.dg/attr_used1.d: New test.
* gdc.dg/attr_used2.d: New test.
* gdc.dg/attr_weak1.d: New test.
* gdc.dg/imports/attributes.d: New test.
40 files changed:
gcc/d/d-attribs.cc
gcc/d/decl.cc
gcc/d/types.cc
gcc/testsuite/gdc.dg/attr_allocsize1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_allocsize2.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_alwaysinline1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_cold1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_exclusions1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_exclusions2.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_flatten1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_module.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_noclone1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_noicf1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_noinline1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_noipa1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_noplt1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_optimize1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_optimize2.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_optimize3.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_optimize4.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_restrict1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_section1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_symver1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_target1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_targetclones1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_used1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_used2.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/attr_weak1.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/gdc108.d
gcc/testsuite/gdc.dg/gdc142.d
gcc/testsuite/gdc.dg/imports/attributes.d [new file with mode: 0644]
gcc/testsuite/gdc.dg/pr90136a.d
gcc/testsuite/gdc.dg/pr90136b.d
gcc/testsuite/gdc.dg/pr90136c.d
gcc/testsuite/gdc.dg/pr95173.d
libphobos/libdruntime/Makefile.am
libphobos/libdruntime/Makefile.in
libphobos/libdruntime/gcc/attribute.d
libphobos/libdruntime/gcc/attributes.d [new file with mode: 0644]
libphobos/libdruntime/gcc/deh.d