Skip to content

Conversation

@erichkeane
Copy link
Collaborator

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.

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.
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Sep 8, 2025
@erichkeane erichkeane enabled auto-merge (squash) September 8, 2025 14:38
@llvmbot
Copy link
Member

llvmbot commented Sep 8, 2025

@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: Erich Keane (erichkeane)

Changes

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

Copy link
Contributor

@xlauko xlauko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@mmha mmha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@erichkeane erichkeane merged commit 2946879 into llvm:main Sep 8, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants