-
Notifications
You must be signed in to change notification settings - Fork 3
X86_64: silence some truncation warnings #76
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
Open
compnerd
wants to merge
1
commit into
main
Choose a base branch
from
compnerd/truncation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,13 +238,14 @@ struct CPUState64 { | |
gp.r14 = regs[14]; | ||
gp.r15 = regs[15]; | ||
gp.rip = regs[16]; | ||
gp.eflags = regs[17]; | ||
gp.cs = regs[18]; | ||
gp.ss = regs[19]; | ||
gp.ds = regs[20]; | ||
gp.es = regs[21]; | ||
gp.fs = regs[22]; | ||
gp.gs = regs[23]; | ||
// Truncate the value to 32-bit as these are 32-bit registers. | ||
gp.eflags = static_cast<uint32_t>(regs[17]); | ||
gp.cs = static_cast<uint32_t>(regs[18]); | ||
gp.ss = static_cast<uint32_t>(regs[19]); | ||
gp.ds = static_cast<uint32_t>(regs[20]); | ||
gp.es = static_cast<uint32_t>(regs[21]); | ||
gp.fs = static_cast<uint32_t>(regs[22]); | ||
gp.gs = static_cast<uint32_t>(regs[23]); | ||
} | ||
|
||
public: | ||
|
@@ -594,7 +595,7 @@ struct CPUState { | |
} | ||
inline void setPC(uint64_t pc) { | ||
if (is32) | ||
state32.setPC(pc); | ||
state32.setPC(static_cast<uint32_t>(pc)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in slack, IMO better to have a helper like
|
||
else | ||
state64.setPC(pc); | ||
} | ||
|
@@ -604,7 +605,7 @@ struct CPUState { | |
} | ||
inline void setSP(uint64_t sp) { | ||
if (is32) | ||
state32.setSP(sp); | ||
state32.setSP(static_cast<uint32_t>(sp)); | ||
else | ||
state64.setSP(sp); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ ErrorCode HardwareBreakpointManager::disableLocation(int idx, | |
|
||
ErrorCode HardwareBreakpointManager::enableDebugCtrlReg(uint64_t &ctrlReg, | ||
int idx, Mode mode, | ||
int size) { | ||
size_t size) { | ||
int enableIdx = idx * 2; | ||
#if !defined(OS_WIN32) | ||
enableIdx += 1; | ||
|
@@ -193,7 +193,7 @@ int HardwareBreakpointManager::hit(Target::Thread *thread, Site &site) { | |
if (debugRegs[kStatusRegIdx] & (1ull << i)) { | ||
DS2ASSERT(_locations[i] != 0); | ||
site = _sites.find(_locations[i])->second; | ||
regIdx = i; | ||
regIdx = static_cast<int>(i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simpler to s/size_t/int/ at l.192? |
||
break; | ||
} | ||
} | ||
|
@@ -277,11 +277,13 @@ ErrorCode HardwareBreakpointManager::writeDebugRegisters( | |
state.dr.dr[i] = (i == 4 || i == 5) ? 0 : regs[i]; | ||
} | ||
#elif defined(ARCH_X86_64) | ||
for (int i = 0; i < kNumDebugRegisters; ++i) { | ||
for (size_t i = 0; i < kNumDebugRegisters; ++i) { | ||
if (state.is32) { | ||
state.state32.dr.dr[i] = (i == 4 || i == 5) ? 0 : regs[i]; | ||
state.state32.dr.dr[i] = | ||
(i == 4 || i == 5) ? 0 : static_cast<uint32_t>(regs[i]); | ||
} else { | ||
state.state64.dr.dr[i] = (i == 4 || i == 5) ? 0 : regs[i]; | ||
state.state64.dr.dr[i] = | ||
(i == 4 || i == 5) ? 0 : static_cast<uint32_t>(regs[i]); | ||
} | ||
} | ||
#else | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I'm a bit confused about the point of CPUState64 being a union. Why not simply
memcpy(gp.regs, regs, sizeof(gp.regs));
and avoid the need to remember which of these need to be truncated, etc?