[clang] [CIR] Fix assertion order in 'Address' (PR #157477)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 8 07:38:54 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangir
@llvm/pr-subscribers-clang
Author: Erich Keane (erichkeane)
<details>
<summary>Changes</summary>
We are checking the 'type' of 'pointer' before we are checking whether it is null or not! This is clearly incorrect, so this patch reorders the asserts.
---
Full diff: https://github.com/llvm/llvm-project/pull/157477.diff
1 Files Affected:
- (modified) clang/lib/CIR/CodeGen/Address.h (+3-3)
``````````diff
diff --git a/clang/lib/CIR/CodeGen/Address.h b/clang/lib/CIR/CodeGen/Address.h
index a851d06321cc1..fb74aa0f3bb00 100644
--- a/clang/lib/CIR/CodeGen/Address.h
+++ b/clang/lib/CIR/CodeGen/Address.h
@@ -44,13 +44,13 @@ class Address {
clang::CharUnits alignment)
: pointerAndKnownNonNull(pointer, false), elementType(elementType),
alignment(alignment) {
- assert(mlir::isa<cir::PointerType>(pointer.getType()) &&
- "Expected cir.ptr type");
-
assert(pointer && "Pointer cannot be null");
assert(elementType && "Element type cannot be null");
assert(!alignment.isZero() && "Alignment cannot be zero");
+ assert(mlir::isa<cir::PointerType>(pointer.getType()) &&
+ "Expected cir.ptr type");
+
assert(mlir::cast<cir::PointerType>(pointer.getType()).getPointee() ==
elementType);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/157477
More information about the cfe-commits
mailing list