-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix DEADCODE Coverity issue for acl_context_test #253
Conversation
@pcolberg What are your thoughts on this? Do you think we should remove the loop completely or try to fix the case that failed when |
This looks like a typo; there is another occurrence where the loop correctly tests both fpga-runtime-for-opencl/test/acl_context_test.cpp Lines 975 to 999 in 5a71e64
|
The Specifically, this is returned by line 899 of |
I found that this error only occurs when |
c569883
to
bb77139
Compare
I've taken a good look at the code now and I'm going to try and explain what is happening in the my own words. For the problematic iteration (i.e.
With all that said... I think it returning What do you think, @pcolberg? |
Yes, that is good. Thanks for the clear, detailed analysis; please be sure to save it in the commit message. |
bb77139
to
14dd784
Compare
A typo was causing much of the code to be seen as deadcode. A loop was not looping the correct number of times. This commit makes changes so that the correct number of loop iterations are done. However, with just this change, the test will fail since clCreateContextFromType returns CL_INVALID_DEVICE on the iteration with ienv = 1, apitype = 1, and i = 0. The reasoning for why this happens in the test is as follows: 1. First, we set the environment to contain L_CONTEXT_OFFLINE_DEVICE_INTELFPGA=+a10_ref_small 2. Then, we initialize our 5 accelerators that we use in the test. Since we have L_CONTEXT_OFFLINE_DEVICE_INTELFPGA=+a10_ref_small in our environment, this is equivalent to adding a 6th offline accelerator to our system. 3. We then try to get our context by calling clCreateContextFromType. Note that we use CL_DEVICE_TYPE_ALL meaning we want all device types included in the context (i.e. doesn't matter if the devices are GPUs, CPUs, etc). 4. Inside the clCreateContextFromType call, we get our desired set of devices by calling clGetDeviceIDs and pass them to l_finalize_context. The devices that we get from clGetDeviceIDs include the offline device we added through the environment variable. 5. l_finalize_context calls l_init_context_with_devices with the same devices. 6. Finally, l_init_context_with_devices correctly errors out since we have a combination of present and absent (offline) devices. So, this commit also changes the code within the for loop to account for the differences between each iteration. These Coverity issues are fixed with this commit: 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) {...".
14dd784
to
1c82bd7
Compare
The two issues were:
apitype
only ever had a value of 0. The for loop it is initialized in exits onceapitype >= 1
. I'm not sure if this is a typo by the original code writer? I tried having it take on values 0 and 1 (as similar code does in other parts of this file), but it errored out. I could try to debug this further if this is seen as the proper solution. For now though, I just removed the for loop with theapitype
variable that looped over nothing.fixed_val
was never used and never modified.Fixes: