TAFFO-org/TAFFO

[Initializer] Integer base conversion is not correct

Closed this issue · 1 comments

When parsing integers in base 16, the result in base 10 does not correspond to the original value.

TEST_F(AnnotationParserTest, IntegerNoSignBase16) {
// valid, positive integer without sign in base 16
// 0x0123456789abcdef (base 16) = 81985529216486895 (base 10)
annstr = llvm::StringRef("backtracking(0x0123456789AbCdEf) struct[void]");
res = parser.parseAnnotationString(annstr);
error = parser.lastError().str();
EXPECT_EQ(NO_ERR, error);
ASSERT_TRUE(res);
EXPECT_EQ(parser.backtrackingDepth, 81985529216486895);
}


[ RUN      ] AnnotationParserTest.IntegerNoSignBase16
TAFFO/unittests/Initializer/TaffoInitializer/AnnotationParserTest.cpp:738: Failure
      Expected: parser.backtrackingDepth
      Which is: 2309737967
To be equal to: 81985529216486895
[  FAILED  ] AnnotationParserTest.IntegerNoSignBase16 (0 ms)

TEST_F(AnnotationParserTest, IntegerPositiveSignBase16) {
// valid, positive integer in base 16
// 0x0123456789abcdef (base 16) = 81985529216486895 (base 10)
annstr = llvm::StringRef("backtracking(+0x0123456789aBcDeF) struct[void]");
res = parser.parseAnnotationString(annstr);
error = parser.lastError().str();
EXPECT_EQ(NO_ERR, error);
ASSERT_TRUE(res);
EXPECT_EQ(parser.backtrackingDepth, 81985529216486895);
}


[ RUN      ] AnnotationParserTest.IntegerPositiveSignBase16
TAFFO/unittests/Initializer/TaffoInitializer/AnnotationParserTest.cpp:750: Failure
      Expected: parser.backtrackingDepth
      Which is: 2309737967
To be equal to: 81985529216486895
[  FAILED  ] AnnotationParserTest.IntegerPositiveSignBase16 (0 ms)

TEST_F(AnnotationParserTest, IntegerNegativeSignBase16) {
// valid, negative integer in base 16
// 0x0123456789abcdef (base 16) = 81985529216486895 (base 10)
annstr = llvm::StringRef("backtracking(-0x0123456789abcDEF) struct[void]");
res = parser.parseAnnotationString(annstr);
error = parser.lastError().str();
EXPECT_EQ(NO_ERR, error);
ASSERT_TRUE(res);
EXPECT_EQ(parser.backtrackingDepth, -81985529216486895);
}


[ RUN      ] AnnotationParserTest.IntegerNegativeSignBase16
TAFFO/unittests/Initializer/TaffoInitializer/AnnotationParserTest.cpp:762: Failure
      Expected: parser.backtrackingDepth
      Which is: 1985229329
To be equal to: -81985529216486895
[  FAILED  ] AnnotationParserTest.IntegerNegativeSignBase16 (0 ms)

This was only due to truncation to 32 bits due to the use of int/unsigned variables, so this is actually intended behavior.