mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
C++: port sign analysis library from Java
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
// The ASM statements are
|
||||
// causing problems, because our SSA analysis does not notice that they
|
||||
// might change the value of `x`. This was a latent bug that came out
|
||||
// of the woodwork when we added support for statement expressions.
|
||||
|
||||
int printf(const char *format, ...);
|
||||
|
||||
int main() {
|
||||
unsigned int x = 0, y;
|
||||
y = 1;
|
||||
|
||||
printf("x = %i y = %i\n", x, y); // 0, 1
|
||||
|
||||
// exchange x and y
|
||||
asm volatile ( "xchg %0, %1\n"
|
||||
: "+r" (x), "+a" (y) // outputs (x and y)
|
||||
:
|
||||
:
|
||||
);
|
||||
|
||||
printf("x = %i y = %i\n", x, y); // 1, 0 (but without analysing the ASM: unknown, unknown)
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// semmle-extractor-options: --gnu_version 40400
|
||||
// Note: this file uses statement expressions, which are a GNU extension,
|
||||
// so it has an options file to specify the compiler version. The statement
|
||||
// expression extension is described here:
|
||||
// https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
|
||||
|
||||
int printf(const char *format, ...);
|
||||
|
||||
// The & operator is
|
||||
// causing problems, because it disables SSA. Also, range analysis did not
|
||||
// have support for the statement expression language feature that is used
|
||||
// here.
|
||||
|
||||
void minmax()
|
||||
{
|
||||
int x = 1, y = 2, z = 3;
|
||||
|
||||
printf("x = %i, y = %i, z = %i\n", x, y, z); // 1, 2, 3
|
||||
|
||||
z = ({
|
||||
int t = 0;
|
||||
if (&x != &y) {t = x;} // t = 1
|
||||
t;
|
||||
});
|
||||
|
||||
printf("x = %i, y = %i, z = %i\n", x, y, z); // 1, 2, 1
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
| test.c:67:7:67:11 | r0_6(int) = Constant[-1000] | test.c:67:7:67:11 | - ... |
|
||||
| test.c:154:39:154:40 | r3_0(long long) = Constant[-1] | test.c:154:39:154:40 | (long long)... |
|
||||
| test.c:171:7:171:8 | r16_1(int) = Constant[-7] | test.c:171:7:171:8 | - ... |
|
||||
| test.c:176:7:176:8 | r1_1(int) = Constant[-7] | test.c:176:7:176:8 | - ... |
|
||||
| test.c:181:7:181:8 | r4_1(int) = Constant[-7] | test.c:181:7:181:8 | - ... |
|
||||
| test.c:186:7:186:8 | r7_1(int) = Constant[-7] | test.c:186:7:186:8 | - ... |
|
||||
| test.c:186:23:186:24 | r9_2(int) = Constant[-2] | test.c:186:23:186:24 | - ... |
|
||||
| test.c:208:28:208:30 | r25_0(int) = Constant[-13] | test.c:208:28:208:30 | - ... |
|
||||
| test.c:212:28:212:30 | r5_0(int) = Constant[-13] | test.c:212:28:212:30 | - ... |
|
||||
| test.c:216:28:216:30 | r10_0(int) = Constant[-13] | test.c:216:28:216:30 | - ... |
|
||||
| test.c:216:45:216:46 | r11_2(int) = Constant[-7] | test.c:216:45:216:46 | - ... |
|
||||
| test.c:236:28:236:30 | r25_0(int) = Constant[-13] | test.c:236:28:236:30 | - ... |
|
||||
| test.c:240:28:240:30 | r5_0(int) = Constant[-13] | test.c:240:28:240:30 | - ... |
|
||||
| test.c:244:28:244:30 | r10_0(int) = Constant[-13] | test.c:244:28:244:30 | - ... |
|
||||
| test.c:244:45:244:46 | r11_2(int) = Constant[-7] | test.c:244:45:244:46 | - ... |
|
||||
| test.c:256:7:256:9 | r0_9(int) = Constant[-17] | test.c:256:7:256:9 | - ... |
|
||||
| test.c:260:7:260:9 | r18_1(int) = Constant[-17] | test.c:260:7:260:9 | - ... |
|
||||
| test.c:264:7:264:9 | r23_1(int) = Constant[-17] | test.c:264:7:264:9 | - ... |
|
||||
| test.c:264:30:264:32 | r25_0(int) = Constant[-13] | test.c:264:30:264:32 | - ... |
|
||||
| test.c:268:7:268:9 | r3_1(int) = Constant[-17] | test.c:268:7:268:9 | - ... |
|
||||
| test.c:268:30:268:32 | r5_0(int) = Constant[-13] | test.c:268:30:268:32 | - ... |
|
||||
| test.c:272:7:272:9 | r8_1(int) = Constant[-17] | test.c:272:7:272:9 | - ... |
|
||||
| test.c:272:30:272:32 | r10_0(int) = Constant[-13] | test.c:272:30:272:32 | - ... |
|
||||
| test.c:272:47:272:48 | r11_2(int) = Constant[-7] | test.c:272:47:272:48 | - ... |
|
||||
| test.c:284:7:284:9 | r0_9(int) = Constant[-17] | test.c:284:7:284:9 | - ... |
|
||||
| test.c:288:7:288:9 | r18_1(int) = Constant[-17] | test.c:288:7:288:9 | - ... |
|
||||
| test.c:292:7:292:9 | r23_1(int) = Constant[-17] | test.c:292:7:292:9 | - ... |
|
||||
| test.c:292:29:292:31 | r25_0(int) = Constant[-13] | test.c:292:29:292:31 | - ... |
|
||||
| test.c:296:7:296:9 | r3_1(int) = Constant[-17] | test.c:296:7:296:9 | - ... |
|
||||
| test.c:296:29:296:31 | r5_0(int) = Constant[-13] | test.c:296:29:296:31 | - ... |
|
||||
| test.c:300:7:300:9 | r8_1(int) = Constant[-17] | test.c:300:7:300:9 | - ... |
|
||||
| test.c:300:29:300:31 | r10_0(int) = Constant[-13] | test.c:300:29:300:31 | - ... |
|
||||
| test.c:300:46:300:47 | r11_2(int) = Constant[-7] | test.c:300:46:300:47 | - ... |
|
||||
| test.c:312:7:312:9 | r0_9(int) = Constant[-17] | test.c:312:7:312:9 | - ... |
|
||||
| test.c:312:24:312:25 | r14_2(int) = Constant[-2] | test.c:312:24:312:25 | - ... |
|
||||
| test.c:316:7:316:9 | r18_1(int) = Constant[-17] | test.c:316:7:316:9 | - ... |
|
||||
| test.c:316:24:316:25 | r19_2(int) = Constant[-2] | test.c:316:24:316:25 | - ... |
|
||||
| test.c:320:7:320:9 | r23_1(int) = Constant[-17] | test.c:320:7:320:9 | - ... |
|
||||
| test.c:320:24:320:25 | r24_2(int) = Constant[-2] | test.c:320:24:320:25 | - ... |
|
||||
| test.c:320:30:320:32 | r25_0(int) = Constant[-13] | test.c:320:30:320:32 | - ... |
|
||||
| test.c:324:7:324:9 | r3_1(int) = Constant[-17] | test.c:324:7:324:9 | - ... |
|
||||
| test.c:324:24:324:25 | r4_2(int) = Constant[-2] | test.c:324:24:324:25 | - ... |
|
||||
| test.c:324:30:324:32 | r5_0(int) = Constant[-13] | test.c:324:30:324:32 | - ... |
|
||||
| test.c:328:7:328:9 | r8_1(int) = Constant[-17] | test.c:328:7:328:9 | - ... |
|
||||
| test.c:328:24:328:25 | r9_2(int) = Constant[-2] | test.c:328:24:328:25 | - ... |
|
||||
| test.c:328:30:328:32 | r10_0(int) = Constant[-13] | test.c:328:30:328:32 | - ... |
|
||||
| test.c:328:47:328:48 | r11_2(int) = Constant[-7] | test.c:328:47:328:48 | - ... |
|
||||
| test.c:339:12:339:13 | r2_1(int) = Constant[-1] | test.c:339:12:339:13 | - ... |
|
||||
| test.cpp:9:11:9:12 | r0_7(int) = Constant[-1] | test.cpp:9:11:9:12 | - ... |
|
||||
| test.cpp:30:12:30:13 | r11_3(int) = Constant[-1] | test.cpp:30:12:30:13 | - ... |
|
||||
| test.cpp:31:9:31:10 | r12_0(int) = Constant[-1] | test.cpp:31:9:31:10 | - ... |
|
||||
| test.cpp:36:12:36:15 | r15_3(int) = Constant[-128] | test.cpp:36:12:36:15 | - ... |
|
||||
| test.cpp:37:9:37:12 | r16_0(int) = Constant[-128] | test.cpp:37:9:37:12 | - ... |
|
||||
| test.cpp:42:12:42:16 | r19_3(int) = Constant[-1024] | test.cpp:42:12:42:16 | - ... |
|
||||
| test.cpp:43:9:43:13 | r20_0(int) = Constant[-1024] | test.cpp:43:9:43:13 | - ... |
|
||||
@@ -0,0 +1,6 @@
|
||||
import semmle.code.cpp.rangeanalysis.SignAnalysis
|
||||
import semmle.code.cpp.ir.IR
|
||||
|
||||
from Instruction i
|
||||
where negative(i)
|
||||
select i, i.getAST()
|
||||
@@ -0,0 +1,136 @@
|
||||
| inline_assembly.c:10:7:10:7 | r0_7(unsigned int) = Constant[1] | inline_assembly.c:10:7:10:7 | (unsigned int)... |
|
||||
| minmax.c:16:9:16:10 | r0_3(int) = Constant[1] | minmax.c:16:9:16:10 | 1 |
|
||||
| minmax.c:16:16:16:17 | r0_6(int) = Constant[2] | minmax.c:16:16:16:17 | 2 |
|
||||
| minmax.c:16:23:16:24 | r0_9(int) = Constant[3] | minmax.c:16:23:16:24 | 3 |
|
||||
| test.c:8:19:8:19 | r2_2(int) = Constant[1] | test.c:8:19:8:19 | 1 |
|
||||
| test.c:16:20:16:20 | r2_2(int) = Constant[1] | test.c:16:20:16:20 | 1 |
|
||||
| test.c:16:25:16:26 | r2_4(int) = Constant[10] | test.c:16:25:16:26 | 10 |
|
||||
| test.c:24:5:24:11 | r2_2(int) = Constant[1] | test.c:24:5:24:11 | ... ++ |
|
||||
| test.c:25:21:25:22 | r2_7(int) = Constant[10] | test.c:25:21:25:22 | 10 |
|
||||
| test.c:33:19:33:19 | r1_4(int) = Constant[2] | test.c:33:19:33:19 | 2 |
|
||||
| test.c:33:28:33:28 | r2_8(int) = Constant[1] | test.c:33:28:33:28 | 1 |
|
||||
| test.c:42:19:42:19 | r1_4(int) = Constant[2] | test.c:42:19:42:19 | 2 |
|
||||
| test.c:42:22:42:24 | r2_8(int) = Constant[1] | test.c:42:22:42:24 | ... ++ |
|
||||
| test.c:51:17:51:17 | r1_4(int) = Constant[2] | test.c:51:17:51:17 | 2 |
|
||||
| test.c:51:21:51:21 | r1_6(int) = Constant[4] | test.c:51:21:51:21 | 4 |
|
||||
| test.c:51:30:51:30 | r2_8(int) = Constant[1] | test.c:51:30:51:30 | 1 |
|
||||
| test.c:58:11:58:11 | r0_6(int) = Constant[4] | test.c:58:11:58:11 | 4 |
|
||||
| test.c:59:13:59:13 | r2_2(int) = Constant[5] | test.c:59:13:59:13 | 5 |
|
||||
| test.c:63:10:63:10 | r4_1(int) = Constant[1] | test.c:63:10:63:10 | 1 |
|
||||
| test.c:67:24:67:25 | r2_2(int) = Constant[10] | test.c:67:24:67:25 | 10 |
|
||||
| test.c:68:15:68:15 | r3_4(int) = Constant[2] | test.c:68:15:68:15 | 2 |
|
||||
| test.c:77:13:77:13 | r2_2(int) = Constant[4] | test.c:77:13:77:13 | 4 |
|
||||
| test.c:81:13:81:13 | r4_2(int) = Constant[4] | test.c:81:13:81:13 | 4 |
|
||||
| test.c:82:14:82:14 | r5_1(int) = Constant[1] | test.c:82:14:82:14 | 1 |
|
||||
| test.c:89:11:89:11 | r0_8(int) = Constant[7] | test.c:89:11:89:11 | 7 |
|
||||
| test.c:95:10:95:10 | r5_1(int) = Constant[1] | test.c:95:10:95:10 | 1 |
|
||||
| test.c:102:6:102:8 | r2_3(int) = Constant[1] | test.c:102:6:102:8 | ... ++ |
|
||||
| test.c:104:12:104:14 | r3_4(int) = Constant[58] | test.c:104:12:104:14 | 58 |
|
||||
| test.c:107:8:107:10 | r5_3(int) = Constant[1] | test.c:107:8:107:10 | ... ++ |
|
||||
| test.c:109:14:109:16 | r6_3(int) = Constant[44] | test.c:109:14:109:16 | 44 |
|
||||
| test.c:110:14:110:14 | r7_1(int) = Constant[1] | test.c:110:14:110:14 | 1 |
|
||||
| test.c:119:10:119:12 | r0_8(unsigned long long) = Constant[1] | test.c:119:10:119:12 | ... ++ |
|
||||
| test.c:124:36:124:36 | r1_5(unsigned long long) = Constant[1] | test.c:124:36:124:36 | (unsigned long long)... |
|
||||
| test.c:127:24:127:24 | r2_6(unsigned long long) = Constant[1] | test.c:127:24:127:24 | (unsigned long long)... |
|
||||
| test.c:130:11:130:11 | r3_1(int) = Constant[1] | test.c:130:11:130:11 | 1 |
|
||||
| test.c:137:22:137:22 | r0_17(unsigned int) = Constant[1] | test.c:137:22:137:22 | (unsigned int)... |
|
||||
| test.c:138:13:138:13 | r0_23(int) = Constant[1] | test.c:138:13:138:13 | 1 |
|
||||
| test.c:161:7:161:7 | r0_7(int) = Constant[3] | test.c:161:7:161:7 | 3 |
|
||||
| test.c:161:22:161:23 | r8_2(int) = Constant[11] | test.c:161:22:161:23 | 11 |
|
||||
| test.c:166:22:166:23 | r14_2(int) = Constant[11] | test.c:166:22:166:23 | 11 |
|
||||
| test.c:171:23:171:24 | r17_2(int) = Constant[11] | test.c:171:23:171:24 | 11 |
|
||||
| test.c:176:23:176:23 | r2_2(int) = Constant[1] | test.c:176:23:176:23 | 1 |
|
||||
| test.c:200:7:200:7 | r0_9(int) = Constant[3] | test.c:200:7:200:7 | 3 |
|
||||
| test.c:200:22:200:23 | r14_2(int) = Constant[11] | test.c:200:22:200:23 | 11 |
|
||||
| test.c:200:28:200:28 | r15_0(int) = Constant[5] | test.c:200:28:200:28 | 5 |
|
||||
| test.c:200:43:200:44 | r16_2(int) = Constant[23] | test.c:200:43:200:44 | 23 |
|
||||
| test.c:204:7:204:7 | r18_1(int) = Constant[3] | test.c:204:7:204:7 | 3 |
|
||||
| test.c:204:22:204:23 | r19_2(int) = Constant[11] | test.c:204:22:204:23 | 11 |
|
||||
| test.c:204:43:204:44 | r21_2(int) = Constant[23] | test.c:204:43:204:44 | 23 |
|
||||
| test.c:208:7:208:7 | r23_1(int) = Constant[3] | test.c:208:7:208:7 | 3 |
|
||||
| test.c:208:22:208:23 | r24_2(int) = Constant[11] | test.c:208:22:208:23 | 11 |
|
||||
| test.c:208:45:208:46 | r1_2(int) = Constant[23] | test.c:208:45:208:46 | 23 |
|
||||
| test.c:212:7:212:7 | r3_1(int) = Constant[3] | test.c:212:7:212:7 | 3 |
|
||||
| test.c:212:22:212:23 | r4_2(int) = Constant[11] | test.c:212:22:212:23 | 11 |
|
||||
| test.c:216:7:216:7 | r8_1(int) = Constant[3] | test.c:216:7:216:7 | 3 |
|
||||
| test.c:216:22:216:23 | r9_2(int) = Constant[11] | test.c:216:22:216:23 | 11 |
|
||||
| test.c:228:22:228:23 | r14_2(int) = Constant[11] | test.c:228:22:228:23 | 11 |
|
||||
| test.c:228:28:228:28 | r15_0(int) = Constant[5] | test.c:228:28:228:28 | 5 |
|
||||
| test.c:228:43:228:44 | r16_2(int) = Constant[23] | test.c:228:43:228:44 | 23 |
|
||||
| test.c:232:22:232:23 | r19_2(int) = Constant[11] | test.c:232:22:232:23 | 11 |
|
||||
| test.c:232:43:232:44 | r21_2(int) = Constant[23] | test.c:232:43:232:44 | 23 |
|
||||
| test.c:236:22:236:23 | r24_2(int) = Constant[11] | test.c:236:22:236:23 | 11 |
|
||||
| test.c:236:45:236:46 | r1_2(int) = Constant[23] | test.c:236:45:236:46 | 23 |
|
||||
| test.c:240:22:240:23 | r4_2(int) = Constant[11] | test.c:240:22:240:23 | 11 |
|
||||
| test.c:244:22:244:23 | r9_2(int) = Constant[11] | test.c:244:22:244:23 | 11 |
|
||||
| test.c:256:24:256:25 | r14_2(int) = Constant[11] | test.c:256:24:256:25 | 11 |
|
||||
| test.c:256:30:256:30 | r15_0(int) = Constant[5] | test.c:256:30:256:30 | 5 |
|
||||
| test.c:256:45:256:46 | r16_2(int) = Constant[23] | test.c:256:45:256:46 | 23 |
|
||||
| test.c:260:24:260:25 | r19_2(int) = Constant[11] | test.c:260:24:260:25 | 11 |
|
||||
| test.c:260:45:260:46 | r21_2(int) = Constant[23] | test.c:260:45:260:46 | 23 |
|
||||
| test.c:264:24:264:25 | r24_2(int) = Constant[11] | test.c:264:24:264:25 | 11 |
|
||||
| test.c:264:47:264:48 | r1_2(int) = Constant[23] | test.c:264:47:264:48 | 23 |
|
||||
| test.c:268:24:268:25 | r4_2(int) = Constant[11] | test.c:268:24:268:25 | 11 |
|
||||
| test.c:272:24:272:25 | r9_2(int) = Constant[11] | test.c:272:24:272:25 | 11 |
|
||||
| test.c:284:29:284:29 | r15_0(int) = Constant[5] | test.c:284:29:284:29 | 5 |
|
||||
| test.c:284:44:284:45 | r16_2(int) = Constant[23] | test.c:284:44:284:45 | 23 |
|
||||
| test.c:288:44:288:45 | r21_2(int) = Constant[23] | test.c:288:44:288:45 | 23 |
|
||||
| test.c:292:46:292:47 | r1_2(int) = Constant[23] | test.c:292:46:292:47 | 23 |
|
||||
| test.c:312:30:312:30 | r15_0(int) = Constant[5] | test.c:312:30:312:30 | 5 |
|
||||
| test.c:312:45:312:46 | r16_2(int) = Constant[23] | test.c:312:45:312:46 | 23 |
|
||||
| test.c:316:45:316:46 | r21_2(int) = Constant[23] | test.c:316:45:316:46 | 23 |
|
||||
| test.c:320:47:320:48 | r1_2(int) = Constant[23] | test.c:320:47:320:48 | 23 |
|
||||
| test.c:342:14:342:14 | r3_3(int) = Constant[3] | test.c:342:14:342:14 | 3 |
|
||||
| test.c:343:5:343:7 | r4_2(int) = Constant[1] | test.c:343:5:343:7 | ... ++ |
|
||||
| test.c:348:14:348:14 | r7_1(int) = Constant[1] | test.c:348:14:348:14 | 1 |
|
||||
| test.c:357:12:357:14 | r0_22(unsigned int) = Constant[100] | test.c:357:12:357:14 | (unsigned int)... |
|
||||
| test.c:357:22:357:23 | r22_0(unsigned int) = Constant[10] | test.c:357:22:357:23 | (unsigned int)... |
|
||||
| test.c:358:13:358:15 | r17_7(unsigned int) = Constant[100] | test.c:358:13:358:15 | (unsigned int)... |
|
||||
| test.c:358:19:358:20 | r24_0(unsigned int) = Constant[10] | test.c:358:19:358:20 | (unsigned int)... |
|
||||
| test.c:365:11:365:13 | r23_25(unsigned int) = Constant[300] | test.c:365:11:365:13 | (unsigned int)... |
|
||||
| test.c:366:15:366:15 | r38_0(unsigned int) = Constant[5] | test.c:366:15:366:15 | (unsigned int)... |
|
||||
| test.c:366:15:366:15 | r40_0(unsigned int) = Constant[5] | test.c:366:15:366:15 | (unsigned int)... |
|
||||
| test.c:367:15:367:17 | r48_0(unsigned int) = Constant[500] | test.c:367:15:367:17 | (unsigned int)... |
|
||||
| test.c:367:15:367:17 | r50_0(unsigned int) = Constant[500] | test.c:367:15:367:17 | (unsigned int)... |
|
||||
| test.c:368:13:368:13 | r27_0(unsigned int) = Constant[1] | test.c:368:13:368:13 | (unsigned int)... |
|
||||
| test.c:368:13:368:13 | r54_0(unsigned int) = Constant[1] | test.c:368:13:368:13 | (unsigned int)... |
|
||||
| test.c:368:19:368:21 | r55_0(unsigned int) = Constant[500] | test.c:368:19:368:21 | (unsigned int)... |
|
||||
| test.c:369:29:369:29 | r4_0(unsigned int) = Constant[1] | test.c:369:29:369:29 | (unsigned int)... |
|
||||
| test.c:369:29:369:29 | r41_0(unsigned int) = Constant[1] | test.c:369:29:369:29 | (unsigned int)... |
|
||||
| test.c:369:36:369:36 | r5_0(int) = Constant[5] | test.c:369:36:369:36 | 5 |
|
||||
| test.c:370:29:370:29 | r9_0(unsigned int) = Constant[1] | test.c:370:29:370:29 | (unsigned int)... |
|
||||
| test.c:370:29:370:29 | r41_0(unsigned int) = Constant[1] | test.c:370:29:370:29 | (unsigned int)... |
|
||||
| test.c:370:36:370:38 | r10_0(int) = Constant[500] | test.c:370:36:370:38 | 500 |
|
||||
| test.c:371:30:371:30 | r14_0(unsigned int) = Constant[1] | test.c:371:30:371:30 | (unsigned int)... |
|
||||
| test.c:371:30:371:30 | r41_0(unsigned int) = Constant[1] | test.c:371:30:371:30 | (unsigned int)... |
|
||||
| test.c:371:37:371:39 | r15_0(int) = Constant[500] | test.c:371:37:371:39 | 500 |
|
||||
| test.c:379:12:379:14 | r0_16(unsigned int) = Constant[100] | test.c:379:12:379:14 | (unsigned int)... |
|
||||
| test.c:379:22:379:24 | r5_0(unsigned int) = Constant[110] | test.c:379:22:379:24 | (unsigned int)... |
|
||||
| test.c:380:13:380:15 | r1_7(unsigned int) = Constant[100] | test.c:380:13:380:15 | (unsigned int)... |
|
||||
| test.c:380:19:380:21 | r7_0(unsigned int) = Constant[110] | test.c:380:19:380:21 | (unsigned int)... |
|
||||
| test.c:381:8:381:11 | r6_5(unsigned int) = Constant[1000] | test.c:381:8:381:11 | (unsigned int)... |
|
||||
| test.c:382:8:382:11 | r6_8(unsigned int) = Constant[1000] | test.c:382:8:382:11 | (unsigned int)... |
|
||||
| test.c:383:8:383:11 | r6_11(unsigned int) = Constant[1000] | test.c:383:8:383:11 | (unsigned int)... |
|
||||
| test.c:384:12:384:14 | r6_16(unsigned int) = Constant[300] | test.c:384:12:384:14 | (unsigned int)... |
|
||||
| test.c:385:13:385:15 | r11_0(unsigned int) = Constant[300] | test.c:385:13:385:15 | (unsigned int)... |
|
||||
| test.c:385:13:385:15 | r18_0(unsigned int) = Constant[300] | test.c:385:13:385:15 | (unsigned int)... |
|
||||
| test.c:385:21:385:21 | r19_0(unsigned int) = Constant[5] | test.c:385:21:385:21 | (unsigned int)... |
|
||||
| test.c:386:13:386:15 | r11_0(unsigned int) = Constant[200] | test.c:386:13:386:15 | (unsigned int)... |
|
||||
| test.c:386:13:386:15 | r24_0(unsigned int) = Constant[200] | test.c:386:13:386:15 | (unsigned int)... |
|
||||
| test.c:386:21:386:21 | r25_0(unsigned int) = Constant[5] | test.c:386:21:386:21 | (unsigned int)... |
|
||||
| test.c:387:29:387:31 | r28_0(unsigned int) = Constant[200] | test.c:387:29:387:31 | (unsigned int)... |
|
||||
| test.c:387:29:387:31 | r30_0(unsigned int) = Constant[200] | test.c:387:29:387:31 | (unsigned int)... |
|
||||
| test.c:387:38:387:38 | r31_0(int) = Constant[5] | test.c:387:38:387:38 | 5 |
|
||||
| test.c:394:24:394:26 | r0_7(unsigned int) = Constant[100] | test.c:394:24:394:26 | (unsigned int)... |
|
||||
| test.c:394:34:394:36 | r2_0(unsigned int) = Constant[100] | test.c:394:34:394:36 | (unsigned int)... |
|
||||
| test.c:397:9:397:11 | r3_10(unsigned int) = Constant[1] | test.c:397:9:397:11 | ++ ... |
|
||||
| test.c:398:9:398:11 | r3_19(unsigned int) = Constant[1] | test.c:398:9:398:11 | ... ++ |
|
||||
| test.c:398:19:398:19 | r3_22(unsigned int) = Constant[3] | test.c:398:19:398:19 | (unsigned int)... |
|
||||
| test.cpp:11:13:11:13 | r1_2(int) = Constant[3] | test.cpp:11:13:11:13 | 3 |
|
||||
| test.cpp:33:12:33:12 | r13_3(int) = Constant[1] | test.cpp:33:12:33:12 | 1 |
|
||||
| test.cpp:34:9:34:9 | r14_0(int) = Constant[1] | test.cpp:34:9:34:9 | 1 |
|
||||
| test.cpp:39:12:39:14 | r17_3(int) = Constant[128] | test.cpp:39:12:39:14 | 128 |
|
||||
| test.cpp:40:9:40:11 | r18_0(int) = Constant[128] | test.cpp:40:9:40:11 | 128 |
|
||||
| test.cpp:45:12:45:15 | r21_3(int) = Constant[1024] | test.cpp:45:12:45:15 | 1024 |
|
||||
| test.cpp:46:9:46:12 | r22_0(int) = Constant[1024] | test.cpp:46:9:46:12 | 1024 |
|
||||
| test.cpp:69:10:69:21 | r9_1(bool) = Constant[1] | test.cpp:69:10:69:21 | ... \|\| ... |
|
||||
@@ -0,0 +1,6 @@
|
||||
import semmle.code.cpp.rangeanalysis.SignAnalysis
|
||||
import semmle.code.cpp.ir.IR
|
||||
|
||||
from Instruction i
|
||||
where positive(i)
|
||||
select i, i.getAST()
|
||||
@@ -0,0 +1,64 @@
|
||||
| test.c:67:7:67:11 | r0_6(int) = Constant[-1000] | test.c:67:7:67:11 | - ... |
|
||||
| test.c:137:20:137:22 | m0_19(unsigned int) = Store r0_14, r0_18 | test.c:137:20:137:22 | ... - ... |
|
||||
| test.c:137:20:137:22 | r0_18(unsigned int) = Sub r0_16, r0_17 | test.c:137:20:137:22 | ... - ... |
|
||||
| test.c:139:36:139:36 | r0_42(unsigned int) = Load r0_41, m0_19 | test.c:139:36:139:36 | y |
|
||||
| test.c:154:10:154:40 | m3_2(long long) = Store r3_1, r3_0 | test.c:154:10:154:40 | ... ? ... : ... |
|
||||
| test.c:154:39:154:40 | r3_0(long long) = Constant[-1] | test.c:154:39:154:40 | (long long)... |
|
||||
| test.c:171:7:171:8 | r16_1(int) = Constant[-7] | test.c:171:7:171:8 | - ... |
|
||||
| test.c:176:7:176:8 | r1_1(int) = Constant[-7] | test.c:176:7:176:8 | - ... |
|
||||
| test.c:181:7:181:8 | r4_1(int) = Constant[-7] | test.c:181:7:181:8 | - ... |
|
||||
| test.c:186:7:186:8 | r7_1(int) = Constant[-7] | test.c:186:7:186:8 | - ... |
|
||||
| test.c:186:23:186:24 | r9_2(int) = Constant[-2] | test.c:186:23:186:24 | - ... |
|
||||
| test.c:208:28:208:30 | r25_0(int) = Constant[-13] | test.c:208:28:208:30 | - ... |
|
||||
| test.c:212:28:212:30 | r5_0(int) = Constant[-13] | test.c:212:28:212:30 | - ... |
|
||||
| test.c:216:28:216:30 | r10_0(int) = Constant[-13] | test.c:216:28:216:30 | - ... |
|
||||
| test.c:216:45:216:46 | r11_2(int) = Constant[-7] | test.c:216:45:216:46 | - ... |
|
||||
| test.c:236:28:236:30 | r25_0(int) = Constant[-13] | test.c:236:28:236:30 | - ... |
|
||||
| test.c:240:28:240:30 | r5_0(int) = Constant[-13] | test.c:240:28:240:30 | - ... |
|
||||
| test.c:244:28:244:30 | r10_0(int) = Constant[-13] | test.c:244:28:244:30 | - ... |
|
||||
| test.c:244:45:244:46 | r11_2(int) = Constant[-7] | test.c:244:45:244:46 | - ... |
|
||||
| test.c:256:7:256:9 | r0_9(int) = Constant[-17] | test.c:256:7:256:9 | - ... |
|
||||
| test.c:260:7:260:9 | r18_1(int) = Constant[-17] | test.c:260:7:260:9 | - ... |
|
||||
| test.c:264:7:264:9 | r23_1(int) = Constant[-17] | test.c:264:7:264:9 | - ... |
|
||||
| test.c:264:30:264:32 | r25_0(int) = Constant[-13] | test.c:264:30:264:32 | - ... |
|
||||
| test.c:268:7:268:9 | r3_1(int) = Constant[-17] | test.c:268:7:268:9 | - ... |
|
||||
| test.c:268:30:268:32 | r5_0(int) = Constant[-13] | test.c:268:30:268:32 | - ... |
|
||||
| test.c:272:7:272:9 | r8_1(int) = Constant[-17] | test.c:272:7:272:9 | - ... |
|
||||
| test.c:272:30:272:32 | r10_0(int) = Constant[-13] | test.c:272:30:272:32 | - ... |
|
||||
| test.c:272:47:272:48 | r11_2(int) = Constant[-7] | test.c:272:47:272:48 | - ... |
|
||||
| test.c:284:7:284:9 | r0_9(int) = Constant[-17] | test.c:284:7:284:9 | - ... |
|
||||
| test.c:288:7:288:9 | r18_1(int) = Constant[-17] | test.c:288:7:288:9 | - ... |
|
||||
| test.c:292:7:292:9 | r23_1(int) = Constant[-17] | test.c:292:7:292:9 | - ... |
|
||||
| test.c:292:29:292:31 | r25_0(int) = Constant[-13] | test.c:292:29:292:31 | - ... |
|
||||
| test.c:296:7:296:9 | r3_1(int) = Constant[-17] | test.c:296:7:296:9 | - ... |
|
||||
| test.c:296:29:296:31 | r5_0(int) = Constant[-13] | test.c:296:29:296:31 | - ... |
|
||||
| test.c:300:7:300:9 | r8_1(int) = Constant[-17] | test.c:300:7:300:9 | - ... |
|
||||
| test.c:300:29:300:31 | r10_0(int) = Constant[-13] | test.c:300:29:300:31 | - ... |
|
||||
| test.c:300:46:300:47 | r11_2(int) = Constant[-7] | test.c:300:46:300:47 | - ... |
|
||||
| test.c:312:7:312:9 | r0_9(int) = Constant[-17] | test.c:312:7:312:9 | - ... |
|
||||
| test.c:312:24:312:25 | r14_2(int) = Constant[-2] | test.c:312:24:312:25 | - ... |
|
||||
| test.c:316:7:316:9 | r18_1(int) = Constant[-17] | test.c:316:7:316:9 | - ... |
|
||||
| test.c:316:24:316:25 | r19_2(int) = Constant[-2] | test.c:316:24:316:25 | - ... |
|
||||
| test.c:320:7:320:9 | r23_1(int) = Constant[-17] | test.c:320:7:320:9 | - ... |
|
||||
| test.c:320:24:320:25 | r24_2(int) = Constant[-2] | test.c:320:24:320:25 | - ... |
|
||||
| test.c:320:30:320:32 | r25_0(int) = Constant[-13] | test.c:320:30:320:32 | - ... |
|
||||
| test.c:324:7:324:9 | r3_1(int) = Constant[-17] | test.c:324:7:324:9 | - ... |
|
||||
| test.c:324:24:324:25 | r4_2(int) = Constant[-2] | test.c:324:24:324:25 | - ... |
|
||||
| test.c:324:30:324:32 | r5_0(int) = Constant[-13] | test.c:324:30:324:32 | - ... |
|
||||
| test.c:328:7:328:9 | r8_1(int) = Constant[-17] | test.c:328:7:328:9 | - ... |
|
||||
| test.c:328:24:328:25 | r9_2(int) = Constant[-2] | test.c:328:24:328:25 | - ... |
|
||||
| test.c:328:30:328:32 | r10_0(int) = Constant[-13] | test.c:328:30:328:32 | - ... |
|
||||
| test.c:328:47:328:48 | r11_2(int) = Constant[-7] | test.c:328:47:328:48 | - ... |
|
||||
| test.c:339:12:339:13 | m2_2(int) = Store r2_0, r2_1 | test.c:339:12:339:13 | - ... |
|
||||
| test.c:339:12:339:13 | r2_1(int) = Constant[-1] | test.c:339:12:339:13 | - ... |
|
||||
| test.cpp:9:11:9:12 | m0_8(int) = Store r0_6, r0_7 | test.cpp:9:11:9:12 | - ... |
|
||||
| test.cpp:9:11:9:12 | r0_7(int) = Constant[-1] | test.cpp:9:11:9:12 | - ... |
|
||||
| test.cpp:30:12:30:13 | r11_3(int) = Constant[-1] | test.cpp:30:12:30:13 | - ... |
|
||||
| test.cpp:31:5:31:10 | m12_2(int) = Store r12_1, r12_0 | test.cpp:31:5:31:10 | ... = ... |
|
||||
| test.cpp:31:9:31:10 | r12_0(int) = Constant[-1] | test.cpp:31:9:31:10 | - ... |
|
||||
| test.cpp:36:12:36:15 | r15_3(int) = Constant[-128] | test.cpp:36:12:36:15 | - ... |
|
||||
| test.cpp:37:5:37:12 | m16_2(int) = Store r16_1, r16_0 | test.cpp:37:5:37:12 | ... = ... |
|
||||
| test.cpp:37:9:37:12 | r16_0(int) = Constant[-128] | test.cpp:37:9:37:12 | - ... |
|
||||
| test.cpp:42:12:42:16 | r19_3(int) = Constant[-1024] | test.cpp:42:12:42:16 | - ... |
|
||||
| test.cpp:43:5:43:13 | m20_2(int) = Store r20_1, r20_0 | test.cpp:43:5:43:13 | ... = ... |
|
||||
| test.cpp:43:9:43:13 | r20_0(int) = Constant[-1024] | test.cpp:43:9:43:13 | - ... |
|
||||
@@ -0,0 +1,6 @@
|
||||
import semmle.code.cpp.rangeanalysis.SignAnalysis
|
||||
import semmle.code.cpp.ir.IR
|
||||
|
||||
from Instruction i
|
||||
where strictlyNegative(i)
|
||||
select i, i.getAST()
|
||||
@@ -0,0 +1,136 @@
|
||||
| inline_assembly.c:10:7:10:7 | r0_7(unsigned int) = Constant[1] | inline_assembly.c:10:7:10:7 | (unsigned int)... |
|
||||
| minmax.c:16:9:16:10 | r0_3(int) = Constant[1] | minmax.c:16:9:16:10 | 1 |
|
||||
| minmax.c:16:16:16:17 | r0_6(int) = Constant[2] | minmax.c:16:16:16:17 | 2 |
|
||||
| minmax.c:16:23:16:24 | r0_9(int) = Constant[3] | minmax.c:16:23:16:24 | 3 |
|
||||
| test.c:8:19:8:19 | r2_2(int) = Constant[1] | test.c:8:19:8:19 | 1 |
|
||||
| test.c:16:20:16:20 | r2_2(int) = Constant[1] | test.c:16:20:16:20 | 1 |
|
||||
| test.c:16:25:16:26 | r2_4(int) = Constant[10] | test.c:16:25:16:26 | 10 |
|
||||
| test.c:24:5:24:11 | r2_2(int) = Constant[1] | test.c:24:5:24:11 | ... ++ |
|
||||
| test.c:25:21:25:22 | r2_7(int) = Constant[10] | test.c:25:21:25:22 | 10 |
|
||||
| test.c:33:19:33:19 | r1_4(int) = Constant[2] | test.c:33:19:33:19 | 2 |
|
||||
| test.c:33:28:33:28 | r2_8(int) = Constant[1] | test.c:33:28:33:28 | 1 |
|
||||
| test.c:42:19:42:19 | r1_4(int) = Constant[2] | test.c:42:19:42:19 | 2 |
|
||||
| test.c:42:22:42:24 | r2_8(int) = Constant[1] | test.c:42:22:42:24 | ... ++ |
|
||||
| test.c:51:17:51:17 | r1_4(int) = Constant[2] | test.c:51:17:51:17 | 2 |
|
||||
| test.c:51:21:51:21 | r1_6(int) = Constant[4] | test.c:51:21:51:21 | 4 |
|
||||
| test.c:51:30:51:30 | r2_8(int) = Constant[1] | test.c:51:30:51:30 | 1 |
|
||||
| test.c:58:11:58:11 | r0_6(int) = Constant[4] | test.c:58:11:58:11 | 4 |
|
||||
| test.c:59:13:59:13 | r2_2(int) = Constant[5] | test.c:59:13:59:13 | 5 |
|
||||
| test.c:63:10:63:10 | r4_1(int) = Constant[1] | test.c:63:10:63:10 | 1 |
|
||||
| test.c:67:24:67:25 | r2_2(int) = Constant[10] | test.c:67:24:67:25 | 10 |
|
||||
| test.c:68:15:68:15 | r3_4(int) = Constant[2] | test.c:68:15:68:15 | 2 |
|
||||
| test.c:77:13:77:13 | r2_2(int) = Constant[4] | test.c:77:13:77:13 | 4 |
|
||||
| test.c:81:13:81:13 | r4_2(int) = Constant[4] | test.c:81:13:81:13 | 4 |
|
||||
| test.c:82:14:82:14 | r5_1(int) = Constant[1] | test.c:82:14:82:14 | 1 |
|
||||
| test.c:89:11:89:11 | r0_8(int) = Constant[7] | test.c:89:11:89:11 | 7 |
|
||||
| test.c:95:10:95:10 | r5_1(int) = Constant[1] | test.c:95:10:95:10 | 1 |
|
||||
| test.c:102:6:102:8 | r2_3(int) = Constant[1] | test.c:102:6:102:8 | ... ++ |
|
||||
| test.c:104:12:104:14 | r3_4(int) = Constant[58] | test.c:104:12:104:14 | 58 |
|
||||
| test.c:107:8:107:10 | r5_3(int) = Constant[1] | test.c:107:8:107:10 | ... ++ |
|
||||
| test.c:109:14:109:16 | r6_3(int) = Constant[44] | test.c:109:14:109:16 | 44 |
|
||||
| test.c:110:14:110:14 | r7_1(int) = Constant[1] | test.c:110:14:110:14 | 1 |
|
||||
| test.c:119:10:119:12 | r0_8(unsigned long long) = Constant[1] | test.c:119:10:119:12 | ... ++ |
|
||||
| test.c:124:36:124:36 | r1_5(unsigned long long) = Constant[1] | test.c:124:36:124:36 | (unsigned long long)... |
|
||||
| test.c:127:24:127:24 | r2_6(unsigned long long) = Constant[1] | test.c:127:24:127:24 | (unsigned long long)... |
|
||||
| test.c:130:11:130:11 | r3_1(int) = Constant[1] | test.c:130:11:130:11 | 1 |
|
||||
| test.c:137:22:137:22 | r0_17(unsigned int) = Constant[1] | test.c:137:22:137:22 | (unsigned int)... |
|
||||
| test.c:138:13:138:13 | r0_23(int) = Constant[1] | test.c:138:13:138:13 | 1 |
|
||||
| test.c:161:7:161:7 | r0_7(int) = Constant[3] | test.c:161:7:161:7 | 3 |
|
||||
| test.c:161:22:161:23 | r8_2(int) = Constant[11] | test.c:161:22:161:23 | 11 |
|
||||
| test.c:166:22:166:23 | r14_2(int) = Constant[11] | test.c:166:22:166:23 | 11 |
|
||||
| test.c:171:23:171:24 | r17_2(int) = Constant[11] | test.c:171:23:171:24 | 11 |
|
||||
| test.c:176:23:176:23 | r2_2(int) = Constant[1] | test.c:176:23:176:23 | 1 |
|
||||
| test.c:200:7:200:7 | r0_9(int) = Constant[3] | test.c:200:7:200:7 | 3 |
|
||||
| test.c:200:22:200:23 | r14_2(int) = Constant[11] | test.c:200:22:200:23 | 11 |
|
||||
| test.c:200:28:200:28 | r15_0(int) = Constant[5] | test.c:200:28:200:28 | 5 |
|
||||
| test.c:200:43:200:44 | r16_2(int) = Constant[23] | test.c:200:43:200:44 | 23 |
|
||||
| test.c:204:7:204:7 | r18_1(int) = Constant[3] | test.c:204:7:204:7 | 3 |
|
||||
| test.c:204:22:204:23 | r19_2(int) = Constant[11] | test.c:204:22:204:23 | 11 |
|
||||
| test.c:204:43:204:44 | r21_2(int) = Constant[23] | test.c:204:43:204:44 | 23 |
|
||||
| test.c:208:7:208:7 | r23_1(int) = Constant[3] | test.c:208:7:208:7 | 3 |
|
||||
| test.c:208:22:208:23 | r24_2(int) = Constant[11] | test.c:208:22:208:23 | 11 |
|
||||
| test.c:208:45:208:46 | r1_2(int) = Constant[23] | test.c:208:45:208:46 | 23 |
|
||||
| test.c:212:7:212:7 | r3_1(int) = Constant[3] | test.c:212:7:212:7 | 3 |
|
||||
| test.c:212:22:212:23 | r4_2(int) = Constant[11] | test.c:212:22:212:23 | 11 |
|
||||
| test.c:216:7:216:7 | r8_1(int) = Constant[3] | test.c:216:7:216:7 | 3 |
|
||||
| test.c:216:22:216:23 | r9_2(int) = Constant[11] | test.c:216:22:216:23 | 11 |
|
||||
| test.c:228:22:228:23 | r14_2(int) = Constant[11] | test.c:228:22:228:23 | 11 |
|
||||
| test.c:228:28:228:28 | r15_0(int) = Constant[5] | test.c:228:28:228:28 | 5 |
|
||||
| test.c:228:43:228:44 | r16_2(int) = Constant[23] | test.c:228:43:228:44 | 23 |
|
||||
| test.c:232:22:232:23 | r19_2(int) = Constant[11] | test.c:232:22:232:23 | 11 |
|
||||
| test.c:232:43:232:44 | r21_2(int) = Constant[23] | test.c:232:43:232:44 | 23 |
|
||||
| test.c:236:22:236:23 | r24_2(int) = Constant[11] | test.c:236:22:236:23 | 11 |
|
||||
| test.c:236:45:236:46 | r1_2(int) = Constant[23] | test.c:236:45:236:46 | 23 |
|
||||
| test.c:240:22:240:23 | r4_2(int) = Constant[11] | test.c:240:22:240:23 | 11 |
|
||||
| test.c:244:22:244:23 | r9_2(int) = Constant[11] | test.c:244:22:244:23 | 11 |
|
||||
| test.c:256:24:256:25 | r14_2(int) = Constant[11] | test.c:256:24:256:25 | 11 |
|
||||
| test.c:256:30:256:30 | r15_0(int) = Constant[5] | test.c:256:30:256:30 | 5 |
|
||||
| test.c:256:45:256:46 | r16_2(int) = Constant[23] | test.c:256:45:256:46 | 23 |
|
||||
| test.c:260:24:260:25 | r19_2(int) = Constant[11] | test.c:260:24:260:25 | 11 |
|
||||
| test.c:260:45:260:46 | r21_2(int) = Constant[23] | test.c:260:45:260:46 | 23 |
|
||||
| test.c:264:24:264:25 | r24_2(int) = Constant[11] | test.c:264:24:264:25 | 11 |
|
||||
| test.c:264:47:264:48 | r1_2(int) = Constant[23] | test.c:264:47:264:48 | 23 |
|
||||
| test.c:268:24:268:25 | r4_2(int) = Constant[11] | test.c:268:24:268:25 | 11 |
|
||||
| test.c:272:24:272:25 | r9_2(int) = Constant[11] | test.c:272:24:272:25 | 11 |
|
||||
| test.c:284:29:284:29 | r15_0(int) = Constant[5] | test.c:284:29:284:29 | 5 |
|
||||
| test.c:284:44:284:45 | r16_2(int) = Constant[23] | test.c:284:44:284:45 | 23 |
|
||||
| test.c:288:44:288:45 | r21_2(int) = Constant[23] | test.c:288:44:288:45 | 23 |
|
||||
| test.c:292:46:292:47 | r1_2(int) = Constant[23] | test.c:292:46:292:47 | 23 |
|
||||
| test.c:312:30:312:30 | r15_0(int) = Constant[5] | test.c:312:30:312:30 | 5 |
|
||||
| test.c:312:45:312:46 | r16_2(int) = Constant[23] | test.c:312:45:312:46 | 23 |
|
||||
| test.c:316:45:316:46 | r21_2(int) = Constant[23] | test.c:316:45:316:46 | 23 |
|
||||
| test.c:320:47:320:48 | r1_2(int) = Constant[23] | test.c:320:47:320:48 | 23 |
|
||||
| test.c:342:14:342:14 | r3_3(int) = Constant[3] | test.c:342:14:342:14 | 3 |
|
||||
| test.c:343:5:343:7 | r4_2(int) = Constant[1] | test.c:343:5:343:7 | ... ++ |
|
||||
| test.c:348:14:348:14 | r7_1(int) = Constant[1] | test.c:348:14:348:14 | 1 |
|
||||
| test.c:357:12:357:14 | r0_22(unsigned int) = Constant[100] | test.c:357:12:357:14 | (unsigned int)... |
|
||||
| test.c:357:22:357:23 | r22_0(unsigned int) = Constant[10] | test.c:357:22:357:23 | (unsigned int)... |
|
||||
| test.c:358:13:358:15 | r17_7(unsigned int) = Constant[100] | test.c:358:13:358:15 | (unsigned int)... |
|
||||
| test.c:358:19:358:20 | r24_0(unsigned int) = Constant[10] | test.c:358:19:358:20 | (unsigned int)... |
|
||||
| test.c:365:11:365:13 | r23_25(unsigned int) = Constant[300] | test.c:365:11:365:13 | (unsigned int)... |
|
||||
| test.c:366:15:366:15 | r38_0(unsigned int) = Constant[5] | test.c:366:15:366:15 | (unsigned int)... |
|
||||
| test.c:366:15:366:15 | r40_0(unsigned int) = Constant[5] | test.c:366:15:366:15 | (unsigned int)... |
|
||||
| test.c:367:15:367:17 | r48_0(unsigned int) = Constant[500] | test.c:367:15:367:17 | (unsigned int)... |
|
||||
| test.c:367:15:367:17 | r50_0(unsigned int) = Constant[500] | test.c:367:15:367:17 | (unsigned int)... |
|
||||
| test.c:368:13:368:13 | r27_0(unsigned int) = Constant[1] | test.c:368:13:368:13 | (unsigned int)... |
|
||||
| test.c:368:13:368:13 | r54_0(unsigned int) = Constant[1] | test.c:368:13:368:13 | (unsigned int)... |
|
||||
| test.c:368:19:368:21 | r55_0(unsigned int) = Constant[500] | test.c:368:19:368:21 | (unsigned int)... |
|
||||
| test.c:369:29:369:29 | r4_0(unsigned int) = Constant[1] | test.c:369:29:369:29 | (unsigned int)... |
|
||||
| test.c:369:29:369:29 | r41_0(unsigned int) = Constant[1] | test.c:369:29:369:29 | (unsigned int)... |
|
||||
| test.c:369:36:369:36 | r5_0(int) = Constant[5] | test.c:369:36:369:36 | 5 |
|
||||
| test.c:370:29:370:29 | r9_0(unsigned int) = Constant[1] | test.c:370:29:370:29 | (unsigned int)... |
|
||||
| test.c:370:29:370:29 | r41_0(unsigned int) = Constant[1] | test.c:370:29:370:29 | (unsigned int)... |
|
||||
| test.c:370:36:370:38 | r10_0(int) = Constant[500] | test.c:370:36:370:38 | 500 |
|
||||
| test.c:371:30:371:30 | r14_0(unsigned int) = Constant[1] | test.c:371:30:371:30 | (unsigned int)... |
|
||||
| test.c:371:30:371:30 | r41_0(unsigned int) = Constant[1] | test.c:371:30:371:30 | (unsigned int)... |
|
||||
| test.c:371:37:371:39 | r15_0(int) = Constant[500] | test.c:371:37:371:39 | 500 |
|
||||
| test.c:379:12:379:14 | r0_16(unsigned int) = Constant[100] | test.c:379:12:379:14 | (unsigned int)... |
|
||||
| test.c:379:22:379:24 | r5_0(unsigned int) = Constant[110] | test.c:379:22:379:24 | (unsigned int)... |
|
||||
| test.c:380:13:380:15 | r1_7(unsigned int) = Constant[100] | test.c:380:13:380:15 | (unsigned int)... |
|
||||
| test.c:380:19:380:21 | r7_0(unsigned int) = Constant[110] | test.c:380:19:380:21 | (unsigned int)... |
|
||||
| test.c:381:8:381:11 | r6_5(unsigned int) = Constant[1000] | test.c:381:8:381:11 | (unsigned int)... |
|
||||
| test.c:382:8:382:11 | r6_8(unsigned int) = Constant[1000] | test.c:382:8:382:11 | (unsigned int)... |
|
||||
| test.c:383:8:383:11 | r6_11(unsigned int) = Constant[1000] | test.c:383:8:383:11 | (unsigned int)... |
|
||||
| test.c:384:12:384:14 | r6_16(unsigned int) = Constant[300] | test.c:384:12:384:14 | (unsigned int)... |
|
||||
| test.c:385:13:385:15 | r11_0(unsigned int) = Constant[300] | test.c:385:13:385:15 | (unsigned int)... |
|
||||
| test.c:385:13:385:15 | r18_0(unsigned int) = Constant[300] | test.c:385:13:385:15 | (unsigned int)... |
|
||||
| test.c:385:21:385:21 | r19_0(unsigned int) = Constant[5] | test.c:385:21:385:21 | (unsigned int)... |
|
||||
| test.c:386:13:386:15 | r11_0(unsigned int) = Constant[200] | test.c:386:13:386:15 | (unsigned int)... |
|
||||
| test.c:386:13:386:15 | r24_0(unsigned int) = Constant[200] | test.c:386:13:386:15 | (unsigned int)... |
|
||||
| test.c:386:21:386:21 | r25_0(unsigned int) = Constant[5] | test.c:386:21:386:21 | (unsigned int)... |
|
||||
| test.c:387:29:387:31 | r28_0(unsigned int) = Constant[200] | test.c:387:29:387:31 | (unsigned int)... |
|
||||
| test.c:387:29:387:31 | r30_0(unsigned int) = Constant[200] | test.c:387:29:387:31 | (unsigned int)... |
|
||||
| test.c:387:38:387:38 | r31_0(int) = Constant[5] | test.c:387:38:387:38 | 5 |
|
||||
| test.c:394:24:394:26 | r0_7(unsigned int) = Constant[100] | test.c:394:24:394:26 | (unsigned int)... |
|
||||
| test.c:394:34:394:36 | r2_0(unsigned int) = Constant[100] | test.c:394:34:394:36 | (unsigned int)... |
|
||||
| test.c:397:9:397:11 | r3_10(unsigned int) = Constant[1] | test.c:397:9:397:11 | ++ ... |
|
||||
| test.c:398:9:398:11 | r3_19(unsigned int) = Constant[1] | test.c:398:9:398:11 | ... ++ |
|
||||
| test.c:398:19:398:19 | r3_22(unsigned int) = Constant[3] | test.c:398:19:398:19 | (unsigned int)... |
|
||||
| test.cpp:11:13:11:13 | r1_2(int) = Constant[3] | test.cpp:11:13:11:13 | 3 |
|
||||
| test.cpp:33:12:33:12 | r13_3(int) = Constant[1] | test.cpp:33:12:33:12 | 1 |
|
||||
| test.cpp:34:9:34:9 | r14_0(int) = Constant[1] | test.cpp:34:9:34:9 | 1 |
|
||||
| test.cpp:39:12:39:14 | r17_3(int) = Constant[128] | test.cpp:39:12:39:14 | 128 |
|
||||
| test.cpp:40:9:40:11 | r18_0(int) = Constant[128] | test.cpp:40:9:40:11 | 128 |
|
||||
| test.cpp:45:12:45:15 | r21_3(int) = Constant[1024] | test.cpp:45:12:45:15 | 1024 |
|
||||
| test.cpp:46:9:46:12 | r22_0(int) = Constant[1024] | test.cpp:46:9:46:12 | 1024 |
|
||||
| test.cpp:69:10:69:21 | r9_1(bool) = Constant[1] | test.cpp:69:10:69:21 | ... \|\| ... |
|
||||
@@ -0,0 +1,6 @@
|
||||
import semmle.code.cpp.rangeanalysis.SignAnalysis
|
||||
import semmle.code.cpp.ir.IR
|
||||
|
||||
from Instruction i
|
||||
where strictlyPositive(i)
|
||||
select i, i.getAST()
|
||||
400
cpp/ql/test/library-tests/rangeanalysis/signanalysis/test.c
Normal file
400
cpp/ql/test/library-tests/rangeanalysis/signanalysis/test.c
Normal file
@@ -0,0 +1,400 @@
|
||||
struct List {
|
||||
struct List* next;
|
||||
};
|
||||
|
||||
int test1(struct List* p) {
|
||||
int count = 0;
|
||||
for (; p; p = p->next) {
|
||||
count = count+1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int test2(struct List* p) {
|
||||
int count = 0;
|
||||
for (; p; p = p->next) {
|
||||
count = (count+1) % 10;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int test3(struct List* p) {
|
||||
int count = 0;
|
||||
for (; p; p = p->next) {
|
||||
count++;
|
||||
count = count % 10;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int test4() {
|
||||
int i = 0;
|
||||
int total = 0;
|
||||
for (i = 0; i < 2; i = i+1) {
|
||||
total += i;
|
||||
}
|
||||
return total + i;
|
||||
}
|
||||
|
||||
int test5() {
|
||||
int i = 0;
|
||||
int total = 0;
|
||||
for (i = 0; i < 2; i++) {
|
||||
total += i;
|
||||
}
|
||||
return total + i;
|
||||
}
|
||||
|
||||
int test6() {
|
||||
int i = 0;
|
||||
int total = 0;
|
||||
for (i = 0; i+2 < 4; i = i+1) {
|
||||
total += i;
|
||||
}
|
||||
return total + i;
|
||||
}
|
||||
|
||||
int test7(int i) {
|
||||
if (i < 4) {
|
||||
if (i < 5) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test8(int x, int y) {
|
||||
if (-1000 < y && y < 10) {
|
||||
if (x < y-2) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
int test9(int x, int y) {
|
||||
if (y == 0) {
|
||||
if (x < 4) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (x < 4) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
int test10(int x, int y) {
|
||||
if (y > 7) {
|
||||
if (x < y) {
|
||||
return 0;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int test11(char *p) {
|
||||
char c;
|
||||
c = *p;
|
||||
if (c != '\0')
|
||||
*p++ = '\0';
|
||||
|
||||
if (c == ':') {
|
||||
c = *p;
|
||||
if (c != '\0')
|
||||
*p++ = '\0';
|
||||
|
||||
if (c != ',')
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef unsigned long long size_type;
|
||||
|
||||
size_type test12_helper() {
|
||||
static size_type n = 0;
|
||||
return n++;
|
||||
}
|
||||
|
||||
int test12() {
|
||||
size_type Start = 0;
|
||||
while (Start <= test12_helper()-1)
|
||||
{
|
||||
const size_type Length = test12_helper();
|
||||
Start += Length + 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Tests for overflow conditions.
|
||||
int test13(char c, int i) {
|
||||
unsigned char uc = c;
|
||||
unsigned int x = 0;
|
||||
unsigned int y = x-1;
|
||||
int z = i+1;
|
||||
return (double)(c + i + uc + x + y + z);
|
||||
}
|
||||
|
||||
// Regression test for ODASA-6013.
|
||||
int test14(int x) {
|
||||
int x0 = (int)(char)x;
|
||||
int x1 = (int)(unsigned char)x;
|
||||
int x2 = (int)(unsigned short)x;
|
||||
int x3 = (int)(unsigned int)x;
|
||||
char c0 = x;
|
||||
unsigned short s0 = x;
|
||||
return x0 + x1 + x2 + x3 + c0 + s0;
|
||||
}
|
||||
|
||||
long long test15(long long x) {
|
||||
return (x > 0 && x == (int)x) ? x : -1;
|
||||
}
|
||||
|
||||
// Tests for unary operators.
|
||||
int test_unary(int a) {
|
||||
int total = 0;
|
||||
|
||||
if (3 <= a && a <= 11) {
|
||||
int b = +a;
|
||||
int c = -a;
|
||||
total += b+c;
|
||||
}
|
||||
if (0 <= a && a <= 11) {
|
||||
int b = +a;
|
||||
int c = -a;
|
||||
total += b+c;
|
||||
}
|
||||
if (-7 <= a && a <= 11) {
|
||||
int b = +a;
|
||||
int c = -a;
|
||||
total += b+c;
|
||||
}
|
||||
if (-7 <= a && a <= 1) {
|
||||
int b = +a;
|
||||
int c = -a;
|
||||
total += b+c;
|
||||
}
|
||||
if (-7 <= a && a <= 0) {
|
||||
int b = +a;
|
||||
int c = -a;
|
||||
total += b+c;
|
||||
}
|
||||
if (-7 <= a && a <= -2) {
|
||||
int b = +a;
|
||||
int c = -a;
|
||||
total += b+c;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
// Tests for multiplication.
|
||||
int test_mult01(int a, int b) {
|
||||
int total = 0;
|
||||
|
||||
if (3 <= a && a <= 11 && 5 <= b && b <= 23) {
|
||||
int r = a*b; // 15 .. 253
|
||||
total += r;
|
||||
}
|
||||
if (3 <= a && a <= 11 && 0 <= b && b <= 23) {
|
||||
int r = a*b; // 0 .. 253
|
||||
total += r;
|
||||
}
|
||||
if (3 <= a && a <= 11 && -13 <= b && b <= 23) {
|
||||
int r = a*b; // -143 .. 253
|
||||
total += r;
|
||||
}
|
||||
if (3 <= a && a <= 11 && -13 <= b && b <= 0) {
|
||||
int r = a*b; // -143 .. 0
|
||||
total += r;
|
||||
}
|
||||
if (3 <= a && a <= 11 && -13 <= b && b <= -7) {
|
||||
int r = a*b; // -143 .. -21
|
||||
total += r;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
// Tests for multiplication.
|
||||
int test_mult02(int a, int b) {
|
||||
int total = 0;
|
||||
|
||||
if (0 <= a && a <= 11 && 5 <= b && b <= 23) {
|
||||
int r = a*b; // 0 .. 253
|
||||
total += r;
|
||||
}
|
||||
if (0 <= a && a <= 11 && 0 <= b && b <= 23) {
|
||||
int r = a*b; // 0 .. 253
|
||||
total += r;
|
||||
}
|
||||
if (0 <= a && a <= 11 && -13 <= b && b <= 23) {
|
||||
int r = a*b; // -143 .. 253
|
||||
total += r;
|
||||
}
|
||||
if (0 <= a && a <= 11 && -13 <= b && b <= 0) {
|
||||
int r = a*b; // -143 .. 0
|
||||
total += r;
|
||||
}
|
||||
if (0 <= a && a <= 11 && -13 <= b && b <= -7) {
|
||||
int r = a*b; // -143 .. 0
|
||||
total += r;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
// Tests for multiplication.
|
||||
int test_mult03(int a, int b) {
|
||||
int total = 0;
|
||||
|
||||
if (-17 <= a && a <= 11 && 5 <= b && b <= 23) {
|
||||
int r = a*b; // -391 .. 253
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= 11 && 0 <= b && b <= 23) {
|
||||
int r = a*b; // -391 .. 253
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= 11 && -13 <= b && b <= 23) {
|
||||
int r = a*b; // -391 .. 253
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= 11 && -13 <= b && b <= 0) {
|
||||
int r = a*b; // -143 .. 221
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= 11 && -13 <= b && b <= -7) {
|
||||
int r = a*b; // -143 .. 221
|
||||
total += r;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
// Tests for multiplication.
|
||||
int test_mult04(int a, int b) {
|
||||
int total = 0;
|
||||
|
||||
if (-17 <= a && a <= 0 && 5 <= b && b <= 23) {
|
||||
int r = a*b; // -391 .. 0
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= 0 && 0 <= b && b <= 23) {
|
||||
int r = a*b; // -391 .. 0
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= 0 && -13 <= b && b <= 23) {
|
||||
int r = a*b; // -391 .. 221
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= 0 && -13 <= b && b <= 0) {
|
||||
int r = a*b; // 0 .. 221
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= 0 && -13 <= b && b <= -7) {
|
||||
int r = a*b; // 0 .. 221
|
||||
total += r;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
// Tests for multiplication.
|
||||
int test_mult05(int a, int b) {
|
||||
int total = 0;
|
||||
|
||||
if (-17 <= a && a <= -2 && 5 <= b && b <= 23) {
|
||||
int r = a*b; // -391 .. -10
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= -2 && 0 <= b && b <= 23) {
|
||||
int r = a*b; // -391 .. 0
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= -2 && -13 <= b && b <= 23) {
|
||||
int r = a*b; // -391 .. 221
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= -2 && -13 <= b && b <= 0) {
|
||||
int r = a*b; // 0 .. 221
|
||||
total += r;
|
||||
}
|
||||
if (-17 <= a && a <= -2 && -13 <= b && b <= -7) {
|
||||
int r = a*b; // 14 .. 221
|
||||
total += r;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
int test16(int x) {
|
||||
int d, i = 0;
|
||||
if (x < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (i < 3) {
|
||||
i++;
|
||||
}
|
||||
d = i;
|
||||
if (x < 0) { // Comparison is always false.
|
||||
if (d > -x) { // Unreachable code.
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Test ternary expression upper bounds.
|
||||
unsigned int test_ternary01(unsigned int x) {
|
||||
unsigned int y1, y2, y3, y4, y5, y6, y7, y8;
|
||||
y1 = x < 100 ? x : 10; // y1 < 100
|
||||
y2 = x >= 100 ? 10 : x; // y2 < 100
|
||||
y3 = 0;
|
||||
y4 = 0;
|
||||
y5 = 0;
|
||||
y6 = 0;
|
||||
y7 = 0;
|
||||
y8 = 0;
|
||||
if (x < 300) {
|
||||
y3 = x ?: 5; // y3 < 300
|
||||
y4 = x ?: 500; // y4 <= 500
|
||||
y5 = (x+1) ?: 500; // y5 <= 300
|
||||
y6 = ((unsigned char)(x+1)) ?: 5; // y6 < 256
|
||||
y7 = ((unsigned char)(x+1)) ?: 500; // y7 <= 500
|
||||
y8 = ((unsigned short)(x+1)) ?: 500; // y8 <= 300
|
||||
}
|
||||
return y1 + y2 + y3 + y4 + y5 + y6 + y7 + y8;
|
||||
}
|
||||
|
||||
// Test ternary expression lower bounds.
|
||||
unsigned int test_ternary02(unsigned int x) {
|
||||
unsigned int y1, y2, y3, y4, y5;
|
||||
y1 = x > 100 ? x : 110; // y1 > 100
|
||||
y2 = x <= 100 ? 110 : x; // y2 > 100
|
||||
y3 = 1000;
|
||||
y4 = 1000;
|
||||
y5 = 1000;
|
||||
if (x >= 300) {
|
||||
y3 = (x-300) ?: 5; // y3 >= 0
|
||||
y4 = (x-200) ?: 5; // y4 >= 100
|
||||
y5 = ((unsigned char)(x-200)) ?: 5; // y6 >= 0
|
||||
}
|
||||
return y1 + y2 + y3 + y4 + y5;
|
||||
}
|
||||
|
||||
// Test the comma expression.
|
||||
unsigned int test_comma01(unsigned int x) {
|
||||
unsigned int y = x < 100 ? x : 100;
|
||||
unsigned int y1;
|
||||
unsigned int y2;
|
||||
y1 = (++y, y);
|
||||
y2 = (y++, y += 3, y);
|
||||
return y1 + y2;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
template <typename T>
|
||||
class vector {
|
||||
public:
|
||||
T& operator[](int);
|
||||
const T& operator[](int) const;
|
||||
};
|
||||
|
||||
int test1(vector<int> vec, int b) {
|
||||
int x = -1;
|
||||
if (b) {
|
||||
x = vec[3];
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
// Regression test for ODASA-6013.
|
||||
int test2(int x) {
|
||||
int x0 = static_cast<char>(x);
|
||||
return x0;
|
||||
}
|
||||
|
||||
// Tests for conversion to bool
|
||||
bool test3(bool b, int x, int y) {
|
||||
// The purpose the assignments to `x` below is to generate a lot of
|
||||
// potential upper and lower bounds for `x`, so that the logic in
|
||||
// boolConversionLowerBound and boolConversionUpperBound gets exercized.
|
||||
if (y == 0) {
|
||||
x = 0;
|
||||
}
|
||||
if (y == -1) {
|
||||
x = -1;
|
||||
}
|
||||
if (y == 1) {
|
||||
x = 1;
|
||||
}
|
||||
if (y == -128) {
|
||||
x = -128;
|
||||
}
|
||||
if (y == 128) {
|
||||
x = 128;
|
||||
}
|
||||
if (y == -1024) {
|
||||
x = -1024;
|
||||
}
|
||||
if (y == 1024) {
|
||||
x = 1024;
|
||||
}
|
||||
|
||||
int t = 0;
|
||||
|
||||
if (x == 0) {
|
||||
bool xb = (bool)x; // (bool)x == false
|
||||
t += (int)xb;
|
||||
}
|
||||
|
||||
if (x > 0) {
|
||||
bool xb = (bool)x; // (bool)x == true
|
||||
t += (int)xb;
|
||||
}
|
||||
|
||||
if (x < 0) {
|
||||
bool xb = (bool)x; // (bool)x == true
|
||||
t += (int)xb;
|
||||
}
|
||||
|
||||
bool xb = (bool)x; // Value of (bool)x is unknown.
|
||||
t += (int)xb;
|
||||
|
||||
return b || (bool)t;
|
||||
}
|
||||
Reference in New Issue
Block a user