https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/199400

Don't try to initialize pointers that can't be initialized

>From c1c9c193c9cda2ffc33ecfa7295d7311772756bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Sun, 24 May 2026 08:25:38 +0200
Subject: [PATCH] [clang][bytecode] Fix a crash in __builtin_subcb

Don't try to initialize pointers that can't be initialized
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp      | 3 ++-
 clang/test/AST/ByteCode/builtin-functions.cpp | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 3e9ce902427eb..863a25f519e9b 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1019,7 +1019,8 @@ static bool interp__builtin_carryop(InterpState &S, 
CodePtr OpPC,
   QualType CarryOutType = Call->getArg(3)->getType()->getPointeeType();
   PrimType CarryOutT = *S.getContext().classify(CarryOutType);
   assignIntegral(S, CarryOutPtr, CarryOutT, CarryOut);
-  CarryOutPtr.initialize();
+  if (CarryOutPtr.canBeInitialized())
+    CarryOutPtr.initialize();
 
   assert(Call->getType() == Call->getArg(0)->getType());
   pushInteger(S, Result, Call->getType());
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 97fa1760ee167..7b19c3388e7cd 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -2048,3 +2048,10 @@ namespace WcslenInvalidArg {
   static_assert(__builtin_wcslen(L"x") == 1);
 
 }
+
+namespace SubCb {
+  constexpr unsigned char subcb(unsigned char lhs, unsigned char rhs, unsigned 
char carry) {
+    return __builtin_subcb(lhs, rhs, carry, &rhs);
+  }
+  static_assert(subcb(10, 15, 1) == 250);
+}

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

Reply via email to