code format

This commit is contained in:
yuawn
2021-12-11 10:20:40 +00:00
parent 269054e5c5
commit 5b9397f3dd
7 changed files with 194 additions and 172 deletions

View File

@ -1010,7 +1010,7 @@ XXH128_hashFromCanonical(const XXH128_canonical_t *src);
* These declarations should only be used with static linking. * These declarations should only be used with static linking.
* Never use them in association with dynamic linking! * Never use them in association with dynamic linking!
***************************************************************************** *****************************************************************************
*/ */
/* /*
* These definitions are only present to allow static allocation * These definitions are only present to allow static allocation
@ -1435,7 +1435,7 @@ XXH_PUBLIC_API XXH128_hash_t XXH128(const void *data, size_t len,
#define XXH_OLD_NAMES #define XXH_OLD_NAMES
#undef XXH_OLD_NAMES /* don't actually use, it is ugly. */ #undef XXH_OLD_NAMES /* don't actually use, it is ugly. */
#endif /* XXH_DOXYGEN */ #endif /* XXH_DOXYGEN */
/*! /*!
* @} * @}
*/ */
@ -1601,6 +1601,7 @@ static void *XXH_memcpy(void *dest, const void *src, size_t size) {
static_assert((c), m); \ static_assert((c), m); \
\ \
} while (0) } while (0)
#elif defined(__cplusplus) && (__cplusplus >= 201103L) /* C++11 */ #elif defined(__cplusplus) && (__cplusplus >= 201103L) /* C++11 */
#define XXH_STATIC_ASSERT_WITH_MESSAGE(c, m) \ #define XXH_STATIC_ASSERT_WITH_MESSAGE(c, m) \
do { \ do { \
@ -1608,6 +1609,7 @@ static void *XXH_memcpy(void *dest, const void *src, size_t size) {
static_assert((c), m); \ static_assert((c), m); \
\ \
} while (0) } while (0)
#else #else
#define XXH_STATIC_ASSERT_WITH_MESSAGE(c, m) \ #define XXH_STATIC_ASSERT_WITH_MESSAGE(c, m) \
do { \ do { \
@ -1619,6 +1621,7 @@ static void *XXH_memcpy(void *dest, const void *src, size_t size) {
}; \ }; \
\ \
} while (0) } while (0)
#endif #endif
#define XXH_STATIC_ASSERT(c) XXH_STATIC_ASSERT_WITH_MESSAGE((c), #c) #define XXH_STATIC_ASSERT(c) XXH_STATIC_ASSERT_WITH_MESSAGE((c), #c)
#endif #endif
@ -1830,8 +1833,8 @@ static int XXH_isLittleEndian(void) {
return one.c[0]; return one.c[0];
} }
\
#define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian() #define XXH_CPU_LITTLE_ENDIAN XXH_isLittleEndian()
#endif #endif
#endif #endif
@ -2096,13 +2099,14 @@ static xxh_u32 XXH32_avalanche(xxh_u32 h32) {
static xxh_u32 XXH32_finalize(xxh_u32 h32, const xxh_u8 *ptr, size_t len, static xxh_u32 XXH32_finalize(xxh_u32 h32, const xxh_u8 *ptr, size_t len,
XXH_alignment align) { XXH_alignment align) {
\ \
#define XXH_PROCESS1 \ #define XXH_PROCESS1 do {
do { \
\ h32 += (*ptr++) * XXH_PRIME32_5;
h32 += (*ptr++) * XXH_PRIME32_5; \ h32 = XXH_rotl32(h32, 11) * XXH_PRIME32_1;
h32 = XXH_rotl32(h32, 11) * XXH_PRIME32_1; \
\ }
} while (0)
while (0)
#define XXH_PROCESS4 \ #define XXH_PROCESS4 \
do { \ do { \
@ -3385,6 +3389,7 @@ enum XXH_VECTOR_TYPE /* fake enum */ {
(outHi) = vget_high_u32(vreinterpretq_u32_u64(in)); \ (outHi) = vget_high_u32(vreinterpretq_u32_u64(in)); \
\ \
} while (0) } while (0)
#else #else
#define XXH_SPLIT_IN_PLACE(in, outLo, outHi) \ #define XXH_SPLIT_IN_PLACE(in, outLo, outHi) \
do { \ do { \
@ -3393,6 +3398,7 @@ enum XXH_VECTOR_TYPE /* fake enum */ {
(outHi) = vshrn_n_u64((in), 32); \ (outHi) = vshrn_n_u64((in), 32); \
\ \
} while (0) } while (0)
#endif #endif
#endif /* XXH_VECTOR == XXH_NEON */ #endif /* XXH_VECTOR == XXH_NEON */

View File

@ -882,7 +882,7 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
// BUG FIXME TODO: u64 does not work for > 64 bit ... e.g. 80 and 128 bit // BUG FIXME TODO: u64 does not work for > 64 bit ... e.g. 80 and 128 bit
if (sizeInBits > 64) { continue; } if (sizeInBits > 64) { continue; }
IntegerType *intType = IntegerType::get(C, op_size); IntegerType * intType = IntegerType::get(C, op_size);
const unsigned int precision = sizeInBits == 32 ? 24 const unsigned int precision = sizeInBits == 32 ? 24
: sizeInBits == 64 ? 53 : sizeInBits == 64 ? 53
: sizeInBits == 128 ? 113 : sizeInBits == 128 ? 113
@ -917,12 +917,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
Instruction *bpre_op0, *bpre_op1; Instruction *bpre_op0, *bpre_op1;
bpre_op0 = CastInst::Create(Instruction::BitCast, op0, bpre_op0 = CastInst::Create(Instruction::BitCast, op0,
IntegerType::get(C, op_size)); IntegerType::get(C, op_size));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), bpre_op0); bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
bpre_op0);
bpre_op1 = CastInst::Create(Instruction::BitCast, op1, bpre_op1 = CastInst::Create(Instruction::BitCast, op1,
IntegerType::get(C, op_size)); IntegerType::get(C, op_size));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), bpre_op1); bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
bpre_op1);
/* Check if any operand is NaN. /* Check if any operand is NaN.
* If so, all comparisons except unequal (which yields true) yield false */ * If so, all comparisons except unequal (which yields true) yield false */
@ -940,40 +941,40 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
/* Check op0 for NaN */ /* Check op0 for NaN */
/* Shift left 1 Bit, ignore sign bit */ /* Shift left 1 Bit, ignore sign bit */
Instruction *nan_op0, *nan_op1; Instruction *nan_op0, *nan_op1;
nan_op0 = BinaryOperator::Create( nan_op0 = BinaryOperator::Create(Instruction::Shl, bpre_op0,
Instruction::Shl, bpre_op0,
ConstantInt::get(bpre_op0->getType(), 1)); ConstantInt::get(bpre_op0->getType(), 1));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), nan_op0); bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
nan_op0);
/* compare to NaN interval */ /* compare to NaN interval */
Instruction *is_op0_nan = Instruction *is_op0_nan =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op0, ConstantInt::get(intType, NaN_lowend) ); CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op0,
ConstantInt::get(intType, NaN_lowend));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
is_op0_nan); is_op0_nan);
/* Check op1 for NaN */ /* Check op1 for NaN */
/* Shift right 1 Bit, ignore sign bit */ /* Shift right 1 Bit, ignore sign bit */
nan_op1 = BinaryOperator::Create( nan_op1 = BinaryOperator::Create(Instruction::Shl, bpre_op1,
Instruction::Shl, bpre_op1,
ConstantInt::get(bpre_op1->getType(), 1)); ConstantInt::get(bpre_op1->getType(), 1));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), nan_op1); bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
nan_op1);
/* compare to NaN interval */ /* compare to NaN interval */
Instruction *is_op1_nan = Instruction *is_op1_nan =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op1, ConstantInt::get(intType, NaN_lowend) ); CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op1,
ConstantInt::get(intType, NaN_lowend));
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
is_op1_nan); is_op1_nan);
/* combine checks */ /* combine checks */
Instruction *is_nan = BinaryOperator::Create( Instruction *is_nan =
Instruction::Or, is_op0_nan, is_op1_nan); BinaryOperator::Create(Instruction::Or, is_op0_nan, is_op1_nan);
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), is_nan);
is_nan);
/* the result of the comparison, when at least one op is NaN /* the result of the comparison, when at least one op is NaN
is true only for the "NOT EQUAL" predicates. */ is true only for the "NOT EQUAL" predicates. */
bool NaNcmp_result = bool NaNcmp_result = FcmpInst->getPredicate() == CmpInst::FCMP_ONE ||
FcmpInst->getPredicate() == CmpInst::FCMP_ONE ||
FcmpInst->getPredicate() == CmpInst::FCMP_UNE; FcmpInst->getPredicate() == CmpInst::FCMP_UNE;
BasicBlock *nonan_bb = BasicBlock *nonan_bb =
@ -989,24 +990,30 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
/*** now working in nonan_bb ***/ /*** now working in nonan_bb ***/
/* Treat -0.0 as equal to +0.0, that is for -0.0 make it +0.0 */ /* Treat -0.0 as equal to +0.0, that is for -0.0 make it +0.0 */
Instruction *b_op0, *b_op1; Instruction * b_op0, *b_op1;
Instruction *isMzero_op0, *isMzero_op1; Instruction * isMzero_op0, *isMzero_op1;
const unsigned long long MinusZero = 1UL << (sizeInBits - 1U); const unsigned long long MinusZero = 1UL << (sizeInBits - 1U);
const unsigned long long PlusZero = 0; const unsigned long long PlusZero = 0;
isMzero_op0 = isMzero_op0 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op0,
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op0, ConstantInt::get(intType, MinusZero)); ConstantInt::get(intType, MinusZero));
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op0); nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op0);
isMzero_op1 = isMzero_op1 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op1,
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op1, ConstantInt::get(intType, MinusZero)); ConstantInt::get(intType, MinusZero));
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op1); nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op1);
b_op0 = SelectInst::Create(isMzero_op0, ConstantInt::get(intType, PlusZero), bpre_op0); b_op0 = SelectInst::Create(isMzero_op0, ConstantInt::get(intType, PlusZero),
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), b_op0); bpre_op0);
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), b_op0);
b_op1 = SelectInst::Create(isMzero_op1, ConstantInt::get(intType, PlusZero), bpre_op1); b_op1 = SelectInst::Create(isMzero_op1, ConstantInt::get(intType, PlusZero),
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), b_op1); bpre_op1);
nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), b_op1);
/* isolate signs of value of floating point type */ /* isolate signs of value of floating point type */
@ -1017,22 +1024,26 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
s_s0 = s_s0 =
BinaryOperator::Create(Instruction::LShr, b_op0, BinaryOperator::Create(Instruction::LShr, b_op0,
ConstantInt::get(b_op0->getType(), op_size - 1)); ConstantInt::get(b_op0->getType(), op_size - 1));
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), s_s0); nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), s_s0);
t_s0 = new TruncInst(s_s0, Int1Ty); t_s0 = new TruncInst(s_s0, Int1Ty);
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), t_s0); nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), t_s0);
s_s1 = s_s1 =
BinaryOperator::Create(Instruction::LShr, b_op1, BinaryOperator::Create(Instruction::LShr, b_op1,
ConstantInt::get(b_op1->getType(), op_size - 1)); ConstantInt::get(b_op1->getType(), op_size - 1));
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), s_s1); nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), s_s1);
t_s1 = new TruncInst(s_s1, Int1Ty); t_s1 = new TruncInst(s_s1, Int1Ty);
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), t_s1); nonan_bb->getInstList().insert(
BasicBlock::iterator(nonan_bb->getTerminator()), t_s1);
/* compare of the sign bits */ /* compare of the sign bits */
icmp_sign_bit = icmp_sign_bit =
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, t_s0, t_s1); CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, t_s0, t_s1);
nonan_bb->getInstList().insert(BasicBlock::iterator(nonan_bb->getTerminator()), nonan_bb->getInstList().insert(
icmp_sign_bit); BasicBlock::iterator(nonan_bb->getTerminator()), icmp_sign_bit);
/* create a new basic block which is executed if the signedness bits are /* create a new basic block which is executed if the signedness bits are
* equal */ * equal */

