Skip to contentSkip to conversation

Modify tests to work with clang

PATCH In review Taylor Simpson 4 participants 5 messages Nov 15, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Modify tests to work with clang

---
 tests/tcg/multiarch/float_helpers.c | 13 ++++++++++++-
 tests/tcg/multiarch/linux-test.c    |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)
tests/tcg/multiarch/float_helpers.c +12 -1
index 8ee7903..437247c 100644
@@ -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 (""))
tests/tcg/multiarch/linux-test.c +1 -1
index 673d7c8..edfc02c 100644
@@ -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;
Signature · 1 line
2.7.4
#1 lore raw
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

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: [email protected]

=== 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/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
In reply to Taylor Simpson
Quoted 29 lines · Taylor Simpson
---
 tests/tcg/multiarch/float_helpers.c | 13 ++++++++++++-
 tests/tcg/multiarch/linux-test.c    |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)
tests/tcg/multiarch/float_helpers.c +11 -0
index 8ee7903..437247c 100644
@@ -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
  *

tests/tcg/multiarch/float_helpers.c char *fmt_16(uint16_t num) · line 93

Quoted 5 lines
tests/tcg/multiarch/float_helpers.c +1 -1
@@ -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

#3 lore raw
In reply to Taylor Simpson
Quoted 10 lines · Taylor Simpson
---
 tests/tcg/multiarch/float_helpers.c | 13 ++++++++++++-
 tests/tcg/multiarch/linux-test.c    |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)
tests/tcg/multiarch/float_helpers.c +0 -0
index 8ee7903..437247c 100644

<snip>

tests/tcg/multiarch/linux-test.c static void test_signal(void) · line 488

Quoted 10 lines
tests/tcg/multiarch/linux-test.c +1 -1
index 673d7c8..edfc02c 100644
@@ -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?

tests/tcg/multiarch/linux-test.c static void test_signal(void) · line 491

Quoted 3 lines
tests/tcg/multiarch/linux-test.c +0 -0
     }
 
     act.sa_handler = SIG_DFL;

--
Alex Bennée

#4 lore raw

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 <[email protected]>
Sent: Friday, November 15, 2019 6:17 AM
To: Taylor Simpson <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] Modify tests to work with clang

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

Quoted 11 lines · Taylor Simpson
---
 tests/tcg/multiarch/float_helpers.c | 13 ++++++++++++-
 tests/tcg/multiarch/linux-test.c    |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)
tests/tcg/multiarch/float_helpers.c +0 -0
index 8ee7903..437247c 100644

<snip>

tests/tcg/multiarch/linux-test.c static void test_signal(void) · line 488

Quoted 11 lines
tests/tcg/multiarch/linux-test.c +1 -1
index 673d7c8..edfc02c 100644
@@ -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?

tests/tcg/multiarch/linux-test.c static void test_signal(void) · line 491

Quoted 3 lines
tests/tcg/multiarch/linux-test.c +0 -0
     }
 
     act.sa_handler = SIG_DFL;

--
Alex Bennée