[compiler-rt] r333295 - [libFuzzer] Avoid optimization of "abs(x) < 0"

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri May 25 11:27:12 PDT 2018


Author: vitalybuka
Date: Fri May 25 11:27:12 2018
New Revision: 333295

URL: http://llvm.org/viewvc/llvm-project?rev=333295&view=rev
Log:
[libFuzzer] Avoid optimization of "abs(x) < 0"

Modified:
    compiler-rt/trunk/test/fuzzer/AbsNegAndConstant64Test.cpp
    compiler-rt/trunk/test/fuzzer/AbsNegAndConstantTest.cpp

Modified: compiler-rt/trunk/test/fuzzer/AbsNegAndConstant64Test.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/AbsNegAndConstant64Test.cpp?rev=333295&r1=333294&r2=333295&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/AbsNegAndConstant64Test.cpp (original)
+++ compiler-rt/trunk/test/fuzzer/AbsNegAndConstant64Test.cpp Fri May 25 11:27:12 2018
@@ -14,7 +14,8 @@ extern "C" int LLVMFuzzerTestOneInput(co
   uint64_t y;
   memcpy(&x, Data, sizeof(x));
   memcpy(&y, Data + sizeof(x), sizeof(y));
-  if (llabs(x) < 0 && y == 0xbaddcafedeadbeefULL) {
+  volatile int64_t abs_x = llabs(x);
+  if (abs_x < 0 && y == 0xbaddcafedeadbeefULL) {
     printf("BINGO; Found the target, exiting; x = 0x%lx y 0x%lx\n", x, y);
     fflush(stdout);
     exit(1);

Modified: compiler-rt/trunk/test/fuzzer/AbsNegAndConstantTest.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/AbsNegAndConstantTest.cpp?rev=333295&r1=333294&r2=333295&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/AbsNegAndConstantTest.cpp (original)
+++ compiler-rt/trunk/test/fuzzer/AbsNegAndConstantTest.cpp Fri May 25 11:27:12 2018
@@ -14,7 +14,8 @@ extern "C" int LLVMFuzzerTestOneInput(co
   unsigned y;
   memcpy(&x, Data, sizeof(x));
   memcpy(&y, Data + sizeof(x), sizeof(y));
-  if (abs(x) < 0 && y == 0xbaddcafe) {
+  volatile int abs_x = abs(x);
+  if (abs_x < 0 && y == 0xbaddcafe) {
     printf("BINGO; Found the target, exiting; x = 0x%x y 0x%x\n", x, y);
     fflush(stdout);
     exit(1);




More information about the llvm-commits mailing list