View File

@ -7,6 +7,7 @@
#include <unistd.h> #include <unistd.h>
int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t i) { int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t i) {
if (i < 24) return 0; if (i < 24) return 0;
if (buf[0] != 'A') return 0; if (buf[0] != 'A') return 0;
if (buf[1] != 'B') return 0; if (buf[1] != 'B') return 0;
@ -16,17 +17,25 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t i) {
if (strncmp(buf + 12, "IJKL", 4) == 0 && strcmp(buf + 16, "DEADBEEF") == 0) if (strncmp(buf + 12, "IJKL", 4) == 0 && strcmp(buf + 16, "DEADBEEF") == 0)
abort(); abort();
return 0; return 0;
} }
#ifdef __AFL_COMPILER #ifdef __AFL_COMPILER
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
unsigned char buf[1024]; unsigned char buf[1024];
ssize_t i; ssize_t i;
while(__AFL_LOOP(1000)) { while (__AFL_LOOP(1000)) {
i = read(0, (char*)buf, sizeof(buf) - 1);
i = read(0, (char *)buf, sizeof(buf) - 1);
if (i > 0) buf[i] = 0; if (i > 0) buf[i] = 0;
LLVMFuzzerTestOneInput(buf, i); LLVMFuzzerTestOneInput(buf, i);
} }
return 0; return 0;
} }
#endif #endif

