diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-04-23 08:00:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-23 08:00:57 +0200 |
commit | 1a78ef9a9eddd73de7932f5c33a7a7ad7e8b1806 (patch) | |
tree | 2d8f0df755bb488c8ee7039842d3de0e8a99eec7 /clang/lib/AST/ByteCode/InterpBuiltin.cpp | |
parent | 5080a0251fe3352d26560075a9b3b8c9acb13d23 (diff) | |
download | llvm-1a78ef9a9eddd73de7932f5c33a7a7ad7e8b1806.zip llvm-1a78ef9a9eddd73de7932f5c33a7a7ad7e8b1806.tar.gz llvm-1a78ef9a9eddd73de7932f5c33a7a7ad7e8b1806.tar.bz2 |
[clang][bytecode] Allow casts from void* only in std::allocator calls (#136714)
Otherwise, add the missing diagnostic.
Diffstat (limited to 'clang/lib/AST/ByteCode/InterpBuiltin.cpp')
-rw-r--r-- | clang/lib/AST/ByteCode/InterpBuiltin.cpp | 57 |
1 files changed, 2 insertions, 55 deletions
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 523e471..d8b320f 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -1526,34 +1526,7 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC, // A call to __operator_new is only valid within std::allocate<>::allocate. // Walk up the call stack to find the appropriate caller and get the // element type from it. - QualType ElemType; - const CallExpr *NewCall = nullptr; - - for (const InterpFrame *F = Frame; F; F = F->Caller) { - const Function *Func = F->getFunction(); - if (!Func) - continue; - const auto *MD = dyn_cast_if_present<CXXMethodDecl>(Func->getDecl()); - if (!MD) - continue; - const IdentifierInfo *FnII = MD->getIdentifier(); - if (!FnII || !FnII->isStr("allocate")) - continue; - - const auto *CTSD = - dyn_cast<ClassTemplateSpecializationDecl>(MD->getParent()); - if (!CTSD) - continue; - - const IdentifierInfo *ClassII = CTSD->getIdentifier(); - const TemplateArgumentList &TAL = CTSD->getTemplateArgs(); - if (CTSD->isInStdNamespace() && ClassII && ClassII->isStr("allocator") && - TAL.size() >= 1 && TAL[0].getKind() == TemplateArgument::Type) { - ElemType = TAL[0].getAsType(); - NewCall = cast<CallExpr>(F->Caller->getExpr(F->getRetPC())); - break; - } - } + auto [NewCall, ElemType] = S.getStdAllocatorCaller("allocate"); if (ElemType.isNull()) { S.FFDiag(Call, S.getLangOpts().CPlusPlus20 @@ -1655,33 +1628,7 @@ static bool interp__builtin_operator_delete(InterpState &S, CodePtr OpPC, return false; // This is permitted only within a call to std::allocator<T>::deallocate. - bool DeallocateFrameFound = false; - for (const InterpFrame *F = Frame; F; F = F->Caller) { - const Function *Func = F->getFunction(); - if (!Func) - continue; - const auto *MD = dyn_cast_if_present<CXXMethodDecl>(Func->getDecl()); - if (!MD) - continue; - const IdentifierInfo *FnII = MD->getIdentifier(); - if (!FnII || !FnII->isStr("deallocate")) - continue; - - const auto *CTSD = - dyn_cast<ClassTemplateSpecializationDecl>(MD->getParent()); - if (!CTSD) - continue; - - const IdentifierInfo *ClassII = CTSD->getIdentifier(); - const TemplateArgumentList &TAL = CTSD->getTemplateArgs(); - if (CTSD->isInStdNamespace() && ClassII && ClassII->isStr("allocator") && - TAL.size() >= 1 && TAL[0].getKind() == TemplateArgument::Type) { - DeallocateFrameFound = true; - break; - } - } - - if (!DeallocateFrameFound) { + if (!S.getStdAllocatorCaller("deallocate")) { S.FFDiag(Call); return true; } |