Question about strncpy_2-1
Hi all,
With old gcc version(e.g. gcc-4.4), compiling strncpy_2-1 gets the following error:
----------------------------------------------------------------------------------
../../../conformance/interfaces/strncpy/1-1.c: In function ‘main’:
../../../conformance/interfaces/strncpy/1-1.c:64: error: #pragma GCC diagnostic not allowed inside functions ../../../conformance/interfaces/strncpy/1-1.c:65: error: #pragma GCC diagnostic not allowed inside functions ../../../conformance/interfaces/strncpy/1-1.c:67: error: #pragma GCC diagnostic not allowed inside functions conformance/interfaces/strncpy/1-1 compile FAILED; SKIPPING
----------------------------------------------------------------------------------
It seems that push/pop is supported and pragma diagnostic is allowed inside functions since commit 0955be6 in GCC.
It is clear for me to know tha fact that current gcc version doesn't support above pragma diagnostic code, so anyone can tell me if we should keep the error?
Best Regards,
Xiao Yang
Quoted 11 lines · Xiao Yang
Hi all,
With old gcc version(e.g. gcc-4.4), compiling strncpy_2-1 gets the following error:
----------------------------------------------------------------------------------
../../../conformance/interfaces/strncpy/1-1.c: In function ‘main’:
../../../conformance/interfaces/strncpy/1-1.c:64: error: #pragma GCC diagnostic not allowed inside functions ../../../conformance/interfaces/strncpy/1-1.c:65: error: #pragma GCC diagnostic not allowed inside functions ../../../conformance/interfaces/strncpy/1-1.c:67: error: #pragma GCC diagnostic not allowed inside functions conformance/interfaces/strncpy/1-1 compile FAILED; SKIPPING
----------------------------------------------------------------------------------
Quoted 5 lines
It seems that push/pop is supported and pragma diagnostic is allowed inside functions since commit 0955be6 in GCC.
It is clear for me to know tha fact that current gcc version doesn't support above pragma diagnostic code, so anyone can tell me if we should keep the error?
Hi all,
In addition, this compiler error doesn't break the whole openposix compilation.
Best Regards,
Xiao Yang
Quoted 6 lines
Best Regards,
Xiao Yang
Hi!
Quoted 1 line
In addition, this compiler error doesn't break the whole openposix compilation.
That is the desing of the openposix build system, compilation failures are not fatal.
Signature · 2 lines
Cyril Hrubis [email protected]
Hi!
Quoted 11 lines
With old gcc version(e.g. gcc-4.4), compiling strncpy_2-1 gets the following error:
----------------------------------------------------------------------------------
../../../conformance/interfaces/strncpy/1-1.c: In function ???main???:
../../../conformance/interfaces/strncpy/1-1.c:64: error: #pragma GCC diagnostic not allowed inside functions ../../../conformance/interfaces/strncpy/1-1.c:65: error: #pragma GCC diagnostic not allowed inside functions ../../../conformance/interfaces/strncpy/1-1.c:67: error: #pragma GCC diagnostic not allowed inside functions conformance/interfaces/strncpy/1-1 compile FAILED; SKIPPING
----------------------------------------------------------------------------------It seems that push/pop is supported and pragma diagnostic is allowed inside functions since commit 0955be6 in GCC.
Looks like an attempt to silence warnings, but a lousy one that would break on anything but new enough gcc, let's get rid of that.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 openposix/strncpy1-1: Fix compiler errors/warnings
pragma diagnostic can support push/pop and be allowed inside functions by commit 0955be65 on gcc-4.6, and it can support -Wstringop-truncation by commit d8aad78 on gcc-8.1. We try to avoid some compiler errors or warnings by just using pragma diagnostic for test on newer gcc(i.e. >= gcc-8.1) because compiling and running test don't get any failure after removing pragma diagnostic on older gcc.
For example:
1)compiling test gets the following error on gcc-4.4:
------------------------------------------------------
error: #pragma GCC diagnostic not allowed inside functions
------------------------------------------------------
2)compiling test gets the following warning on gcc-4.8:
-----------------------------------------------------
warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas]
------------------------------------------------------
--- .../conformance/interfaces/strncpy/1-1.c | 10 +++++++--- testcases/open_posix_testsuite/include/posixtest.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/strncpy/1-1.c +7 -3
@@ -61,10 +61,14 @@ int main(void) sample_str_1 =random_string (i); num_bytes =rand () % i; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstringop-truncation" +#if GCC_VERSION >=80100 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wstringop-truncation" +#endif ret_str =strncpy (sample_str_2, sample_str_1, num_bytes); -#pragma GCC diagnostic pop +#if GCC_VERSION >=80100 +# pragma GCC diagnostic pop +#endif sample_str_2[num_bytes] ='\0' ; sample_str_1[num_bytes] ='\0' ;
testcases/open_posix_testsuite/include/posixtest.h +2 -0
@@ -47,3 +47,5 @@#define LTP_ATTRIBUTE_NORETURN __attribute__((noreturn))#define LTP_ATTRIBUTE_UNUSED __attribute__((unused))#define LTP_ATTRIBUTE_UNUSED_RESULT __attribute__((warn_unused_result)) + +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
Signature · 1 line
1.7.1
PATCH 1/1 openposix/strncpy1-1: Fix compiler errors/warnings
Hi!
Quoted 15 lines
Signed-off-by Xiao Yang <[email protected]>--- .../conformance/interfaces/strncpy/1-1.c | 10 +++++++--- testcases/open_posix_testsuite/include/posixtest.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-)testcases/open_posix_testsuite/conformance/interfaces/strncpy/1-1.c +0
-1@@ -61,10 +61,14 @@ int main(void) sample_str_1 =random_string (i); num_bytes =rand () % i; -#pragma GCC diagnostic push
testcases/open_posix_testsuite/conformance/interfaces/strncpy/1-1.c int main(void) · line 71
Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/strncpy/1-1.c +7
-2-#pragma GCC diagnostic ignored "-Wstringop-truncation" +#if GCC_VERSION >=80100 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wstringop-truncation" +#endif ret_str =strncpy (sample_str_2, sample_str_1, num_bytes); -#pragma GCC diagnostic pop +#if GCC_VERSION >=80100 +# pragma GCC diagnostic pop +#endif
That looks even more silly than the original. I do not think that it's reasonable to mess up the code that bad only to surpress a single warning.
So what abour removing the pragmas entirely?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 openposix/strncpy1-1: Fix compiler errors/warnings
pragma diagnostic can support push/pop and be allowed inside functions by commit 0955be65 on gcc-4.6, and it can support -Wstringop-truncation by commit d8aad78 on gcc-8.1. We try to avoid some compiler errors or warnings by removing pragma diagnostic for test directly, because we don't get any failure after removing it on old/new gcc.
For example:
1)compiling test gets the following error on gcc-4.4:
------------------------------------------------------
error: #pragma GCC diagnostic not allowed inside functions
------------------------------------------------------
2)compiling test gets the following warning on gcc-4.8:
-----------------------------------------------------
warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas]
------------------------------------------------------
--- testcases/open_posix_testsuite/conformance/interfaces/strncpy/1-1.c | 3 --- 1 file changed, 3 deletions(-)
testcases/open_posix_testsuite/conformance/interfaces/strncpy/1-1.c +0 -3
@@ -61,10 +61,7 @@ int main(void) sample_str_1 =random_string (i); num_bytes =rand () % i; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstringop-truncation" ret_str =strncpy (sample_str_2, sample_str_1, num_bytes); -#pragma GCC diagnostic pop sample_str_2[num_bytes] ='\0' ; sample_str_1[num_bytes] ='\0' ;
Signature · 1 line
1.8.3.1
PATCH v2 1/1 openposix/strncpy1-1: Fix compiler errors/warnings
Hi!
Applied, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/1 openposix/strncpy1-1: Fix compiler errors/warnings
In reply to Cyril HrubisQuoted 30 lines · Cyril Hrubis
Hi!
Quoted 15 lines
Signed-off-by Xiao Yang<[email protected]>--- .../conformance/interfaces/strncpy/1-1.c | 10 +++++++--- testcases/open_posix_testsuite/include/posixtest.h | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-)testcases/open_posix_testsuite/conformance/interfaces/strncpy/1-1.c +0
-1@@ -61,10 +61,14 @@ int main(void) sample_str_1 =random_string (i); num_bytes =rand () % i; -#pragma GCC diagnostic pushtestcases/open_posix_testsuite/conformance/interfaces/strncpy/1-1.c int main(void) · line 71
Quoted 10 lines
testcases/open_posix_testsuite/conformance/interfaces/strncpy/1-1.c +7
-2-#pragma GCC diagnostic ignored "-Wstringop-truncation" +#if GCC_VERSION >=80100 +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wstringop-truncation" +#endif ret_str =strncpy (sample_str_2, sample_str_1, num_bytes); -#pragma GCC diagnostic pop +#if GCC_VERSION >=80100 +# pragma GCC diagnostic pop +#endif That looks even more silly than the original. I do not think that it's reasonable to mess up the code that bad only to surpress a single warning.
Quoted 2 lines
So what abour removing the pragmas entirely?
Hi Cyril,
I didn't get any failure after removing the pragmas on older/newer gcc, so i think
we can remove it directly.
Best Regards,
Xiao Yang