Skip to contentSkip to conversation

fix build with clang

PATCH Applied Norbert Lange 2 participants 7 messages Jul 25, 2022 – Aug 5, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fix build with clang

clang will never support 'variable length array in structure', and there does not seem to be a reason for this weird construct.

---
v1->v2:
* fix algorithm

---
 testsuite/smokey/memcheck/memcheck.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
testsuite/smokey/memcheck/memcheck.c +2 -4
index a33700f49..b11d2babd 100644
@@ -80,9 +80,7 @@ static inline void swap(void *left, void *right, const size_t size)
 
 static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
 {
-	struct {
-		char x[size];
-	} __attribute__((packed)) *base = vbase;
+	char *base = (char *)vbase;
 	unsigned int j, k;
 	double u;
 
@@ -92,7 +90,7 @@ static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
 		k = (unsigned int)(j * u) + 1;
 		if (j == k)
 			continue;
-		swap(&base[j - 1], &base[k - 1], size);
+		swap(base + (j - 1) * size, base + (k - 1) * size, size);
 	}
 }
 
Signature · 1 line
2.35.1
Applied
#1 lore raw
Quoted 27 lines · Norbert Lange

clang will never support 'variable length array in structure', and there does not seem to be a reason for this weird construct.

---
v1->v2:
* fix algorithm

---
 testsuite/smokey/memcheck/memcheck.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
testsuite/smokey/memcheck/memcheck.c +1 -3
index a33700f49..b11d2babd 100644
@@ -80,9 +80,7 @@ static inline void swap(void *left, void *right, const size_t size)
 
 static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
 {
-	struct {
-		char x[size];
-	} __attribute__((packed)) *base = vbase;
+	char *base = (char *)vbase;
 	unsigned int j, k;
 	double u;
 

testsuite/smokey/memcheck/memcheck.c static void random_shuffle(void *vbase, size_t nmemb, const size_t size) · line 96

Quoted 8 lines
testsuite/smokey/memcheck/memcheck.c +1 -1
@@ -92,7 +90,7 @@ static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
 		k = (unsigned int)(j * u) + 1;
 		if (j == k)
 			continue;
-		swap(&base[j - 1], &base[k - 1], size);
+		swap(base + (j - 1) * size, base + (k - 1) * size, size);
 	}
 }
 

Thanks, applied.

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
#2 lore raw

Am Mo., 25. Juli 2022 um 19:22 Uhr schrieb Jan Kiszka <[email protected]>:

Quoted 40 lines · Norbert Lange
Quoted 27 lines

clang will never support 'variable length array in structure', and there does not seem to be a reason for this weird construct.

---
v1->v2:
* fix algorithm

---
 testsuite/smokey/memcheck/memcheck.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
testsuite/smokey/memcheck/memcheck.c +1 -3
index a33700f49..b11d2babd 100644
@@ -80,9 +80,7 @@ static inline void swap(void *left, void *right, const size_t size)
 
 static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
 {
-     struct {
-             char x[size];
-     } __attribute__((packed)) *base = vbase;
+     char *base = (char *)vbase;
      unsigned int j, k;
      double u;
 

testsuite/smokey/memcheck/memcheck.c static void random_shuffle(void *vbase, size_t nmemb, const size_t size) · line 96

Quoted 8 lines
testsuite/smokey/memcheck/memcheck.c +1 -1
@@ -92,7 +90,7 @@ static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
              k = (unsigned int)(j * u) + 1;
              if (j == k)
                      continue;
-             swap(&base[j - 1], &base[k - 1], size);
+             swap(base + (j - 1) * size, base + (k - 1) * size, size);
      }
 }
 

Thanks, applied.

Quoted 5 lines

Jan

--
Siemens AG, Technology
Competence Center Embedded Linux

Could you cherry-pick this commit to 3.0.x and 3.1.x aswell please?

Norbert

#3 lore raw
Quoted 41 lines · Norbert Lange

Am Mo., 25. Juli 2022 um 19:22 Uhr schrieb Jan Kiszka <[email protected]>:

Quoted 40 lines · Norbert Lange
Quoted 27 lines

