qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Modify tests to work with clang
@ 2019-11-15  4:38 Taylor Simpson
  2019-11-15  5:51 ` no-reply
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Taylor Simpson @ 2019-11-15  4:38 UTC (permalink / raw)
  To: alex.bennee, qemu-devel; +Cc: Taylor Simpson

Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
---
 tests/tcg/multiarch/float_helpers.c | 13 ++++++++++++-
 tests/tcg/multiarch/linux-test.c    |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/tests/tcg/multiarch/float_helpers.c b/tests/tcg/multiarch/float_helpers.c
index 8ee7903..437247c 100644
--- a/tests/tcg/multiarch/float_helpers.c
+++ b/tests/tcg/multiarch/float_helpers.c
@@ -26,6 +26,17 @@
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
+/*----------------------------------------------------------------------------
+| The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.
+| The code is a copy of SOFTFLOAT_GNUC_PREREQ, see softfloat-macros.h.
+*----------------------------------------------------------------------------*/
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)
+# define QEMU_GNUC_PREREQ(maj, min) \
+         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
+#else
+# define QEMU_GNUC_PREREQ(maj, min) 0
+#endif
+
 /*
  * Half Precision Numbers
  *
@@ -79,7 +90,7 @@ char *fmt_16(uint16_t num)
 
 #ifndef SNANF
 /* Signaling NaN macros, if supported.  */
-# if __GNUC_PREREQ(3, 3)
+# if defined(__clang__) || QEMU_GNUC_PREREQ(3, 3)
 #  define SNANF (__builtin_nansf (""))
 #  define SNAN (__builtin_nans (""))
 #  define SNANL (__builtin_nansl (""))
diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
index 673d7c8..edfc02c 100644
--- a/tests/tcg/multiarch/linux-test.c
+++ b/tests/tcg/multiarch/linux-test.c
@@ -485,7 +485,7 @@ static void test_signal(void)
     act.sa_flags = SA_SIGINFO;
     chk_error(sigaction(SIGSEGV, &act, NULL));
     if (setjmp(jmp_env) == 0) {
-        *(uint8_t *)0 = 0;
+        *(volatile uint8_t *)0 = 0;
     }
 
     act.sa_handler = SIG_DFL;
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Modify tests to work with clang
  2019-11-15  4:38 [PATCH] Modify tests to work with clang Taylor Simpson
@ 2019-11-15  5:51 ` no-reply
  2019-11-15  7:23 ` Thomas Huth
  2019-11-15 12:17 ` Alex Bennée
  2 siblings, 0 replies; 9+ messages in thread
From: no-reply @ 2019-11-15  5:51 UTC (permalink / raw)
  To: tsimpson; +Cc: tsimpson, alex.bennee, qemu-devel

Patchew URL: https://patchew.org/QEMU/1573792691-398-1-git-send-email-tsimpson@quicinc.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Subject: [PATCH] Modify tests to work with clang
Type: series
Message-id: 1573792691-398-1-git-send-email-tsimpson@quicinc.com

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
40fa5c0 Modify tests to work with clang

=== OUTPUT BEGIN ===
WARNING: Block comments use a leading /* on a separate line
#18: FILE: tests/tcg/multiarch/float_helpers.c:29:
+/*----------------------------------------------------------------------------

WARNING: Block comments use * on subsequent lines
#19: FILE: tests/tcg/multiarch/float_helpers.c:30:
+/*----------------------------------------------------------------------------
+| The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.

WARNING: Block comments use a trailing */ on a separate line
#21: FILE: tests/tcg/multiarch/float_helpers.c:32:
+*----------------------------------------------------------------------------*/

WARNING: architecture specific defines should be avoided
#22: FILE: tests/tcg/multiarch/float_helpers.c:33:
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)

WARNING: architecture specific defines should be avoided
#37: FILE: tests/tcg/multiarch/float_helpers.c:93:
+# if defined(__clang__) || QEMU_GNUC_PREREQ(3, 3)

ERROR: Use of volatile is usually wrong, please add a comment
#50: FILE: tests/tcg/multiarch/linux-test.c:488:
+        *(volatile uint8_t *)0 = 0;

total: 1 errors, 5 warnings, 33 lines checked

