Skip to content

Commit

Permalink
Use known int attribute 'alignstack' instead of attribute with id rus…
Browse files Browse the repository at this point in the history
…t-lang#1.

LLVM will assert if stack alignment is not a power of 2. Switch value to 16.

Fixes rust-lang#73.
  • Loading branch information
nlewycky committed Jul 3, 2019
1 parent 0d7a64e commit 65e90c5
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions tests/all/test_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ fn test_attributes_on_function_values() {
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = fn_value.append_basic_block("entry");
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let alignstack_attribute = Attribute::get_named_enum_kind_id("alignstack");
let enum_attribute = context.create_enum_attribute(alignstack_attribute, 1);

builder.position_at_end(&entry_bb);
builder.build_return(None);
Expand All @@ -116,25 +117,25 @@ fn test_attributes_on_function_values() {
assert_eq!(fn_value.count_attributes(1), 0);

fn_value.remove_string_attribute(0, "my_key"); // Noop
fn_value.remove_enum_attribute(0, 1); // Noop
fn_value.remove_enum_attribute(0, alignstack_attribute); // Noop

// define align 1 "my_key"="my_val" void @my_fn()
fn_value.add_attribute(0, string_attribute);
fn_value.add_attribute(1, string_attribute); // Applied to 1st param
fn_value.add_attribute(0, enum_attribute);

assert_eq!(fn_value.count_attributes(0), 2);
assert_eq!(fn_value.get_enum_attribute(0, 1), Some(enum_attribute));
assert_eq!(fn_value.get_enum_attribute(0, alignstack_attribute), Some(enum_attribute));
assert_eq!(fn_value.get_string_attribute(0, "my_key"), Some(string_attribute));

fn_value.remove_string_attribute(0, "my_key");

assert_eq!(fn_value.count_attributes(0), 1);

fn_value.remove_enum_attribute(0, 1);
fn_value.remove_enum_attribute(0, alignstack_attribute);

assert_eq!(fn_value.count_attributes(0), 0);
assert!(fn_value.get_enum_attribute(0, 1).is_none());
assert!(fn_value.get_enum_attribute(0, alignstack_attribute).is_none());
assert!(fn_value.get_string_attribute(0, "my_key").is_none());
}

Expand All @@ -149,7 +150,8 @@ fn test_attributes_on_call_site_values() {
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = fn_value.append_basic_block("entry");
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let alignstack_attribute = Attribute::get_named_enum_kind_id("alignstack");
let enum_attribute = context.create_enum_attribute(alignstack_attribute, 1);

builder.position_at_end(&entry_bb);

Expand All @@ -162,29 +164,29 @@ fn test_attributes_on_call_site_values() {
assert_eq!(call_site_value.count_attributes(1), 0);

call_site_value.remove_string_attribute(0, "my_key"); // Noop
call_site_value.remove_enum_attribute(0, 1); // Noop
call_site_value.remove_enum_attribute(0, alignstack_attribute); // Noop

// define align 1 "my_key"="my_val" void @my_fn()
call_site_value.add_attribute(0, string_attribute);
call_site_value.add_attribute(1, string_attribute); // Applied to 1st param
call_site_value.add_attribute(0, enum_attribute);

assert_eq!(call_site_value.count_attributes(0), 2);
assert_eq!(call_site_value.get_enum_attribute(0, 1), Some(enum_attribute));
assert_eq!(call_site_value.get_enum_attribute(0, alignstack_attribute), Some(enum_attribute));
assert_eq!(call_site_value.get_string_attribute(0, "my_key"), Some(string_attribute));

call_site_value.remove_string_attribute(0, "my_key");

assert_eq!(call_site_value.count_attributes(0), 1);

call_site_value.remove_enum_attribute(0, 1);
call_site_value.remove_enum_attribute(0, alignstack_attribute);

assert_eq!(call_site_value.count_attributes(0), 0);
assert!(call_site_value.get_enum_attribute(0, 1).is_none());
assert!(call_site_value.get_enum_attribute(0, alignstack_attribute).is_none());
assert!(call_site_value.get_string_attribute(0, "my_key").is_none());
assert_eq!(call_site_value.get_called_fn_value(), fn_value);

call_site_value.set_param_alignment_attribute(0, 12);
call_site_value.set_param_alignment_attribute(0, 16);

assert_eq!(call_site_value.count_attributes(0), 1);
assert!(call_site_value.get_enum_attribute(0, 1).is_some());
Expand Down

0 comments on commit 65e90c5

Please sign in to comment.