[clang] [Clang][Sema] Fix __builtin_infer_alloc_token() return type (PR #168773)
Marco Elver via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 19 12:55:48 PST 2025
https://github.com/melver created https://github.com/llvm/llvm-project/pull/168773
Using the builtin failed on 32-bit architectures:
| clang/lib/AST/ExprConstant.cpp:14299: [..]: Assertion `I.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && "Invalid evaluation result."' failed.
The return type is meant to be size_t. Fix it.
>From 406428ff864522c8200710956c81c74a0055259a Mon Sep 17 00:00:00 2001
From: Marco Elver <elver at google.com>
Date: Wed, 19 Nov 2025 21:51:52 +0100
Subject: [PATCH] [Clang][Sema] Fix __builtin_infer_alloc_token() return type
Using the builtin failed on 32-bit architectures:
| clang/lib/AST/ExprConstant.cpp:14299: [..]: Assertion `I.getBitWidth() == Info.Ctx.getIntWidth(E->getType()) && "Invalid evaluation result."' failed.
The return type is meant to be size_t. Fix it.
---
clang/lib/Sema/SemaChecking.cpp | 2 +-
clang/test/SemaCXX/alloc-token.cpp | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index cf407f7279c46..3e1edc4548034 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1512,7 +1512,7 @@ static bool checkBuiltinInferAllocToken(Sema &S, CallExpr *TheCall) {
return S.Diag(Arg->getBeginLoc(), diag::err_param_with_void_type);
}
- TheCall->setType(S.Context.UnsignedLongLongTy);
+ TheCall->setType(S.Context.getSizeType());
return false;
}
diff --git a/clang/test/SemaCXX/alloc-token.cpp b/clang/test/SemaCXX/alloc-token.cpp
index 518ad7d94eb96..2a11e3366d5fb 100644
--- a/clang/test/SemaCXX/alloc-token.cpp
+++ b/clang/test/SemaCXX/alloc-token.cpp
@@ -3,6 +3,8 @@
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -falloc-token-mode=typehash -DMODE_TYPEHASH
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -falloc-token-max=2 -DTOKEN_MAX=2
+// RUN: %clang_cc1 -triple arm-linux-androideabi -std=c++23 -fsyntax-only -verify %s -falloc-token-max=2 -DTOKEN_MAX=2
+// RUN: %clang_cc1 -triple arm-linux-androideabi -std=c++23 -fsyntax-only -verify %s -falloc-token-max=2 -DTOKEN_MAX=2 -fexperimental-new-constant-interpreter
#if !__has_builtin(__builtin_infer_alloc_token)
#error "missing __builtin_infer_alloc_token"
More information about the cfe-commits
mailing list