[llvm-branch-commits] [clang] clang: Use a switch over APFloat semantics instead of if chain (PR #207213)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jul 2 09:01:36 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
Replace the chain of fltSemantics singleton address comparisons with a
switch over the APFloatBase::Semantics enum.
Co-authored-by: Claude (Opus 4.8) <noreply@<!-- -->anthropic.com>
---
Full diff: https://github.com/llvm/llvm-project/pull/207213.diff
1 Files Affected:
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+11-8)
``````````diff
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp
index c68a24ca045bc..ddf82ab5b33f8 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -301,21 +301,24 @@ void CodeGenTypes::RefreshTypeCacheForClass(const CXXRecordDecl *RD) {
static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext,
const llvm::fltSemantics &format) {
- if (&format == &llvm::APFloat::IEEEhalf())
+ switch (llvm::APFloat::SemanticsToEnum(format)) {
+ case llvm::APFloat::S_IEEEhalf:
return llvm::Type::getHalfTy(VMContext);
- if (&format == &llvm::APFloat::BFloat())
+ case llvm::APFloat::S_BFloat:
return llvm::Type::getBFloatTy(VMContext);
- if (&format == &llvm::APFloat::IEEEsingle())
+ case llvm::APFloat::S_IEEEsingle:
return llvm::Type::getFloatTy(VMContext);
- if (&format == &llvm::APFloat::IEEEdouble())
+ case llvm::APFloat::S_IEEEdouble:
return llvm::Type::getDoubleTy(VMContext);
- if (&format == &llvm::APFloat::IEEEquad())
+ case llvm::APFloat::S_IEEEquad:
return llvm::Type::getFP128Ty(VMContext);
- if (&format == &llvm::APFloat::PPCDoubleDouble())
+ case llvm::APFloat::S_PPCDoubleDouble:
return llvm::Type::getPPC_FP128Ty(VMContext);
- if (&format == &llvm::APFloat::x87DoubleExtended())
+ case llvm::APFloat::S_x87DoubleExtended:
return llvm::Type::getX86_FP80Ty(VMContext);
- llvm_unreachable("Unknown float format!");
+ default:
+ llvm_unreachable("Unknown float format!");
+ }
}
llvm::Type *CodeGenTypes::ConvertFunctionTypeInternal(QualType QFT) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/207213
More information about the llvm-branch-commits
mailing list