[llvm] [IR] Reject token and label overload types in intrinsic signature matching (PR #210799)

Akshay K via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 20 12:55:30 PDT 2026


https://github.com/kumarak created https://github.com/llvm/llvm-project/pull/210799


Parsing a declaration of an llvm_any_ty intrinsic with a token overload type crashes opt at parse time:

```
declare token @llvm.ssa.copy.token(token)
Unhandled type
UNREACHABLE executed at llvm/lib/IR/Intrinsics.cpp:133!
```
The unconstrained Any matcher accepts a token, and Intrinsic::remangleIntrinsicFunction (run from `LLParser::validateEndOfModule`, before the Verifier) then fails to mangle it into the intrinsic name.

Token and label types have no name mangling, so no overloaded intrinsic can be instantiated on them. Reject them in matchIntrinsicType's Overloaded case, turning the crash into the same clean "expected ..., but got token" broken-module error that constrained overloads already produce. 

Fixed llvm_token_ty operands (gc.result, coro.*, ...) are unaffected.

Fixes #210641.

>From 0f1c645b6afb55c7bb1c55495d486e1083cc43fc Mon Sep 17 00:00:00 2001
From: AkshayK <iit.akshay at gmail.com>
Date: Mon, 20 Jul 2026 14:08:06 -0400
Subject: [PATCH] [IR] Reject token and label overload types in intrinsic
 signature matching

Declaring an llvm_any_ty intrinsic with a token overload type, e.g.

  declare token @llvm.ssa.copy.token(token)

crashed opt at parse time: the unconstrained Any matcher accepted token,
and remangleIntrinsicFunction (run before the Verifier) then hit
llvm_unreachable("Unhandled type") mangling it into the intrinsic name.

Token and label have no name mangling, so no overloaded intrinsic can
be instantiated on them. Reject them in matchIntrinsicType's Overloaded
case, degrading the crash into the same broken-module diagnostic that
constrained overloads already produce. Fixed llvm_token_ty operands
(gc.result, coro.*, ...) are unaffected.

Fixes #210641.
---
 llvm/lib/IR/Intrinsics.cpp                          |  5 +++++
 .../Assembler/intrinsic-token-overload-invalid.ll   | 13 +++++++++++++
 2 files changed, 18 insertions(+)
 create mode 100644 llvm/test/Assembler/intrinsic-token-overload-invalid.ll

diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index 266af8e06a230..ede7a73c49ed2 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -1098,6 +1098,11 @@ matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> &Infos,
            "Table consistency error");
     OverloadTys.push_back(Ty);
 
+    // Token and label types have no mangling (see getMangledTypeStr), so
+    // they cannot be overload types; reject them with a signature error.
+    if (Ty->isTokenTy() || Ty->isLabelTy())
+      return PrintMsg(false, "any manglable type", OIdx);
+
     IITDescriptor::AnyKindVectorConstraint VC;
     IITDescriptor::AnyKindElementConstraint EC;
     std::tie(VC, EC) = D.getOverloadConstraints();
diff --git a/llvm/test/Assembler/intrinsic-token-overload-invalid.ll b/llvm/test/Assembler/intrinsic-token-overload-invalid.ll
new file mode 100644
index 0000000000000..84d0882b50085
--- /dev/null
+++ b/llvm/test/Assembler/intrinsic-token-overload-invalid.ll
@@ -0,0 +1,13 @@
+; RUN: not opt -disable-output %s 2>&1 | FileCheck %s
+
+; Token overloads of llvm_any_ty intrinsics used to crash parse-time intrinsic
+; remangling with "Unhandled type" in the name mangler (#210641). They must be
+; rejected with a normal signature error, like constrained overloads are.
+
+; CHECK: intrinsic return type (overload type 0) expected any manglable type, but got token
+declare token @llvm.ssa.copy.ttoken(token)
+
+; CHECK: intrinsic argument 0 type (overload type 0) expected any manglable type, but got token
+declare i1 @llvm.is.constant.ttoken(token)
+
+; CHECK: error: input module is broken!



More information about the llvm-commits mailing list