[CPP-434] Initial version of query + test cases.

This commit is contained in:
Ziemowit Laski
2019-10-01 15:11:18 -07:00
parent c8e5be74d5
commit 55c26a8880
3 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
// Signed-comparison tests
/* 1. Signed-signed comparison. The semantics are undefined. */
bool cannotHoldAnother8(int n1) {
// clang 8.0.0 -O2: deleted (silently)
// gcc 9.2 -O2: deleted (silently)
// msvc 19.22 /O2: not deleted
return n1 + 8 < n1; // BAD
}
bool canHoldPreceding16(int n1) {
return n1 - 16 < n1;
}
/* 2. Signed comparison with a narrower unsigned type. The narrower
type gets promoted to the (signed) larger type, and so the
semantics are undefined. */
bool cannotHoldAnotherUShort(int n1, unsigned short delta) {
// clang 8.0.0 -O2: deleted (silently)
// gcc 9.2 -O2: deleted (silently)
// msvc 19.22 /O2: not deleted
return n1 + delta < n1; // BAD
}
bool canHoldPrecedingUShort(int n1, unsigned short delta) {
return n1 - delta < n1;
}
/* 3. Signed comparison with a non-narrower unsigned type. The
signed type gets promoted to (a possibly wider) unsigned type,
and the resulting comparison is unsigned. */
bool cannotHoldAnotherUInt(int n1, unsigned int delta) {
// clang 8.0.0 -O2: not deleted
// gcc 9.2 -O2: not deleted
// msvc 19.22 /O2: not deleted
return n1 + delta < n1; // GOOD
}
bool canHoldPrecedingUInt(int n1, unsigned int delta) {
return n1 - delta < n1;
}

View File

@@ -0,0 +1 @@
Likely Bugs/Arithmetic/SignedComparisons.ql