[RFC] clang, posix: bypass static assert that does not compile with Clang

Daniel Hellstrom daniel at gaisler.com
Fri Oct 5 06:57:51 UTC 2018


From: Jacob Hansen <jacob.hansen at gaisler.com>

This commits bypasses a static assert when using the Clang compiler.
This is done as the static assertion does not compile with Clang
("static_assert expression is not an integral constant expression").

I am not sure this static assertion makes sense at all. SEM_FAILED
is used as a return value on failures from running sem_open(). Is
the test supposed to check that SEM_FAILED is defiend as NULL in the
included libraries (newlib) ? It is defiend as "(sem_t *) 0" in newlib.

The draft version of the posix standard, required sem_open to return -1, so
maybe this is an attempt to ensure that SEM_FAILED is actually defined?
But the compilation would failed if SEM_FAILED is not defined anyway.

I guess the check would make sense if somehow the code depended on
SEM_FAILED to be equal to NULL. But in that case I would think the code
should be updated to remove this dependency.

Looking at the source for sem_open at cpukit/posix/src/semopen.c it
seems that it uses the SEM_FAILED define as a return value, and I do not
see any dependencies on SEM_FAILED==NULL anywhere.

The change that introduces this code is:

"posix: Implement self-contained POSIX semaphores":
  c090db7405b72ce6d0b726c0a39fb1c1aebab7ea
---
 cpukit/posix/src/seminit.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cpukit/posix/src/seminit.c b/cpukit/posix/src/seminit.c
index 65104ad..5c91a8e 100644
--- a/cpukit/posix/src/seminit.c
+++ b/cpukit/posix/src/seminit.c
@@ -22,7 +22,9 @@
 
 #include <limits.h>
 
+#ifndef __clang__
 RTEMS_STATIC_ASSERT(NULL == SEM_FAILED, sem_failed);
+#endif
 
 /*
  *  11.2.1 Initialize an Unnamed Semaphore, P1003.1b-1993, p.219
-- 
2.7.4




More information about the devel mailing list