Skip to content

Commit

Permalink
Assert set_param_alignment_attribute's alignment is a power of 2
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDan64 committed Jul 21, 2019
1 parent 0af7642 commit 0f318d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/values/call_site_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ impl CallSiteValue {

/// Shortcut for setting the alignment `Attribute` for this `CallSiteValue`.
///
/// # Panics
///
/// When the alignment is not a power of 2.
///
/// # Example
///
/// ```no_run
Expand All @@ -475,6 +479,8 @@ impl CallSiteValue {
/// call_site_value.set_param_alignment_attribute(0, 2);
/// ```
pub fn set_param_alignment_attribute(&self, index: u32, alignment: u32) {
assert_eq!(alignment.count_ones(), 1, "Alignment must be a power of two.");

unsafe {
LLVMSetInstrParamAlignment(self.as_value_ref(), index, alignment)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/all/test_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn test_call_site() {

assert_eq!(call_site.get_call_convention(), 2);

call_site.set_param_alignment_attribute(0, 12);
call_site.set_param_alignment_attribute(0, 16);
}

#[test]
Expand Down

0 comments on commit 0f318d2

Please sign in to comment.