https://github.com/mugiwaraluffy56 updated 
https://github.com/llvm/llvm-project/pull/178936

>From b79958f08dbbed3e15015ef9f410a6d40d1ff96f Mon Sep 17 00:00:00 2001
From: mugiwaraluffy56 <[email protected]>
Date: Fri, 30 Jan 2026 23:59:32 +0530
Subject: [PATCH] [clang][bytecode] Fix crash on __builtin_infer_alloc_token
 with non-primitive arguments

The discard loop assumed all arguments would have primitive types,
but struct/class arguments are passed as pointers on the stack.
Check if the type is classifiable before discarding.

Fixes #178892
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 2 +-
 clang/test/SemaCXX/alloc-token.cpp       | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index fb7c51608f85b..2891fb8217258 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1399,7 +1399,7 @@ static bool interp__builtin_infer_alloc_token(InterpState 
&S, CodePtr OpPC,
 
   // We do not read any of the arguments; discard them.
   for (int I = Call->getNumArgs() - 1; I >= 0; --I)
-    discard(S.Stk, *S.getContext().classify(Call->getArg(I)));
+    discard(S.Stk, S.getContext().classify(Call->getArg(I)).value_or(PT_Ptr));
 
   // Note: Type inference from a surrounding cast is not supported in
   // constexpr evaluation.
diff --git a/clang/test/SemaCXX/alloc-token.cpp 
b/clang/test/SemaCXX/alloc-token.cpp
index 2a11e3366d5fb..aae25720d4329 100644
--- a/clang/test/SemaCXX/alloc-token.cpp
+++ b/clang/test/SemaCXX/alloc-token.cpp
@@ -79,4 +79,9 @@ void negative_tests() {
   negative_template_test<void>(); // expected-note {{in instantiation of 
function template specialization 'negative_template_test<void>' requested here}}
   constexpr auto inference_fail = __builtin_infer_alloc_token(123); // 
expected-error {{must be initialized by a constant expression}} \
                                                                     // 
expected-note {{could not infer allocation type for 
__builtin_infer_alloc_token}}
+
+  // PR178892: Ensure struct arguments don't crash the bytecode interpreter.
+  struct S {};
+  constexpr auto struct_arg = __builtin_infer_alloc_token(S()); // 
expected-error {{must be initialized by a constant expression}} \
+                                                                // 
expected-note {{could not infer allocation type for 
__builtin_infer_alloc_token}}
 }

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to