[llvm] IR: Use cast_or_null for module flag getters (PR #225629)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 01:00:52 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/225629

The verifier enforces all of these have the correct type

>From 21ca4b64a5f0ea67fe3dc9b4f14cbcad23573f52 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 23 Sep 2026 09:59:24 +0200
Subject: [PATCH] IR: Use cast_or_null for module flag getters

The verifier enforces all of these have the correct type
---
 llvm/lib/IR/Module.cpp | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index 5544663a510df..9eb41accb4cc2 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;
 }



More information about the llvm-commits mailing list