Appending '00'B to a bit-string produces unexpected '...11'B result
Submitted by Vadim Yanitskiy
Link to original bug (#566516)
Description
Consider the following test case:
private type component dummy_CT { };
testcase TC_bitstring_magic() runs on dummy_CT { var bitstring A := '00011010110010010010000010000000'B; var bitstring B := '00010010010010010000000000000000'B; var bitstring C := ''B; // expected '101011100'B
for (var integer i := 0; i < lengthof(A); i := i + 1) {
/* Skip zero-bits in A */
if (A[i] == '1'B) {
C := C & B[i]; // <-- (!)
}
}
log("=== C := ", C);
/* The problem is here: somehow we get '10101110011'B
* Where this magic '11'B is coming from? */
log("=== C & '00'B := ", C & '00'B);
if (not match(C & '00'B, '10101110000'B)) {
setverdict(fail, "C does not match");
}
setverdict(pass);
}
I faced this problem while working on a test case. Somehow the result of "C & '00'B" is '10101110011'B instead of '10101110000'B (check last two LSB's). I've also tried with '0'B, and the problem remains - it appends '1'B instead.
MTC@DELL: Test case TC_bitstring_magic started.
MTC@DELL: === C := '101011100'B
MTC@DELL: === C & '00'B := '10101110011'B
MTC@DELL: setverdict(fail): none -> fail reason: "C does not match"
The content of both A and B seem too affect the test result, i.e. changing their bits or the overall size could make the test case pass. What's even more strange, adding an intermediate match() makes the test case pass:
testcase TC_bitstring_magic2() runs on dummy_CT { var bitstring A := '00011010110010010010000010000000'B; var bitstring B := '00010010010010010000000000000000'B; var bitstring C := ''B; // expected '101011100'B
for (var integer i := 0; i < lengthof(A); i := i + 1) {
/* Skip zero-bits in A */
if (A[i] == '1'B) {
C := C & B[i]; // <-- (!)
}
}
log("=== C := ", C);
if (not match(C, '101011100'B)) { // <-- (!)
setverdict(fail, "C does not match");
}
log("=== C & '00'B := ", C & '00'B);
if (not match(C & '00'B, '10101110000'B)) {
setverdict(fail, "C does not match");
}
setverdict(pass);
}
MTC@DELL: Test case TC_bitstring_magic2 started.
MTC@DELL: === C := '101011100'B
MTC@DELL: === C & '00'B := '10101110000'B
MTC@DELL: setverdict(pass): none -> pass
In the actual code, I've managed to work this around by expanding bit assignment in the loop:
testcase TC_bitstring_magic3() runs on dummy_CT { var bitstring A := '00011010110010010010000010000000'B; var bitstring B := '00010010010010010000000000000000'B; var bitstring C := ''B; // expected '101011100'B
for (var integer i := 0; i < lengthof(A); i := i + 1) {
/* Skip zero-bits in A */
if (A[i] == '1'B) {
if (B[i] == '1'B) { // <-- (!)
C := C & '1'B;
} else {
C := C & '0'B;
}
}
}
log("=== C := ", C);
log("=== C & '00'B := ", C & '00'B);
if (not match(C & '00'B, '10101110000'B)) {
setverdict(fail, "C does not match");
}
setverdict(pass);
}
MTC@DELL: Test case TC_bitstring_magic3 started.
MTC@DELL: === C := '101011100'B
MTC@DELL: === C & '00'B := '10101110000'B
MTC@DELL: setverdict(pass): none -> pass
Version: 6.6.1