Skip to content

[CIR] Exclude _BitInt from fundamental integer type constraints - #191493

Merged
adams381 merged 1 commit into
llvm:mainfrom
adams381:bitint-fundamental-type-fix
Apr 13, 2026
Merged

adams381 merged 1 commit into
llvm:mainfrom
adams381:bitint-fundamental-type-fix

Conversation

@adams381

Copy link
Copy Markdown
Contributor

Follow-up to #188113 per @erichkeane's feedback: isFundamentalIntType and isFundamental() should not disagree.

The previous patch added !isBitInt() only inside IntType::isFundamental(), leaving the underlying TableGen predicates (CIR_AnyFundamentalIntType etc.) unaware of _BitInt. That meant isSignedFundamental() and isUnsignedFundamental() were silently wrong — a _BitInt(32) would pass them.

This patch adds a CIR_IsNotBitIntPred to the three fundamental-int constraint defs so everything stays consistent. isFundamental() now just forwards to isFundamentalIntType() with no extra logic.

Includes an invalid-bitint.cir test that checks a _BitInt(32) is rejected where a fundamental unsigned int is required.

Made with Cursor

Move the _BitInt exclusion from IntType::isFundamental() into the
TableGen type-constraint definitions (CIR_AnyFundamentalIntType,
CIR_AnyFundamentalUIntType, CIR_AnyFundamentalSIntType) so that
isFundamentalIntType() and isFundamental() agree.  This also fixes
isSignedFundamental() and isUnsignedFundamental(), which previously
did not exclude _BitInt types.

Follow-up to llvm#188113 addressing review feedback from @erichkeane.

Made-with: Cursor
@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Apr 10, 2026
@llvmbot

llvmbot commented Apr 10, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-clangir

@llvm/pr-subscribers-clang

Author: adams381

Changes

Follow-up to #188113 per @erichkeane's feedback: isFundamentalIntType and isFundamental() should not disagree.

The previous patch added !isBitInt() only inside IntType::isFundamental(), leaving the underlying TableGen predicates (CIR_AnyFundamentalIntType etc.) unaware of _BitInt. That meant isSignedFundamental() and isUnsignedFundamental() were silently wrong — a _BitInt(32) would pass them.

This patch adds a CIR_IsNotBitIntPred to the three fundamental-int constraint defs so everything stays consistent. isFundamental() now just forwards to isFundamentalIntType() with no extra logic.

Includes an invalid-bitint.cir test that checks a _BitInt(32) is rejected where a fundamental unsigned int is required.

Made with Cursor


Full diff: https://github.com/llvm/llvm-project/pull/191493.diff

3 Files Affected:

  • (modified) clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td (+9-3)
  • (modified) clang/include/clang/CIR/Dialect/IR/CIRTypes.td (+1-1)
  • (added) clang/test/CIR/IR/invalid-bitint.cir (+13)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
index 2a92437c64811..3cc79b9796e06 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
@@ -110,21 +110,27 @@ def CIR_SInt128 : CIR_SInt<128>;
 
 // Fundamental integer types represent standard source-level integer types that
 // have a specified set of admissible bitwidths (8, 16, 32, 64).
+// _BitInt types are excluded even when their width matches a fundamental width.
+
+def CIR_IsNotBitIntPred : CPred<"!$_self.getIsBitInt()">;
 
 def CIR_AnyFundamentalIntType
-    : CIR_ConfinedType<CIR_AnyIntType, [CIR_HasFundamentalIntWidthPred],
+    : CIR_ConfinedType<CIR_AnyIntType,
+        [CIR_HasFundamentalIntWidthPred, CIR_IsNotBitIntPred],
         "fundamental integer type"> {
     let cppFunctionName = "isFundamentalIntType";
 }
 
 def CIR_AnyFundamentalUIntType
-    : CIR_ConfinedType<CIR_AnyUIntType, [CIR_HasFundamentalIntWidthPred],
+    : CIR_ConfinedType<CIR_AnyUIntType,
+        [CIR_HasFundamentalIntWidthPred, CIR_IsNotBitIntPred],
         "fundamental unsigned integer type"> {
     let cppFunctionName = "isFundamentalUIntType";
 }
 
 def CIR_AnyFundamentalSIntType
-    : CIR_ConfinedType<CIR_AnySIntType, [CIR_HasFundamentalIntWidthPred],
+    : CIR_ConfinedType<CIR_AnySIntType,
+        [CIR_HasFundamentalIntWidthPred, CIR_IsNotBitIntPred],
         "fundamental signed integer type"> {
     let cppFunctionName = "isFundamentalSIntType";
 }
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index b177eab08ccad..1114eb667280a 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -79,7 +79,7 @@ def CIR_IntType : CIR_Type<"Int", "int", [
     /// unsigned integer types whose bit width is 8, 16, 32, or 64).
     /// _BitInt types are never fundamental even if their width matches.
     bool isFundamental() const {
-      return !isBitInt() && isFundamentalIntType(*this);
+      return isFundamentalIntType(*this);
     }
     bool isSignedFundamental() const {
       return isFundamentalSIntType(*this);
diff --git a/clang/test/CIR/IR/invalid-bitint.cir b/clang/test/CIR/IR/invalid-bitint.cir
new file mode 100644
index 0000000000000..450d2ae29ac9a
--- /dev/null
+++ b/clang/test/CIR/IR/invalid-bitint.cir
@@ -0,0 +1,13 @@
+// RUN: cir-opt %s -verify-diagnostics -split-input-file
+
+// _BitInt types with fundamental widths should not satisfy fundamental type
+// constraints.  Verify that cir.libc.memcpy rejects a _BitInt(32) length.
+
+module {
+  cir.func @bitint_not_fundamental_memcpy(%src : !cir.ptr<!cir.void>,
+                                          %len : !cir.int<u, 32, bitint>) {
+    // expected-error@+1 {{'cir.libc.memcpy' op operand #2 must be fundamental unsigned integer type, but got '!cir.int<u, 32, bitint>'}}
+    cir.libc.memcpy %len bytes from %src to %src : !cir.int<u, 32, bitint>, !cir.ptr<!cir.void> -> !cir.ptr<!cir.void>
+    cir.return
+  }
+}

@adams381
adams381 requested a review from erichkeane April 10, 2026 19:31
@adams381
adams381 merged commit 79647b1 into llvm:main Apr 13, 2026
13 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