View File

@ -13,7 +13,7 @@ int main() {
volatile FLOAT_TYPE a, b; volatile FLOAT_TYPE a, b;
#ifdef INFINITY #ifdef INFINITY
FLOAT_TYPE inf = (FLOAT_TYPE) INFINITY; FLOAT_TYPE inf = (FLOAT_TYPE)INFINITY;
#else #else
FLOAT_TYPE inf = 1.0 / 0.0; /* produces infinity */ FLOAT_TYPE inf = 1.0 / 0.0; /* produces infinity */
#endif #endif

View File

@ -14,12 +14,12 @@ int main() {
/* NaN */ /* NaN */
#ifdef NAN #ifdef NAN
a = (FLOAT_TYPE) NAN; /* produces NaN */ a = (FLOAT_TYPE)NAN; /* produces NaN */
#else #else
a = 0.0 / 0.0; /* produces NaN */ a = 0.0 / 0.0; /* produces NaN */
#endif #endif
#ifdef INFINITY #ifdef INFINITY
FLOAT_TYPE inf = (FLOAT_TYPE) INFINITY; FLOAT_TYPE inf = (FLOAT_TYPE)INFINITY;
#else #else
FLOAT_TYPE inf = 1.0 / 0.0; /* produces infinity */ FLOAT_TYPE inf = 1.0 / 0.0; /* produces infinity */
#endif #endif

View File

@ -171,7 +171,7 @@ static void __tokencap_load_mappings(void) {
int mib[] = {CTL_VM, VM_PROC, VM_PROC_MAP, __tokencap_pid, int mib[] = {CTL_VM, VM_PROC, VM_PROC_MAP, __tokencap_pid,
sizeof(struct kinfo_vmentry)}; sizeof(struct kinfo_vmentry)};
#endif #endif
char *buf, *low, *high; char * buf, *low, *high;
size_t miblen = sizeof(mib) / sizeof(mib[0]); size_t miblen = sizeof(mib) / sizeof(mib[0]);
size_t len; size_t len;
@ -345,11 +345,7 @@ static void __tokencap_dump(const u8 *ptr, size_t len, u8 is_text) {
wrt_ok &= (pos == write(__tokencap_out_file, buf, pos)); wrt_ok &= (pos == write(__tokencap_out_file, buf, pos));
wrt_ok &= (2 == write(__tokencap_out_file, "\"\n", 2)); wrt_ok &= (2 == write(__tokencap_out_file, "\"\n", 2));
if (!wrt_ok) { if (!wrt_ok) { DEBUGF("%s", "writing to the token file failed\n"); }
DEBUGF("%s", "writing to the token file failed\n");
}
} }