[llvm] IR: Use cast_or_null for module flag getters (PR #225629)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 01:01:47 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
The verifier enforces all of these have the correct type
---
Full diff: https://github.com/llvm/llvm-project/pull/225629.diff
1 Files Affected:
- (modified) llvm/lib/IR/Module.cpp (+4-6)
``````````diff
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 5544663a510df4..9eb41accb4cc29 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -683,8 +683,7 @@ void Module::setCodeModel(CodeModel::Model CL) {
}
LongDoubleFormat Module::getLongDoubleFormat() const {
- if (auto *Val =
- dyn_cast_or_null<MDString>(getModuleFlag("long-double-type"))) {
+ if (auto *Val = cast_or_null<MDString>(getModuleFlag("long-double-type"))) {
if (std::optional<LongDoubleFormat> Format =
parseLongDoubleFormat(Val->getString()))
return *Format;
@@ -699,7 +698,7 @@ void Module::setLongDoubleFormat(LongDoubleFormat Format) {
}
FloatABI::ABIType Module::getFloatABI() const {
- if (auto *Val = dyn_cast_or_null<MDString>(getModuleFlag("float-abi")))
+ if (auto *Val = cast_or_null<MDString>(getModuleFlag("float-abi")))
return *FloatABI::parseABIType(Val->getString());
// Without an explicit flag, fall back to the ABI implied by the target
// triple.
@@ -718,7 +717,7 @@ void Module::setThreadModel(ThreadModel Model) {
}
ExceptionHandling Module::getExceptionModel() const {
- if (auto *Val = dyn_cast_or_null<MDString>(getModuleFlag("exception-model")))
+ if (auto *Val = cast_or_null<MDString>(getModuleFlag("exception-model")))
return *parseExceptionModel(Val->getString());
// TODO: Return getDefaultExceptionHandling when TargetOptions field is
@@ -1005,8 +1004,7 @@ void Module::setDarwinTargetVariantSDKVersion(VersionTuple Version) {
StringRef Module::getTargetABIFromMD() {
StringRef TargetABI;
- if (auto *TargetABIMD =
- dyn_cast_or_null<MDString>(getModuleFlag("target-abi")))
+ if (auto *TargetABIMD = cast_or_null<MDString>(getModuleFlag("target-abi")))
TargetABI = TargetABIMD->getString();
return TargetABI;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/225629
More information about the llvm-commits
mailing list