Message ID | ydd7cjmq491.fsf@CeBiTec.Uni-Bielefeld.DE |
---|---|
State | New |
Headers | show |
Series | testsuite: Fix c-c++-common/pr103798-2.c on Solaris [PR113706] | expand |
On 2/2/24 10:23, Rainer Orth wrote: > c-c++-common/pr103798-2.c FAILs on Solaris when compiled as C++: > > FAIL: c-c++-common/pr103798-2.c -std=gnu++14 scan-assembler-not memchr > FAIL: c-c++-common/pr103798-2.c -std=gnu++17 scan-assembler-not memchr > FAIL: c-c++-common/pr103798-2.c -std=gnu++20 scan-assembler-not memchr > FAIL: c-c++-common/pr103798-2.c -std=gnu++98 scan-assembler-not memchr > > As H.J. analyzed in the PR, Solaris <string.h> declares std::memchr, not > memchr, which isn't treated as __builtin_memchr. The problem seems to be not the std::, but that the Solaris string.h declares const void *memchr(const void *, int, size_t); as specified by the C++ standard, while gcc expects the return type to be void* like in C. This looks like a GCC bug, not Solaris; I'd prefer to xfail the testcase rather than work around the compiler bug. Jason
Hi Jason, > On 2/2/24 10:23, Rainer Orth wrote: >> c-c++-common/pr103798-2.c FAILs on Solaris when compiled as C++: >> FAIL: c-c++-common/pr103798-2.c -std=gnu++14 scan-assembler-not memchr >> FAIL: c-c++-common/pr103798-2.c -std=gnu++17 scan-assembler-not memchr >> FAIL: c-c++-common/pr103798-2.c -std=gnu++20 scan-assembler-not memchr >> FAIL: c-c++-common/pr103798-2.c -std=gnu++98 scan-assembler-not memchr >> As H.J. analyzed in the PR, Solaris <string.h> declares std::memchr, not >> memchr, which isn't treated as __builtin_memchr. > > The problem seems to be not the std::, but that the Solaris string.h > declares > > const void *memchr(const void *, int, size_t); > > as specified by the C++ standard, while gcc expects the return type to be > void* like in C. > > This looks like a GCC bug, not Solaris; I'd prefer to xfail the testcase > rather than work around the compiler bug. thanks for the analysis. What I found with my current patch, just the memchr prototype changed to always return const void *, the test still PASSes as C, but FAILs as C++. In the C++ case I get a warning: /vol/gcc/src/hg/master/local/gcc/testsuite/c-c++-common/pr103798-2.c:10:20: warning: declaration of ‘const void* memchr(const void*, int, size_t)’ conflicts with built-in declaration ‘void* memchr(const void*, int, unsigned int)’ [-Wbuiltin-declaration-mismatch] Here's the patch to xfail the test instead. Tested on sparc-sun-solaris2.11 and x86_64-pc-linux-gnu. Ok for trunk? Rainer
On 2/13/24 05:27, Rainer Orth wrote: > Hi Jason, > >> On 2/2/24 10:23, Rainer Orth wrote: >>> c-c++-common/pr103798-2.c FAILs on Solaris when compiled as C++: >>> FAIL: c-c++-common/pr103798-2.c -std=gnu++14 scan-assembler-not memchr >>> FAIL: c-c++-common/pr103798-2.c -std=gnu++17 scan-assembler-not memchr >>> FAIL: c-c++-common/pr103798-2.c -std=gnu++20 scan-assembler-not memchr >>> FAIL: c-c++-common/pr103798-2.c -std=gnu++98 scan-assembler-not memchr >>> As H.J. analyzed in the PR, Solaris <string.h> declares std::memchr, not >>> memchr, which isn't treated as __builtin_memchr. >> >> The problem seems to be not the std::, but that the Solaris string.h >> declares >> >> const void *memchr(const void *, int, size_t); >> >> as specified by the C++ standard, while gcc expects the return type to be >> void* like in C. >> >> This looks like a GCC bug, not Solaris; I'd prefer to xfail the testcase >> rather than work around the compiler bug. > > thanks for the analysis. > > What I found with my current patch, just the memchr prototype changed to > always return const void *, the test still PASSes as C, but FAILs as > C++. > > In the C++ case I get a warning: > > /vol/gcc/src/hg/master/local/gcc/testsuite/c-c++-common/pr103798-2.c:10:20: warning: declaration of ‘const void* memchr(const void*, int, size_t)’ conflicts with built-in declaration ‘void* memchr(const void*, int, unsigned int)’ [-Wbuiltin-declaration-mismatch] > > Here's the patch to xfail the test instead. > > Tested on sparc-sun-solaris2.11 and x86_64-pc-linux-gnu. > > Ok for trunk? OK, thanks. Jason
# HG changeset patch # Parent 943813561aef290adb442042f9c4fe9999cd82ee testsuite: Fix c-c++-common/pr103798-2.c on Solaris [PR113706] diff --git a/gcc/testsuite/c-c++-common/pr103798-2.c b/gcc/testsuite/c-c++-common/pr103798-2.c --- a/gcc/testsuite/c-c++-common/pr103798-2.c +++ b/gcc/testsuite/c-c++-common/pr103798-2.c @@ -1,7 +1,16 @@ /* { dg-do run } */ /* { dg-options "-O2 -fdump-tree-optimized -save-temps" } */ -#include <string.h> +#define NULL ((void *) 0) + +typedef __SIZE_TYPE__ size_t; +#ifdef __cplusplus +extern "C" { +#endif +extern void *memchr (const void *, int, size_t); +#ifdef __cplusplus +} +#endif __attribute__ ((weak)) int