Commit 40fa5c0d7a1b (Modify tests to work with clang) has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/1573792691-398-1-git-send-email-tsimpson@quicinc.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Modify tests to work with clang
  2019-11-15  4:38 [PATCH] Modify tests to work with clang Taylor Simpson
  2019-11-15  5:51 ` no-reply
@ 2019-11-15  7:23 ` Thomas Huth
  2019-11-15 12:17 ` Alex Bennée
  2 siblings, 0 replies; 9+ messages in thread
From: Thomas Huth @ 2019-11-15  7:23 UTC (permalink / raw)
  To: Taylor Simpson, alex.bennee, qemu-devel

On 15/11/2019 05.38, Taylor Simpson wrote:
> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
> ---
>  tests/tcg/multiarch/float_helpers.c | 13 ++++++++++++-
>  tests/tcg/multiarch/linux-test.c    |  2 +-
>  2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/tcg/multiarch/float_helpers.c b/tests/tcg/multiarch/float_helpers.c
> index 8ee7903..437247c 100644
> --- a/tests/tcg/multiarch/float_helpers.c
> +++ b/tests/tcg/multiarch/float_helpers.c
> @@ -26,6 +26,17 @@
>  
>  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
>  
> +/*----------------------------------------------------------------------------
> +| The macro QEMU_GNUC_PREREQ tests for minimum version of the GNU C compiler.
> +| The code is a copy of SOFTFLOAT_GNUC_PREREQ, see softfloat-macros.h.
> +*----------------------------------------------------------------------------*/
> +#if defined(__GNUC__) && defined(__GNUC_MINOR__)
> +# define QEMU_GNUC_PREREQ(maj, min) \
> +         ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
> +#else
> +# define QEMU_GNUC_PREREQ(maj, min) 0
> +#endif
> +
>  /*
>   * Half Precision Numbers
>   *
> @@ -79,7 +90,7 @@ char *fmt_16(uint16_t num)
>  
>  #ifndef SNANF
>  /* Signaling NaN macros, if supported.  */
> -# if __GNUC_PREREQ(3, 3)
> +# if defined(__clang__) || QEMU_GNUC_PREREQ(3, 3)

IIRC clearly, Clang reports itself as GCC 4.2, so you certainly don't
need the defined(__clang__) here.
But additionally, we require at least GCC 4.8 to compile QEMU these days
(see the check in the configure script), so you can even remove this #if
statement completely, so that the following #defines are simply always used.

 Thomas



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Modify tests to work with clang
  2019-11-15  4:38 [PATCH] Modify tests to work with clang Taylor Simpson
  2019-11-15  5:51 ` no-reply
  2019-11-15  7:23 ` Thomas Huth
@ 2019-11-15 12:17 ` Alex Bennée
  2019-11-15 14:14   ` Taylor Simpson
  2 siblings, 1 reply; 9+ messages in thread
From: Alex Bennée @ 2019-11-15 12:17 UTC (permalink / raw)
  To: Taylor Simpson; +Cc: qemu-devel


Taylor Simpson <tsimpson@quicinc.com> writes:

> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
> ---
>  tests/tcg/multiarch/float_helpers.c | 13 ++++++++++++-
>  tests/tcg/multiarch/linux-test.c    |  2 +-
>  2 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/tests/tcg/multiarch/float_helpers.c b/tests/tcg/multiarch/float_helpers.c
> index 8ee7903..437247c 100644
> --- a/tests/tcg/multiarch/float_helpers.c
> +++ b/tests/tcg/multiarch/float_helpers.c
<snip>
> diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
> index 673d7c8..edfc02c 100644
> --- a/tests/tcg/multiarch/linux-test.c
> +++ b/tests/tcg/multiarch/linux-test.c
> @@ -485,7 +485,7 @@ static void test_signal(void)
>      act.sa_flags = SA_SIGINFO;
>      chk_error(sigaction(SIGSEGV, &act, NULL));
>      if (setjmp(jmp_env) == 0) {
> -        *(uint8_t *)0 = 0;
> +        *(volatile uint8_t *)0 = 0;

This looks suspicious - volatile is almost never the answer to a
question. What are we trying to achieve here?

>      }
>
>      act.sa_handler = SIG_DFL;


--
Alex Bennée


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] Modify tests to work with clang
  2019-11-15 12:17 ` Alex Bennée
