]> granicus.if.org Git - llvm/commitdiff
[libFuzzer] Check for target(popcnt) capability before usage
authorKuba Mracek <mracek@apple.com>
Fri, 21 Apr 2017 16:57:37 +0000 (16:57 +0000)
committerKuba Mracek <mracek@apple.com>
Fri, 21 Apr 2017 16:57:37 +0000 (16:57 +0000)
Older compilers (e.g. LLVM 3.4) do not support the attribute target("popcnt").
In order to support those, this diff check the attribute support using the preprocessor.

Patch by George Karpenkov.

Differential Revision: https://reviews.llvm.org/D32311

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300999 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Fuzzer/FuzzerDefs.h

index bd182750800257e33a308d08cb2a44223dc277f5..939b92f55ec45b851f9a003b05513f56d64da27d 100644 (file)
 #error "Support for your platform has not been implemented"
 #endif
 
+#ifndef __has_attribute
+#  define __has_attribute(x) 0
+#endif
+
 #define LIBFUZZER_POSIX LIBFUZZER_APPLE || LIBFUZZER_LINUX
 
 #ifdef __x86_64
-#define ATTRIBUTE_TARGET_POPCNT __attribute__((target("popcnt")))
+#  if __has_attribute(target)
+#    define ATTRIBUTE_TARGET_POPCNT __attribute__((target("popcnt")))
+#  else
+#    define ATTRIBUTE_TARGET_POPCNT
+#  endif
 #else
-#define ATTRIBUTE_TARGET_POPCNT
+#  define ATTRIBUTE_TARGET_POPCNT
 #endif