clang will never support 'variable length array in structure', and there does not seem to be a reason for this weird construct.

---
v1->v2:
* fix algorithm

---
 testsuite/smokey/memcheck/memcheck.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
testsuite/smokey/memcheck/memcheck.c +1 -3
index a33700f49..b11d2babd 100644
@@ -80,9 +80,7 @@ static inline void swap(void *left, void *right, const size_t size)
 
 static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
 {
-     struct {
-             char x[size];
-     } __attribute__((packed)) *base = vbase;
+     char *base = (char *)vbase;
      unsigned int j, k;
      double u;
 

testsuite/smokey/memcheck/memcheck.c static void random_shuffle(void *vbase, size_t nmemb, const size_t size) · line 96

Quoted 8 lines
testsuite/smokey/memcheck/memcheck.c +1 -1
@@ -92,7 +90,7 @@ static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
              k = (unsigned int)(j * u) + 1;
              if (j == k)
                      continue;
-             swap(&base[j - 1], &base[k - 1], size);
+             swap(base + (j - 1) * size, base + (k - 1) * size, size);
      }
 }
 

Thanks, applied.

Quoted 8 lines
Quoted 5 lines

Jan

--
Siemens AG, Technology
Competence Center Embedded Linux

Could you cherry-pick this commit to 3.0.x and 3.1.x aswell please?

I can. I was just not expecting someone starting something new with clang on these old versions now. If you change something as fundamental as the compiler, why sticking with that versions?

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
#4 lore raw

Am Fr., 5. Aug. 2022 um 15:45 Uhr schrieb Jan Kiszka <[email protected]>:

Quoted 49 lines · Norbert Lange
Quoted 47 lines

Am Mo., 25. Juli 2022 um 19:22 Uhr schrieb Jan Kiszka <[email protected]>:

Quoted 45 lines · Norbert Lange
Quoted 27 lines

clang will never support 'variable length array in structure', and there does not seem to be a reason for this weird construct.

---
v1->v2:
* fix algorithm

---
 testsuite/smokey/memcheck/memcheck.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
testsuite/smokey/memcheck/memcheck.c +1 -3
index a33700f49..b11d2babd 100644
@@ -80,9 +80,7 @@ static inline void swap(void *left, void *right, const size_t size)
 
 static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
 {
-     struct {
-             char x[size];
-     } __attribute__((packed)) *base = vbase;
+     char *base = (char *)vbase;
      unsigned int j, k;
      double u;
 

testsuite/smokey/memcheck/memcheck.c static void random_shuffle(void *vbase, size_t nmemb, const size_t size) · line 96

Quoted 8 lines
testsuite/smokey/memcheck/memcheck.c +1 -1
@@ -92,7 +90,7 @@ static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
              k = (unsigned int)(j * u) + 1;
              if (j == k)
                      continue;
-             swap(&base[j - 1], &base[k - 1], size);
+             swap(base + (j - 1) * size, base + (k - 1) * size, size);
      }
 }
 

Thanks, applied.

Jan

--
Siemens AG, Technology
Competence Center Embedded Linux

Quoted 6 lines
Quoted 2 lines

Could you cherry-pick this commit to 3.0.x and 3.1.x aswell please?

I can. I was just not expecting someone starting something new with clang on these old versions now. If you change something as fundamental as the compiler, why sticking with that versions?

I am trying to setup a build-server which uses clang, for using sanitzers, codecoverage
and code-quality. We wont change the compiler and don't want to change the xenomai version.

I guess I could just use a newer version of xenomai for the tests without adverse effects,
but so far I only have one xenomai version for everything.

Norbert

#5 lore raw

Am Fr., 5. Aug. 2022 um 16:00 Uhr schrieb Norbert Lange <[email protected]>:

Quoted 54 lines

Am Fr., 5. Aug. 2022 um 15:45 Uhr schrieb Jan Kiszka <[email protected]>:

Quoted 52 lines · Norbert Lange
Quoted 49 lines

Am Mo., 25. Juli 2022 um 19:22 Uhr schrieb Jan Kiszka <[email protected]>:

Quoted 40 lines · Norbert Lange
Quoted 27 lines