@ 2019-11-15 14:14   ` Taylor Simpson
  0 siblings, 0 replies; 9+ messages in thread
From: Taylor Simpson @ 2019-11-15 14:14 UTC (permalink / raw)
  To: Alex Bennée; +Cc: qemu-devel

Without volatile, clang turns that statement into a call to abort.

It is discussed here (Chris Lattner's blog from 2011)
http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html

Here is the relevant paragraph
If you're using an LLVM-based compiler, you can dereference a "volatile" null pointer to get a crash if that's what you're looking for, since volatile loads and stores are generally not touched by the optimizer. There is currently no flag that enables random NULL pointer loads to be treated as valid accesses or to make random loads know that their pointer is "allowed to be null".

Taylor


-----Original Message-----
From: Alex Bennée <alex.bennee@linaro.org>
Sent: Friday, November 15, 2019 6:17 AM
To: Taylor Simpson <tsimpson@quicinc.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] Modify tests to work with clang

-------------------------------------------------------------------------
CAUTION: This email originated from outside of the organization.
-------------------------------------------------------------------------

Taylor Simpson <tsimpson@quicinc.com> writes:

> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
> ---
>  tests/tcg/multiarch/float_helpers.c | 13 ++++++++++++-
>  tests/tcg/multiarch/linux-test.c    |  2 +-
>  2 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/tests/tcg/multiarch/float_helpers.c
> b/tests/tcg/multiarch/float_helpers.c
> index 8ee7903..437247c 100644
> --- a/tests/tcg/multiarch/float_helpers.c
> +++ b/tests/tcg/multiarch/float_helpers.c
<snip>
> diff --git a/tests/tcg/multiarch/linux-test.c
> b/tests/tcg/multiarch/linux-test.c
> index 673d7c8..edfc02c 100644
> --- a/tests/tcg/multiarch/linux-test.c
> +++ b/tests/tcg/multiarch/linux-test.c
> @@ -485,7 +485,7 @@ static void test_signal(void)
>      act.sa_flags = SA_SIGINFO;
>      chk_error(sigaction(SIGSEGV, &act, NULL));
>      if (setjmp(jmp_env) == 0) {
> -        *(uint8_t *)0 = 0;
> +        *(volatile uint8_t *)0 = 0;

This looks suspicious - volatile is almost never the answer to a question. What are we trying to achieve here?

>      }
>
>      act.sa_handler = SIG_DFL;


--
Alex Bennée

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Modify tests to work with clang
  2019-11-17 23:14 Taylor Simpson
  2019-11-18  8:52 ` Thomas Huth
  2019-11-18  9:17 ` Richard Henderson
@ 2019-11-18 11:48 ` Alex Bennée
  2 siblings, 0 replies; 9+ messages in thread
From: Alex Bennée @ 2019-11-18 11:48 UTC (permalink / raw)
  To: Taylor Simpson; +Cc: qemu-devel


Taylor Simpson <tsimpson@quicinc.com> writes:

> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>

Queued to 4.2/for-rc2, thanks.

