[clang] [Clang][Sema] Fix __builtin_infer_alloc_token() return type (PR #168773)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 19 12:56:16 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Marco Elver (melver)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/168773.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaChecking.cpp (+1-1)
- (modified) clang/test/SemaCXX/alloc-token.cpp (+2)
``````````diff
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"
``````````
</details>
https://github.com/llvm/llvm-project/pull/168773
More information about the cfe-commits
mailing list