[clang] 2946879 - [CIR] Fix assertion order in 'Address' (#157477)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 8 07:59:35 PDT 2025


Author: Erich Keane
Date: 2025-09-08T14:59:31Z
New Revision: 2946879c49d2cb17d1b53ff398edd681baf49417

URL: https://github.com/llvm/llvm-project/commit/2946879c49d2cb17d1b53ff398edd681baf49417
DIFF: https://github.com/llvm/llvm-project/commit/2946879c49d2cb17d1b53ff398edd681baf49417.diff

LOG: [CIR] Fix assertion order in 'Address' (#157477)

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.

Added: 
    

Modified: 
    clang/lib/CIR/CodeGen/Address.h

Removed: 
    


################################################################################
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);
   }


        


More information about the cfe-commits mailing list