[clang][bytecode] Fix a crash in __builtin_subcb#199400
Open
tbaederr wants to merge 1 commit into
Open
Conversation
Don't try to initialize pointers that can't be initialized
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesDon't try to initialize pointers that can't be initialized Full diff: https://github.com/llvm/llvm-project/pull/199400.diff 2 Files Affected:
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);
+}
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Don't try to initialize pointers that can't be initialized