Skip to content

Commit bb77139

Browse files
Fix DEADCODE Coverity issue
test/acl_context_test.cpp:1116:9: Type: Logically dead code (DEADCODE) test/acl_context_test.cpp:1111:9: cond_const: Condition "apitype", taking false branch. Now the value of "apitype" is equal to 0. test/acl_context_test.cpp:1117:13: const: At condition "apitype", the value of "apitype" must be equal to 0. test/acl_context_test.cpp:1116:9: dead_error_condition: The condition "apitype" cannot be true. test/acl_context_test.cpp:1116:9: dead_error_line: Execution cannot reach the expression "clCreateContextFromType(props, 4294967295UL, notify_me, this, &status)" inside this statement: "context = (apitype ? clCrea...". test/acl_context_test.cpp:1125:11: Type: Logically dead code (DEADCODE) test/acl_context_test.cpp:1103:9: assignment: Assigning: "fixed_val" = "0L". test/acl_context_test.cpp:1124:13: const: At condition "fixed_val != 0L", the value of "fixed_val" must be equal to 0. test/acl_context_test.cpp:1124:9: dead_error_condition: The condition "fixed_val != 0L" cannot be true. test/acl_context_test.cpp:1125:11: dead_error_line: Execution cannot reach this statement: "if (!envvals[ienv].valid) {...".
1 parent 7a81c63 commit bb77139

File tree

1 file changed

+38
-59
lines changed

1 file changed

+38
-59
lines changed

test/acl_context_test.cpp

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,71 +1097,50 @@ MT_TEST(Context, offline_device) {
10971097

10981098
syncThreads();
10991099

1100-
for (int apitype = 0; apitype < 1; apitype++) { // just do test by type.
1101-
for (int i = 0; i < 2; i++) { // without/with platform.
1102-
int idx = 0;
1103-
cl_context_properties fixed_val = 0;
1104-
if (i) {
1105-
props[idx++] = CL_CONTEXT_PLATFORM;
1106-
props[idx++] = (cl_context_properties)m_platform;
1107-
ACL_LOCKED(acl_print_debug_msg(" set platform %p\n", m_platform));
1108-
}
1109-
props[idx++] = 0;
1110-
1111-
ACL_LOCKED(acl_print_debug_msg(
1112-
" create %s with env str '%s' ienv %d \n",
1113-
(apitype ? "fromType" : "fromList"),
1114-
(envvals[ienv].str ? envvals[ienv].str : "<nil>"), ienv));
1115-
cl_int status = CL_INVALID_VALUE;
1116-
cl_context context =
1117-
apitype
1118-
? clCreateContextFromType(props, CL_DEVICE_TYPE_ALL, notify_me,
1119-
this, &status)
1120-
: clCreateContext(props, 1, m_device, notify_me, this, &status);
1121-
ACL_LOCKED(acl_print_debug_msg(" fixed_val %d valid %d\n",
1122-
(int)fixed_val,
1123-
(int)envvals[ienv].valid));
1124-
if (fixed_val != 0) {
1125-
if (!envvals[ienv].valid) {
1126-
CHECK_EQUAL(CL_INVALID_VALUE, status);
1127-
continue;
1128-
}
1129-
if (envvals[ienv].str != 0) {
1130-
ACL_LOCKED(acl_print_debug_msg(" %s vs. %s \n", (char *)fixed_val,
1131-
envvals[ienv].str));
1132-
if (0 != strcmp((char *)fixed_val, envvals[ienv].str)) {
1133-
CHECK_EQUAL(CL_DEVICE_NOT_AVAILABLE, status);
1134-
continue;
1135-
}
1136-
}
1137-
}
1100+
for (int i = 0; i < 2; i++) { // without/with platform.
1101+
int idx = 0;
1102+
if (i) {
1103+
props[idx++] = CL_CONTEXT_PLATFORM;
1104+
props[idx++] = (cl_context_properties)m_platform;
1105+
ACL_LOCKED(acl_print_debug_msg(" set platform %p\n", m_platform));
1106+
}
1107+
props[idx++] = 0;
11381108

1139-
CHECK_EQUAL(CL_SUCCESS, status);
1140-
ACL_LOCKED(acl_print_debug_msg(" Got context %p\n", context));
1109+
ACL_LOCKED(acl_print_debug_msg(
1110+
" create fromList with env str '%s' ienv %d \n",
1111+
(envvals[ienv].str ? envvals[ienv].str : "<nil>"), ienv));
11411112

1142-
cl_context_properties props_ret[20];
1143-
size_t size_ret = 0;
1144-
CHECK_EQUAL(CL_SUCCESS,
1145-
clGetContextInfo(context, CL_CONTEXT_PROPERTIES,
1146-
sizeof(props_ret), props_ret, &size_ret));
1147-
CHECK_EQUAL(sizeof(cl_context_properties) * idx, size_ret);
1113+
cl_int status = CL_INVALID_VALUE;
11481114

1149-
int idx_ret = 0;
1150-
if (i) {
1151-
CHECK_EQUAL(CL_CONTEXT_PLATFORM, props_ret[idx_ret++]);
1152-
CHECK_EQUAL((cl_context_properties)m_platform, props_ret[idx_ret++]);
1153-
}
1115+
cl_context context =
1116+
clCreateContext(props, 1, m_device, notify_me, this, &status);
1117+
ACL_LOCKED(acl_print_debug_msg("valid %d\n", (int)envvals[ienv].valid));
1118+
1119+
CHECK_EQUAL(CL_SUCCESS, status);
1120+
ACL_LOCKED(acl_print_debug_msg(" Got context %p\n", context));
11541121

1155-
CHECK_EQUAL(0, props_ret[idx_ret++]);
1156-
CHECK_EQUAL(idx, idx_ret);
1122+
cl_context_properties props_ret[20];
1123+
size_t size_ret = 0;
1124+
CHECK_EQUAL(CL_SUCCESS,
1125+
clGetContextInfo(context, CL_CONTEXT_PROPERTIES,
1126+
sizeof(props_ret), props_ret, &size_ret));
1127+
CHECK_EQUAL(sizeof(cl_context_properties) * idx, size_ret);
11571128

1158-
syncThreads();
1159-
ACL_LOCKED(acl_print_debug_msg(" Releaseing context\n"));
1160-
clReleaseContext(context);
1161-
syncThreads();
1162-
CHECK_EQUAL(0, acl_get_num_alloc_cl_context());
1163-
syncThreads();
1129+
int idx_ret = 0;
1130+
if (i) {
1131+
CHECK_EQUAL(CL_CONTEXT_PLATFORM, props_ret[idx_ret++]);
1132+
CHECK_EQUAL((cl_context_properties)m_platform, props_ret[idx_ret++]);
11641133
}
1134+
1135+
CHECK_EQUAL(0, props_ret[idx_ret++]);
1136+
CHECK_EQUAL(idx, idx_ret);
1137+
1138+
syncThreads();
1139+
ACL_LOCKED(acl_print_debug_msg(" Releaseing context\n"));
1140+
clReleaseContext(context);
1141+
syncThreads();
1142+
CHECK_EQUAL(0, acl_get_num_alloc_cl_context());
1143+
syncThreads();
11651144
}
11661145
}
11671146

0 commit comments

Comments
 (0)