
# Copyright (C) Igor Sysoev
# Copyright (C) NGINX, Inc.

# C language features.

njs_feature="GCC __builtin_expect()"
njs_feature_name=NJS_HAVE_BUILTIN_EXPECT
njs_feature_run=no
njs_feature_incs=
njs_feature_libs=
njs_feature_test="int main(int argc, char *const *argv) {
                      if ((__typeof__(argc == 0))
                                   __builtin_expect((argc == 0), 0))
                          return 0;
                      return 1;
                  }"
. auto/feature


njs_feature="GCC __builtin_unreachable()"
njs_feature_name=NJS_HAVE_BUILTIN_UNREACHABLE
njs_feature_run=no
njs_feature_incs=
njs_feature_libs=
njs_feature_test="int main(void) {
                      __builtin_unreachable();
                  }"
. auto/feature


njs_feature="GCC __builtin_prefetch()"
njs_feature_name=NJS_HAVE_BUILTIN_PREFETCH
njs_feature_run=no
njs_feature_incs=
njs_feature_libs=
njs_feature_test="int main(void) {
                      __builtin_prefetch(0);
                      return 0;
                  }"
. auto/feature


njs_feature="GCC __builtin_clz()"
njs_feature_name=NJS_HAVE_BUILTIN_CLZ
njs_feature_run=no
njs_feature_incs=
njs_feature_libs=
njs_feature_test="int main(void) {
                      if (__builtin_clz(1) != 31) {
                          return 1;
                      }
                      return 0;
                  }"
. auto/feature


njs_feature="GCC __builtin_clzll()"
njs_feature_name=NJS_HAVE_BUILTIN_CLZLL
njs_feature_run=no
njs_feature_incs=
njs_feature_libs=
njs_feature_test="int main(void) {
                      if (__builtin_clzll(1ULL) != 63) {
                          return 1;
                      }
                      return 0;
                  }"
. auto/feature


njs_feature="GCC __attribute__ visibility"
njs_feature_name=NJS_HAVE_GCC_ATTRIBUTE_VISIBILITY
njs_feature_run=no
njs_feature_path=
njs_feature_libs=
njs_feature_test="int n __attribute__ ((visibility(\"default\")));

                  int main(void) {
                      return 0;
                  }"
. auto/feature


njs_feature="GCC __attribute__ malloc"
njs_feature_name=NJS_HAVE_GCC_ATTRIBUTE_MALLOC
njs_feature_run=no
njs_feature_path=
njs_feature_libs=
njs_feature_test="#include <stdlib.h>

                  void *f(void) __attribute__ ((__malloc__));

                  void *f(void) {
                      return malloc(1);
                  }

                  int main(void) {
                      if (f() != NULL) {
                          return 1;
                      }
                      return 0;
                  }"
. auto/feature


njs_feature="GCC __attribute__ aligned"
njs_feature_name=NJS_HAVE_GCC_ATTRIBUTE_ALIGNED
njs_feature_run=no
njs_feature_path=
njs_feature_libs=
njs_feature_test="int n __attribute__ ((aligned(64)));

                  int main(void) {
                    return 0;
                  }"
. auto/feature


njs_feature="GCC __attribute__ packed"
njs_feature_name=NJS_HAVE_GCC_ATTRIBUTE_PACKED
njs_feature_run=no
njs_feature_path=
njs_feature_libs=
njs_feature_test="struct __attribute__((packed)) s { char v; };

                  int main(void) {
                    return 0;
                  }"
. auto/feature


njs_feature="GCC __attribute__ fallthrough"
njs_feature_name=NJS_HAVE_GCC_ATTRIBUTE_FALLTHROUGH
njs_feature_run=no
njs_feature_path=
njs_feature_libs=
njs_feature_test="int main(int argc, char *argv[]) {
                    switch (argc) {
                    case 0:
                      argc++;
                      __attribute__((fallthrough));
                    default:
                      argc++;
                    }

                    return argc;
                  }"
. auto/feature


njs_feature="GCC __attribute__ no_sanitize"
njs_feature_name=NJS_HAVE_GCC_ATTRIBUTE_NO_SANITIZE
njs_feature_run=no
njs_feature_path=
njs_feature_libs=
njs_feature_test="__attribute__((no_sanitize(\"undefined\"))) int main(void) {
                    return 0;
                  }"
. auto/feature


njs_feature="Address sanitizer"
njs_feature_name=NJS_HAVE_ADDRESS_SANITIZER
njs_feature_run=no
njs_feature_path=
njs_feature_libs=
njs_feature_test="int main(void) {
                      return
                  #ifdef __SANITIZE_ADDRESS__
                          0;
                  #else
                      #if defined(__has_feature)
                          #if __has_feature(address_sanitizer)
                          0;
                          #endif
                      #endif
                  #endif
                  }"
. auto/feature


njs_feature="Memory sanitizer"
njs_feature_name=NJS_HAVE_MEMORY_SANITIZER
njs_feature_run=yes
njs_feature_incs=
njs_feature_libs=
njs_feature_test="#include <sanitizer/msan_interface.h>
                  int main(int argc, char *argv[]) {
                      __msan_unpoison(argv, sizeof(char *));
                      return 0;
                  }"
. auto/feature
