mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-22 13:11:32 +00:00
Fix leak. Only create one NamedMDNode for each name.
This commit is contained in:
@ -1198,8 +1198,13 @@ pub fn tbaa_label(
|
|||||||
let context = module.get_context();
|
let context = module.get_context();
|
||||||
|
|
||||||
// `!wasmer_tbaa_root = {}`, the TBAA root node for wasmer.
|
// `!wasmer_tbaa_root = {}`, the TBAA root node for wasmer.
|
||||||
module.add_global_metadata("wasmer_tbaa_root", &MetadataValue::create_node(&[]));
|
let tbaa_root = module
|
||||||
let tbaa_root = module.get_global_metadata("wasmer_tbaa_root")[0];
|
.get_global_metadata("wasmer_tbaa_root")
|
||||||
|
.pop()
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
module.add_global_metadata("wasmer_tbaa_root", &MetadataValue::create_node(&[]));
|
||||||
|
module.get_global_metadata("wasmer_tbaa_root")[0]
|
||||||
|
});
|
||||||
|
|
||||||
// Construct (or look up) the type descriptor, for example
|
// Construct (or look up) the type descriptor, for example
|
||||||
// `!"local 0" = !{!"local 0", !wasmer_tbaa_root}`.
|
// `!"local 0" = !{!"local 0", !wasmer_tbaa_root}`.
|
||||||
@ -1209,28 +1214,38 @@ pub fn tbaa_label(
|
|||||||
label.to_string()
|
label.to_string()
|
||||||
};
|
};
|
||||||
let type_label = context.metadata_string(label.as_str());
|
let type_label = context.metadata_string(label.as_str());
|
||||||
module.add_global_metadata(
|
let type_tbaa = module
|
||||||
label.as_str(),
|
.get_global_metadata(label.as_str())
|
||||||
&MetadataValue::create_node(&[type_label.into(), tbaa_root.into()]),
|
.pop()
|
||||||
);
|
.unwrap_or_else(|| {
|
||||||
let type_tbaa = module.get_global_metadata(label.as_str())[0];
|
module.add_global_metadata(
|
||||||
|
label.as_str(),
|
||||||
|
&MetadataValue::create_node(&[type_label.into(), tbaa_root.into()]),
|
||||||
|
);
|
||||||
|
module.get_global_metadata(label.as_str())[0]
|
||||||
|
});
|
||||||
|
|
||||||
// Construct (or look up) the access tag, which is a struct of the form
|
// Construct (or look up) the access tag, which is a struct of the form
|
||||||
// (base type, acess type, offset).
|
// (base type, access type, offset).
|
||||||
//
|
//
|
||||||
// "If BaseTy is a scalar type, Offset must be 0 and BaseTy and AccessTy
|
// "If BaseTy is a scalar type, Offset must be 0 and BaseTy and AccessTy
|
||||||
// must be the same".
|
// must be the same".
|
||||||
// -- https://llvm.org/docs/LangRef.html#tbaa-metadata
|
// -- https://llvm.org/docs/LangRef.html#tbaa-metadata
|
||||||
let label = label + "_memop";
|
let label = label + "_memop";
|
||||||
module.add_global_metadata(
|
let type_tbaa = module
|
||||||
label.as_str(),
|
.get_global_metadata(label.as_str())
|
||||||
&MetadataValue::create_node(&[
|
.pop()
|
||||||
type_tbaa.into(),
|
.unwrap_or_else(|| {
|
||||||
type_tbaa.into(),
|
module.add_global_metadata(
|
||||||
intrinsics.i64_zero.into(),
|
label.as_str(),
|
||||||
]),
|
&MetadataValue::create_node(&[
|
||||||
);
|
type_tbaa.into(),
|
||||||
let type_tbaa = module.get_global_metadata(label.as_str())[0];
|
type_tbaa.into(),
|
||||||
|
intrinsics.i64_zero.into(),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
module.get_global_metadata(label.as_str())[0]
|
||||||
|
});
|
||||||
|
|
||||||
// Attach the access tag to the instruction.
|
// Attach the access tag to the instruction.
|
||||||
let tbaa_kind = context.get_kind_id("tbaa");
|
let tbaa_kind = context.get_kind_id("tbaa");
|
||||||
|
Reference in New Issue
Block a user