clang will never support 'variable length array in structure', and there does not seem to be a reason for this weird construct.

---
v1->v2:
* fix algorithm

---
 testsuite/smokey/memcheck/memcheck.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
testsuite/smokey/memcheck/memcheck.c +1 -3
index a33700f49..b11d2babd 100644
@@ -80,9 +80,7 @@ static inline void swap(void *left, void *right, const size_t size)
 
 static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
 {
-     struct {
-             char x[size];
-     } __attribute__((packed)) *base = vbase;
+     char *base = (char *)vbase;
      unsigned int j, k;
      double u;
 

testsuite/smokey/memcheck/memcheck.c static void random_shuffle(void *vbase, size_t nmemb, const size_t size) · line 96

Quoted 8 lines
testsuite/smokey/memcheck/memcheck.c +1 -1
@@ -92,7 +90,7 @@ static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
              k = (unsigned int)(j * u) + 1;
              if (j == k)
                      continue;
-             swap(&base[j - 1], &base[k - 1], size);
+             swap(base + (j - 1) * size, base + (k - 1) * size, size);
      }
 }
 

Thanks, applied.

Quoted 5 lines

Jan

--
Siemens AG, Technology
Competence Center Embedded Linux

Could you cherry-pick this commit to 3.0.x and 3.1.x aswell please?

Quoted 8 lines
Quoted 3 lines

I can. I was just not expecting someone starting something new with clang on these old versions now. If you change something as fundamental as the compiler, why sticking with that versions?

I am trying to setup a build-server which uses clang, for using sanitzers, codecoverage
and code-quality. We wont change the compiler and don't want to change the xenomai version.

(We wont change anything for our *productive software*)

Norbert

#6 lore raw
In reply to Norbert Lange
Quoted 57 lines · Norbert Lange

Am Fr., 5. Aug. 2022 um 15:45 Uhr schrieb Jan Kiszka <[email protected]>:

Quoted 49 lines · Norbert Lange
Quoted 47 lines

Am Mo., 25. Juli 2022 um 19:22 Uhr schrieb Jan Kiszka <[email protected]>:

Quoted 45 lines · Norbert Lange
Quoted 27 lines

clang will never support 'variable length array in structure', and there does not seem to be a reason for this weird construct.

---
v1->v2:
* fix algorithm

---
 testsuite/smokey/memcheck/memcheck.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
testsuite/smokey/memcheck/memcheck.c +1 -3
index a33700f49..b11d2babd 100644
@@ -80,9 +80,7 @@ static inline void swap(void *left, void *right, const size_t size)
 
 static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
 {
-     struct {
-             char x[size];
-     } __attribute__((packed)) *base = vbase;
+     char *base = (char *)vbase;
      unsigned int j, k;
      double u;
 

testsuite/smokey/memcheck/memcheck.c static void random_shuffle(void *vbase, size_t nmemb, const size_t size) · line 96

Quoted 8 lines
testsuite/smokey/memcheck/memcheck.c +1 -1
@@ -92,7 +90,7 @@ static void random_shuffle(void *vbase, size_t nmemb, const size_t size)
              k = (unsigned int)(j * u) + 1;
              if (j == k)
                      continue;
-             swap(&base[j - 1], &base[k - 1], size);
+             swap(base + (j - 1) * size, base + (k - 1) * size, size);
      }
 }
 

Thanks, applied.

Jan

--
Siemens AG, Technology
Competence Center Embedded Linux

Quoted 6 lines
Quoted 2 lines

Could you cherry-pick this commit to 3.0.x and 3.1.x aswell please?

I can. I was just not expecting someone starting something new with clang on these old versions now. If you change something as fundamental as the compiler, why sticking with that versions?

Quoted 9 lines

I am trying to setup a build-server which uses clang, for using sanitzers, codecoverage
and code-quality. We wont change the compiler and don't want to change the xenomai version.

I guess I could just use a newer version of xenomai for the tests without adverse effects,
but so far I only have one xenomai version for everything.

Ok, point taken, 3.1.x updated. 3.0.x didn't have that testcase. If something else is broken /wrt clang in that version, please send a specific patch.

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux