Skip to content
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

SH: Use bitwise OR with mask for sign extension #2371

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

lhsazevedo
Copy link
Contributor

@lhsazevedo lhsazevedo commented May 29, 2024

Sign extend using bitwise OR with mask, instead of unary minus. Fixes error when building for UWP with Security Development Lifecycle (SDL) checks:

capstone\arch\SH\SHDisassembler.c(1463,11): error C4146: unary minus operator applied to unsigned type, result still unsigned [capstone\capstone.vcxproj]
capstone\arch\SH\SHDisassembler.c(1468,11): error C4146: unary minus operator applied to unsigned type, result still unsigned [capstone\capstone.vcxproj]

See https://learn.microsoft.com/en-us/cpp/build/reference/sdl-enable-additional-security-checks?view=msvc-170

Also inline with the rest of the codebase, which uses bitwise OR and mask for sign extension:

$ grep -r '|= ~' .
./arch/TMS320C64x/TMS320C64xDisassembler.c:		imm |= ~((1 << 5) - 1);
./arch/TMS320C64x/TMS320C64xDisassembler.c:		imm |= ~((1 << 16) - 1);
./arch/TMS320C64x/TMS320C64xDisassembler.c:		imm |= ~((1 << 7) - 1);
./arch/TMS320C64x/TMS320C64xDisassembler.c:		imm |= ~((1 << 10) - 1);
./arch/TMS320C64x/TMS320C64xDisassembler.c:		imm |= ~((1 << 12) - 1);
./arch/TMS320C64x/TMS320C64xDisassembler.c:		imm |= ~((1 << 21) - 1);
./arch/X86/X86Disassembler.c:							immediate |= ~(0xffull);
./arch/X86/X86Disassembler.c:							immediate |= ~(0xffffull);
./arch/X86/X86Disassembler.c:							immediate |= ~(0xffffffffull);
./arch/X86/X86Disassembler.c:					immediate |= ~(0xffull);
./arch/X86/X86Disassembler.c:					immediate |= ~(0xffffull);
./arch/X86/X86Disassembler.c:					immediate |= ~(0xffffffffull);
./arch/X86/X86Disassembler.c:					immediate |= ~(0xffull);
./arch/X86/X86Disassembler.c:					immediate |= ~(0xffffull);
./arch/X86/X86Disassembler.c:					immediate |= ~(0xffffffffull);
./arch/AArch64/AArch64Disassembler.c:		ImmVal |= ~((1LL << 19) - 1);
./arch/AArch64/AArch64Disassembler.c:		offset |= ~((1LL << 9) - 1);
./arch/AArch64/AArch64Disassembler.c:		offset |= ~((1LL << 7) - 1);
./arch/AArch64/AArch64Disassembler.c:		imm |= ~((1LL << 21) - 1);
./arch/AArch64/AArch64Disassembler.c:		imm |= ~((1LL << 26) - 1);
./arch/AArch64/AArch64Disassembler.c:		dst |= ~((1LL << 14) - 1);
./arch/AArch64/AArch64Disassembler.c:			Imm |= ~((1LL << Bits) - 1);                                       \
./arch/AArch64/AArch64AddressingModes.h:		Imm |= ~Mask;
./arch/SH/SHDisassembler.c:				imm |= ~((1 << 28) - 1);
./arch/SH/SHDisassembler.c:				imm |= ~((1 << 20) - 1);
$ grep -r '= -(' .
./MathExtras.h:	Value &= -((int8_t)Value);
./suite/synctools/tablegen/include/llvm/CodeGen/ReachingDefAnalysis.h:  const int ReachingDefDefaultVal = -(1 << 20);
./suite/synctools/tablegen/include/llvm/CodeGen/SelectionDAGNodes.h:      NId = -(NId + 1);

Suggested reviewer: @ysat0

Sign extend using bitwise OR with mask, instead of unary minus.
Fixes error when building for UWP with Security Development Lifecycle (SDL).
See https://learn.microsoft.com/en-us/cpp/build/reference/sdl-enable-additional-security-checks?view=msvc-170
@lhsazevedo lhsazevedo changed the title Use bitwise OR with mask for sign extension SH: Use bitwise OR with mask for sign extension May 29, 2024
@Rot127 Rot127 added this to the v5.0.2 milestone May 29, 2024
@XVilka
Copy link
Contributor

XVilka commented May 29, 2024

Should be also cherry-picked to next

@XVilka
Copy link
Contributor

XVilka commented Jun 1, 2024

@kabeor you forgot this one 😄

Copy link
Contributor

@ysat0 ysat0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.
Thanks.

@XVilka
Copy link
Contributor

XVilka commented Jun 8, 2024

@kabeor @aquynh

@XVilka
Copy link
Contributor

XVilka commented Jun 12, 2024

@kabeor

@aquynh aquynh merged commit e90ef39 into capstone-engine:v5 Jun 13, 2024
6 checks passed
@aquynh
Copy link
Collaborator

aquynh commented Jun 13, 2024

merged, thanks!

please can you also make a PR for the next branch?

@lhsazevedo
Copy link
Contributor Author

lhsazevedo commented Jun 13, 2024

Sure!

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.

5 participants