oksh-noxz

[fork] Portable OpenBSD ksh, based on the Public Domain Korn Shell (pdksh).
git clone https://noxz.tech/git/oksh-noxz.git
oksh-noxz

commit: 24e859a7eb8aba1c052706fe825c2c9e2ec6b94b
parent: 44a70a086e83d8a3f1f6aeb21c73ac25ace6e2cd
author: Brian Callahan <bcallah@openbsd.org>
date:   Wed, 5 Feb 2020 07:55:28 -0500
If a system doesn't have a __dead or __dead2 macro, check
explicitly for __attribute__((noreturn)) support from the compiler.
Remove the __dead macro entirely if the compiler doesn't have
attribute support.

Anticipating issues from older non-gcc/clang compilers.
Mconfigure25++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
@@ -188,6 +188,21 @@ EOF
   fi
 }
 
+noreturncheck() {
+  cat << EOF > conftest.c
+#include <stdlib.h>
+__attribute__((noreturn)) usage(void){exit(1);}int main(void){usage();return 0;}
+EOF
+  $cc $cflags $ldflags -o conftest conftest.c > /dev/null 2>&1
+  if [ $? -eq 0 ] ; then
+    rm -f conftest conftest.o conftest.c
+    return 0
+  else
+    rm -f conftest conftest.o conftest.c
+    return 1
+  fi
+}
+
 pledgecheck() {
   cat << EOF > conftest.c
 #include <unistd.h>
@@ -637,8 +652,14 @@ else
     echo "#define __dead __dead2" >> pconfig.h
     echo "yes"
   else
-    echo "#define __dead __attribute__((__no_return__))" >> pconfig.h
-    echo "no"
+    printf "checking for __attribute__((__noreturn__))... "
+    noreturncheck
+    if [ $? -eq 0 ] ; then
+      echo "#define __dead __attribute__((__noreturn__))" >> pconfig.h
+      echo "yes"
+    else
+      echo "#define __dead" >> pconfig.h
+      echo "no"
   fi
 fi