> ---
>  tests/tcg/multiarch/float_helpers.c | 2 --
>  tests/tcg/multiarch/linux-test.c    | 6 +++++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/tests/tcg/multiarch/float_helpers.c b/tests/tcg/multiarch/float_helpers.c
> index 8ee7903..bc530e5 100644
> --- a/tests/tcg/multiarch/float_helpers.c
> +++ b/tests/tcg/multiarch/float_helpers.c
> @@ -79,11 +79,9 @@ char *fmt_16(uint16_t num)
>
>  #ifndef SNANF
>  /* Signaling NaN macros, if supported.  */
> -# if __GNUC_PREREQ(3, 3)
>  #  define SNANF (__builtin_nansf (""))
>  #  define SNAN (__builtin_nans (""))
>  #  define SNANL (__builtin_nansl (""))
> -# endif
>  #endif
>
>  static float f32_numbers[] = {
> diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
> index 673d7c8..8a7c15c 100644
> --- a/tests/tcg/multiarch/linux-test.c
> +++ b/tests/tcg/multiarch/linux-test.c
> @@ -485,7 +485,11 @@ static void test_signal(void)
>      act.sa_flags = SA_SIGINFO;
>      chk_error(sigaction(SIGSEGV, &act, NULL));
>      if (setjmp(jmp_env) == 0) {
> -        *(uint8_t *)0 = 0;
> +        /*
> +         * clang requires volatile or it will turn this into a
> +         * call to abort() instead of forcing a SIGSEGV.
> +         */
> +        *(volatile uint8_t *)0 = 0;
>      }
>
>      act.sa_handler = SIG_DFL;


--
Alex Bennée


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Modify tests to work with clang
  2019-11-17 23:14 Taylor Simpson
  2019-11-18  8:52 ` Thomas Huth
@ 2019-11-18  9:17 ` Richard Henderson
  2019-11-18 11:48 ` Alex Bennée
  2 siblings, 0 replies; 9+ messages in thread
From: Richard Henderson @ 2019-11-18  9:17 UTC (permalink / raw)
  To: Taylor Simpson, alex.bennee, qemu-devel

On 11/18/19 12:14 AM, Taylor Simpson wrote:
> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
> ---
>  tests/tcg/multiarch/float_helpers.c | 2 --
>  tests/tcg/multiarch/linux-test.c    | 6 +++++-
>  2 files changed, 5 insertions(+), 3 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Modify tests to work with clang
  2019-11-17 23:14 Taylor Simpson
@ 2019-11-18  8:52 ` Thomas Huth
  2019-11-18  9:17 ` Richard Henderson
  2019-11-18 11:48 ` Alex Bennée
  2 siblings, 0 replies; 9+ messages in thread
From: Thomas Huth @ 2019-11-18  8:52 UTC (permalink / raw)
  To: Taylor Simpson, qemu-devel; +Cc: QEMU Trivial, alex.bennee

On 18/11/2019 00.14, Taylor Simpson wrote:
> Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
> ---
>  tests/tcg/multiarch/float_helpers.c | 2 --
>  tests/tcg/multiarch/linux-test.c    | 6 +++++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/tcg/multiarch/float_helpers.c b/tests/tcg/multiarch/float_helpers.c
> index 8ee7903..bc530e5 100644
> --- a/tests/tcg/multiarch/float_helpers.c
> +++ b/tests/tcg/multiarch/float_helpers.c
> @@ -79,11 +79,9 @@ char *fmt_16(uint16_t num)
>  
>  #ifndef SNANF
>  /* Signaling NaN macros, if supported.  */
> -# if __GNUC_PREREQ(3, 3)
>  #  define SNANF (__builtin_nansf (""))
>  #  define SNAN (__builtin_nans (""))
>  #  define SNANL (__builtin_nansl (""))
> -# endif
>  #endif
>  
>  static float f32_numbers[] = {
> diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
> index 673d7c8..8a7c15c 100644
> --- a/tests/tcg/multiarch/linux-test.c
> +++ b/tests/tcg/multiarch/linux-test.c
> @@ -485,7 +485,11 @@ static void test_signal(void)
>      act.sa_flags = SA_SIGINFO;
>      chk_error(sigaction(SIGSEGV, &act, NULL));
>      if (setjmp(jmp_env) == 0) {
> -        *(uint8_t *)0 = 0;
> +        /*
> +         * clang requires volatile or it will turn this into a
> +         * call to abort() instead of forcing a SIGSEGV.
> +         */
> +        *(volatile uint8_t *)0 = 0;
>      }
>  
>      act.sa_handler = SIG_DFL;
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] Modify tests to work with clang
@ 2019-11-17 23:14 Taylor Simpson
  2019-11-18  8:52 ` Thomas Huth
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Taylor Simpson @ 2019-11-17 23:14 UTC (permalink / raw)
  To: alex.bennee, qemu-devel; +Cc: Taylor Simpson

Signed-off-by: Taylor Simpson <tsimpson@quicinc.com>
---
 tests/tcg/multiarch/float_helpers.c | 2 --
 tests/tcg/multiarch/linux-test.c    | 6 +++++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/tests/tcg/multiarch/float_helpers.c b/tests/tcg/multiarch/float_helpers.c
index 8ee7903..bc530e5 100644
--- a/tests/tcg/multiarch/float_helpers.c
+++ b/tests/tcg/multiarch/float_helpers.c
@@ -79,11 +79,9 @@ char *fmt_16(uint16_t num)
 
 #ifndef SNANF
 /* Signaling NaN macros, if supported.  */
-# if __GNUC_PREREQ(3, 3)
 #  define SNANF (__builtin_nansf (""))
 #  define SNAN (__builtin_nans (""))
 #  define SNANL (__builtin_nansl (""))
-# endif
 #endif
 
 static float f32_numbers[] = {
diff --git a/tests/tcg/multiarch/linux-test.c b/tests/tcg/multiarch/linux-test.c
index 673d7c8..8a7c15c 100644
--- a/tests/tcg/multiarch/linux-test.c
+++ b/tests/tcg/multiarch/linux-test.c
@@ -485,7 +485,11 @@ static void test_signal(void)
     act.sa_flags = SA_SIGINFO;
     chk_error(sigaction(SIGSEGV, &act, NULL));
     if (setjmp(jmp_env) == 0) {
-        *(uint8_t *)0 = 0;
+        /*
+         * clang requires volatile or it will turn this into a
+         * call to abort() instead of forcing a SIGSEGV.
+         */
+        *(volatile uint8_t *)0 = 0;
     }
 
     act.sa_handler = SIG_DFL;
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-11-18 11:49 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-15  4:38 [PATCH] Modify tests to work with clang Taylor Simpson
2019-11-15  5:51 ` no-reply
2019-11-15  7:23 ` Thomas Huth
2019-11-15 12:17 ` Alex Bennée
2019-11-15 14:14   ` Taylor Simpson
2019-11-17 23:14 Taylor Simpson
2019-11-18  8:52 ` Thomas Huth
2019-11-18  9:17 ` Richard Henderson
2019-11-18 11:48 ` Alex Bennée

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).