Skip to content

Improve testcases for unsigned char platforms#5524

Merged
chrchr-github merged 1 commit intocppcheck-opensource:mainfrom
moui0:main
Oct 7, 2023
Merged

Improve testcases for unsigned char platforms#5524
chrchr-github merged 1 commit intocppcheck-opensource:mainfrom
moui0:main

Conversation

@moui0
Copy link
Copy Markdown
Contributor

@moui0 moui0 commented Oct 7, 2023

I got error messages while building cppcheck 2.12.0 for RISC-V Arch Linux:

Testing Complete
Number of tests: 4420
Number of todos: 331
Tests failed: 2

/usr/src/debug/cppcheck/cppcheck/test/testcondition.cpp:4501(TestCondition::alwaysTrue): Assertion failed. 
Expected: 
[test.cpp:6]: (style) Condition 'o[1]=='\0'' is always false\n

Actual: 
[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\0'' is always false\n

_____
/usr/src/debug/cppcheck/cppcheck/test/testcondition.cpp:5014(TestCondition::alwaysTrueContainer): Assertion failed. 
Expected: 
[test.cpp:5]: (style) Condition 'buffer.back()=='\0'' is always false\n

Actual: 
[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\0'' is always false\n

I found out the reason is that the testcases were designed for x86/x86_64 or other signed char platforms (i.e. default character type is signed char ), whereareas RISC-V is an unsigned char platform, which causes different behavior in lib/valueflow.cpp:valueFlowImpossibleValues. I'm not sure whether this error leads from a functional bug, so if you have a better approach to fix it, please let me know.

Maybe you could reproduce this error on x86_64 platform by setting defaultSign = 'u'; in Platform::set(Type t).

moui0 added a commit to moui0/archriscv-packages that referenced this pull request Oct 7, 2023
Improve cppcheck testcases on `unsigned char` platform.

Upstreamed: cppcheck-opensource/cppcheck#5524
@chrchr-github
Copy link
Copy Markdown
Collaborator

@moui0
Copy link
Copy Markdown
Contributor Author

moui0 commented Oct 7, 2023

Is it possible to fix this problem by modifying valueflow.cpp, as the current fix is not efficient?

Perhaps a similar code block can be added for signed, but this may lead to similar issues in many testcases on the x86 platform:

https://github.com/danmar/cppcheck/blob/723ba16eb657b4369d3d67727ae271bec6d8bfad/lib/valueflow.cpp#L1836-L1844

felixonmars pushed a commit to felixonmars/archriscv-packages that referenced this pull request Oct 7, 2023
Improve cppcheck testcases on `unsigned char` platform.

Upstreamed: cppcheck-opensource/cppcheck#5524
@chrchr-github chrchr-github merged commit eb076d8 into cppcheck-opensource:main Oct 7, 2023
@chrchr-github
Copy link
Copy Markdown
Collaborator

@moui0 How do you want to be credited as an author?

@moui0
Copy link
Copy Markdown
Contributor Author

moui0 commented Oct 8, 2023

Wang Haoyu, please. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants