-
Notifications
You must be signed in to change notification settings - Fork 80
Add type checking to {bitcast,ptrtoint,inttoptr} #69
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3e660f5
Typecheck {bitcast,ptrtoint,inttoptr} construction
pwaller d51964f
Check fromSize < toSize in trunc construction
pwaller fdf0ef2
Type check insertvalue operands
pwaller 79d4e4b
Support PointerType in aggregateElemType
pwaller 4e8d2c0
Add missing inst.Type()
pwaller 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
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 |
---|---|---|
|
@@ -30,6 +30,11 @@ type InstTrunc struct { | |
// NewTrunc returns a new trunc instruction based on the given source value and | ||
// target type. | ||
func NewTrunc(from value.Value, to types.Type) *InstTrunc { | ||
fromSize := from.Type().(*types.IntType).BitSize | ||
toSize := to.(*types.IntType).BitSize | ||
if fromSize < toSize { | ||
panic(fmt.Errorf("invalid trunc: from.BitSize < to.BitSize (%v < %v)", fromSize, toSize)) | ||
} | ||
return &InstTrunc{From: from, To: to} | ||
} | ||
|
||
|
@@ -444,6 +449,12 @@ type InstPtrToInt struct { | |
// NewPtrToInt returns a new ptrtoint instruction based on the given source | ||
// value and target type. | ||
func NewPtrToInt(from value.Value, to types.Type) *InstPtrToInt { | ||
if _, isFromPointer := from.Type().(*types.PointerType); !isFromPointer { | ||
panic(fmt.Errorf("invalid ptrtoint operand type; expected *types.PointerType, got \"from\": %T", from.Type())) | ||
} | ||
if _, isToInt := to.(*types.IntType); !isToInt { | ||
panic(fmt.Errorf("invalid ptrtoint operand type; expected *types.IntType, got \"to\": %T", to)) | ||
} | ||
return &InstPtrToInt{From: from, To: to} | ||
} | ||
|
||
|
@@ -490,6 +501,12 @@ type InstIntToPtr struct { | |
// NewIntToPtr returns a new inttoptr instruction based on the given source | ||
// value and target type. | ||
func NewIntToPtr(from value.Value, to types.Type) *InstIntToPtr { | ||
if _, isFromInt := from.Type().(*types.IntType); !isFromInt { | ||
panic(fmt.Errorf("invalid inttoptr operand type; expected *types.IntType, got \"from\": %T", from.Type())) | ||
} | ||
if _, isToPtr := to.(*types.PointerType); !isToPtr { | ||
panic(fmt.Errorf("invalid inttoptr operand type; expected *types.PointerType, got \"to\": %T", to)) | ||
} | ||
return &InstIntToPtr{From: from, To: to} | ||
} | ||
|
||
|
@@ -536,6 +553,12 @@ type InstBitCast struct { | |
// NewBitCast returns a new bitcast instruction based on the given source value | ||
// and target type. | ||
func NewBitCast(from value.Value, to types.Type) *InstBitCast { | ||
if _, isFromPtr := from.Type().(*types.PointerType); !isFromPtr { | ||
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. I'm fairly sure you can bitcase, e.g. a 64-bit integer into a 64-bit floating point value.
|
||
panic(fmt.Errorf("invalid bitcast operand type; expected *types.PointerType, got \"from\": %T", from.Type())) | ||
} | ||
if _, isToPtr := to.(*types.PointerType); !isToPtr { | ||
panic(fmt.Errorf("invalid bitcast operand type; expected *types.PointerType, got \"to\": %T", to)) | ||
} | ||
return &InstBitCast{From: from, To: to} | ||
} | ||
|
||
|
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.
Uh oh!
There was an error while loading. Please reload this page.