On 3/14/26 11:04 AM, Nathaniel Shead wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk/15?
OK.
-- >8 -- The crash in the given PR occurs because we've streamed the definition of an anticipated builtin, but when processing the nonnull attribute we find that its DECL_ARGUMENTS is null. Back in r14-8196-g3471a61ed0ddef70de8f1bbba85cd1e945fc86fd I removed the setting of DECL_ARGUMENTS as this was causing issues where we were replacing the argument list for existing definitions. But it looks like really it should have been adjusted just to only do the replacement in cases that a definition wasn't already available, i.e. if installing. PR c++/124485 gcc/cp/ChangeLog: * module.cc (trees_in::read_function_def): Set DECL_ARGUMENTS if installing. gcc/testsuite/ChangeLog: * g++.dg/modules/builtin-10_a.C: New test. * g++.dg/modules/builtin-10_b.C: New test. Signed-off-by: Nathaniel Shead <[email protected]> --- gcc/cp/module.cc | 1 + gcc/testsuite/g++.dg/modules/builtin-10_a.C | 24 +++++++++++++++++++++ gcc/testsuite/g++.dg/modules/builtin-10_b.C | 9 ++++++++ 3 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/builtin-10_a.C create mode 100644 gcc/testsuite/g++.dg/modules/builtin-10_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 83d24a3267d..066afca874f 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -13216,6 +13216,7 @@ trees_in::read_function_def (tree decl, tree maybe_template) DECL_RESULT (decl) = result; DECL_INITIAL (decl) = initial; DECL_SAVED_TREE (decl) = saved; + DECL_ARGUMENTS (decl) = DECL_ARGUMENTS (maybe_dup);if (context)SET_DECL_FRIEND_CONTEXT (decl, context); diff --git a/gcc/testsuite/g++.dg/modules/builtin-10_a.C b/gcc/testsuite/g++.dg/modules/builtin-10_a.C new file mode 100644 index 00000000000..cbadede81df --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/builtin-10_a.C @@ -0,0 +1,24 @@ +// PR c++/124485 +// { dg-additional-options "-fmodules -Wno-global-module -O3" } +// { dg-module-cmi M } + +module; +extern "C" { + typedef long unsigned int size_t; + + extern void *memset (void *__s, int __c, size_t __n) noexcept (true) __attribute__ ((__nonnull__ (1))); + + extern + __inline + __attribute__((__always_inline__)) + __attribute__((__gnu_inline__)) + __attribute__((__artificial__)) + void * + __attribute__((__leaf__)) + memset(void *__dest, int __ch, size_t __len) noexcept(true) { + return __builtin___memset_chk(__dest, __ch, __len, + __builtin_object_size(__dest, 0)); + } +} +export module M; +export using ::memset; diff --git a/gcc/testsuite/g++.dg/modules/builtin-10_b.C b/gcc/testsuite/g++.dg/modules/builtin-10_b.C new file mode 100644 index 00000000000..acb49bbbe8b --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/builtin-10_b.C @@ -0,0 +1,9 @@ +// PR c++/124485 +// { dg-additional-options "-fmodules -O3 -fdump-lang-module-alias" } + +import M; +void foo(void *data) { + memset(data, 0xFF, 4); +} + +// { dg-final { scan-lang-dump {Deduping '::memset'} module } }
