Skip to content

Commit 0f318d2

Browse files
committed
Assert set_param_alignment_attribute's alignment is a power of 2
1 parent 0af7642 commit 0f318d2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/values/call_site_value.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ impl CallSiteValue {
455455

456456
/// Shortcut for setting the alignment `Attribute` for this `CallSiteValue`.
457457
///
458+
/// # Panics
459+
///
460+
/// When the alignment is not a power of 2.
461+
///
458462
/// # Example
459463
///
460464
/// ```no_run
@@ -475,6 +479,8 @@ impl CallSiteValue {
475479
/// call_site_value.set_param_alignment_attribute(0, 2);
476480
/// ```
477481
pub fn set_param_alignment_attribute(&self, index: u32, alignment: u32) {
482+
assert_eq!(alignment.count_ones(), 1, "Alignment must be a power of two.");
483+
478484
unsafe {
479485
LLVMSetInstrParamAlignment(self.as_value_ref(), index, alignment)
480486
}

tests/all/test_values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn test_call_site() {
6060

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

63-
call_site.set_param_alignment_attribute(0, 12);
63+
call_site.set_param_alignment_attribute(0, 16);
6464
}
6565

6666
#[test]

0 commit comments

Comments
 (0)