Add -Z llvm_module_flag
Allow adding values to the `!llvm.module.flags` metadata for a generated module. The syntax is `-Z llvm_module_flag=<name>:<type>:<value>:<behavior>` Currently only u32 values are supported but the type is required to be specified for forward compatibility. The `behavior` element must match one of the named LLVM metadata behaviors.viors. This flag is expected to be perma-unstable.
This commit is contained in:
parent
2c1b65ee14
commit
2e6b57541d
5 changed files with 68 additions and 0 deletions
|
@ -368,6 +368,24 @@ pub unsafe fn create_module<'ll>(
|
|||
llvm::LLVMMDNodeInContext(llcx, &name_metadata, 1),
|
||||
);
|
||||
|
||||
// Add module flags specified via -Z llvm_module_flag
|
||||
for (key, value, behavior) in &sess.opts.unstable_opts.llvm_module_flag {
|
||||
let key = format!("{key}\0");
|
||||
let behavior = match behavior.as_str() {
|
||||
"error" => llvm::LLVMModFlagBehavior::Error,
|
||||
"warning" => llvm::LLVMModFlagBehavior::Warning,
|
||||
"require" => llvm::LLVMModFlagBehavior::Require,
|
||||
"override" => llvm::LLVMModFlagBehavior::Override,
|
||||
"append" => llvm::LLVMModFlagBehavior::Append,
|
||||
"appendunique" => llvm::LLVMModFlagBehavior::AppendUnique,
|
||||
"max" => llvm::LLVMModFlagBehavior::Max,
|
||||
"min" => llvm::LLVMModFlagBehavior::Min,
|
||||
// We already checked this during option parsing
|
||||
_ => unreachable!(),
|
||||
};
|
||||
llvm::LLVMRustAddModuleFlag(llmod, behavior, key.as_ptr().cast(), *value)
|
||||
}
|
||||
|
||||
llmod
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue