Author: Timm Baeder
Date: 2026-05-26T11:44:04+02:00
New Revision: b2634fc4f8b1b1702a970812d534d3a888788b3e

URL: 
https://github.com/llvm/llvm-project/commit/b2634fc4f8b1b1702a970812d534d3a888788b3e
DIFF: 
https://github.com/llvm/llvm-project/commit/b2634fc4f8b1b1702a970812d534d3a888788b3e.diff

LOG: [clang][bytecode] Fix a crash in __builtin_subcb (#199400)

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

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/InterpBuiltin.cpp
    clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index ffdbc2346b5ca..8a53ae0937782 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 6e4b894d63db3..214cb06a27d99 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -2065,3 +2065,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