aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/InterpBuiltin.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-06-16 08:28:52 +0200
committerGitHub <noreply@github.com>2025-06-16 08:28:52 +0200
commit4f9e6bad8438f4440bfd68be2f0ebdca0d588d47 (patch)
treeada4e90e1396c37acf3fed1f6b752c30bc578962 /clang/lib/AST/ByteCode/InterpBuiltin.cpp
parent4ea616d072d126a31149174ca2efdbdace9ce568 (diff)
downloadllvm-4f9e6bad8438f4440bfd68be2f0ebdca0d588d47.zip
llvm-4f9e6bad8438f4440bfd68be2f0ebdca0d588d47.tar.gz
llvm-4f9e6bad8438f4440bfd68be2f0ebdca0d588d47.tar.bz2
[clang][bytecode] Fix calling operator new with nothrow/align parameter (#144271)
Discard all the parameters we don't care about.
Diffstat (limited to 'clang/lib/AST/ByteCode/InterpBuiltin.cpp')
-rw-r--r--clang/lib/AST/ByteCode/InterpBuiltin.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 5fc5034..d01e3d0 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1423,7 +1423,6 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC,
// Walk up the call stack to find the appropriate caller and get the
// element type from it.
auto [NewCall, ElemType] = S.getStdAllocatorCaller("allocate");
- APSInt Bytes = popToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(0)));
if (ElemType.isNull()) {
S.FFDiag(Call, S.getLangOpts().CPlusPlus20
@@ -1439,6 +1438,25 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC,
return false;
}
+ // We only care about the first parameter (the size), so discard all the
+ // others.
+ {
+ unsigned NumArgs = Call->getNumArgs();
+ assert(NumArgs >= 1);
+
+ // The std::nothrow_t arg never gets put on the stack.
+ if (Call->getArg(NumArgs - 1)->getType()->isNothrowT())
+ --NumArgs;
+ auto Args = llvm::ArrayRef(Call->getArgs(), Call->getNumArgs());
+ // First arg is needed.
+ Args = Args.drop_front();
+
+ // Discard the rest.
+ for (const Expr *Arg : Args)
+ discard(S.Stk, *S.getContext().classify(Arg));
+ }
+
+ APSInt Bytes = popToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(0)));
CharUnits ElemSize = S.getASTContext().getTypeSizeInChars(ElemType);
assert(!ElemSize.isZero());
// Divide the number of bytes by sizeof(ElemType), so we get the number of