[clang] [CodeGen] Replace loop with "if !empty()" (PR #166515)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 4 23:20:25 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Vitaly Buka (vitalybuka)
<details>
<summary>Changes</summary>
The loop iterates once and returns the first element.
Replace it with "if !empty()" to make it more explicit.
---
Full diff: https://github.com/llvm/llvm-project/pull/166515.diff
1 Files Affected:
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2-3)
``````````diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0fea57b2e1799..98d59b79ab881 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2368,9 +2368,8 @@ static QualType GeneralizeTransparentUnion(QualType Ty) {
const RecordDecl *UD = UT->getDecl()->getDefinitionOrSelf();
if (!UD->hasAttr<TransparentUnionAttr>())
return Ty;
- for (const auto *it : UD->fields()) {
- return it->getType();
- }
+ if (!UD->fields().empty())
+ return UD->fields().begin()->getType();
return Ty;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/166515
More information about the cfe-commits
mailing list