[llvm] r300999 - [libFuzzer] Check for target(popcnt) capability before usage

Kuba Mracek via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 21 09:57:38 PDT 2017


Author: kuba.brecka
Date: Fri Apr 21 11:57:37 2017
New Revision: 300999

URL: http://llvm.org/viewvc/llvm-project?rev=300999&view=rev
Log:
[libFuzzer] Check for target(popcnt) capability before usage

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


Modified:
    llvm/trunk/lib/Fuzzer/FuzzerDefs.h

Modified: llvm/trunk/lib/Fuzzer/FuzzerDefs.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerDefs.h?rev=300999&r1=300998&r2=300999&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerDefs.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerDefs.h Fri Apr 21 11:57:37 2017
@@ -36,12 +36,20 @@
 #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
 
 




More information about the llvm-commits mailing list