[clang] [NFC][Sema][OpenMP] Fix free-nonheap-object warning (PR #112942)
Jinsong Ji via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 19 06:27:09 PDT 2024
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/112942
>From a01e0d660a1631c7b9a78d1a48dc6dc2080cc19a Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Fri, 18 Oct 2024 19:29:43 +0200
Subject: [PATCH] [NFC][Sema][OpenMP] Fix free-nonheap-object warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This is one of the many PRs to fix errors with LLVM_ENABLE_WERROR=on. Built by GCC 11.
Fix warning
In destructor ‘llvm::APInt::~APInt()’,
inlined from ‘llvm::APInt::~APInt()’ at llvm-project/llvm/include/llvm/ADT/APInt.h:190:3,
inlined from ‘llvm::APSInt::~APSInt()’ at llvm-project/llvm/include/llvm/ADT/APSInt.h:23:21,
inlined from ‘bool checkOMPArraySectionConstantForReduction(clang::ASTContext&, const clang::ArraySectionExpr*, bool&, llvm::SmallVectorImpl<llvm::APSInt>&)’ at llvm-project/clang/lib/Sema/SemaOpenMP.cpp:18357:45,
inlined from ‘bool actOnOMPReductionKindClause(clang::Sema&, {anonymous}::DSAStackTy*, clang::OpenMPClauseKind, llvm::ArrayRef<clang::Expr*>, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation, clang::CXXScopeSpec&, const clang::DeclarationNameInfo&, llvm::ArrayRef<clang::Expr*>, {anonymous}::ReductionData&)’ at llvm-project/clang/lib/Sema/SemaOpenMP.cpp:18715:68:
llvm-project/llvm/include/llvm/ADT/APInt.h:192:18: error: ‘void operator delete [](void*)’ called on a pointer to an unallocated object ‘1’ [-Werror=free-nonheap-object]
192 | delete[] U.pVal;
| ^~~~
---
clang/lib/Sema/SemaOpenMP.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 0232745b3c19e5..fa81fc42c0ee53 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -18335,7 +18335,8 @@ static bool checkOMPArraySectionConstantForReduction(
return false;
// This is an array subscript which has implicit length 1!
- ArraySizes.push_back(llvm::APSInt::get(1));
+ llvm::APSInt ConstantOne = llvm::APSInt::get(1);
+ ArraySizes.push_back(ConstantOne);
} else {
Expr::EvalResult Result;
if (!Length->EvaluateAsInt(Result, Context))
@@ -18354,7 +18355,8 @@ static bool checkOMPArraySectionConstantForReduction(
if (!SingleElement) {
while (const auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) {
// Has implicit length 1!
- ArraySizes.push_back(llvm::APSInt::get(1));
+ llvm::APSInt ConstantOne = llvm::APSInt::get(1);
+ ArraySizes.push_back(ConstantOne);
Base = TempASE->getBase()->IgnoreParenImpCasts();
}
}
More information about the cfe-commits
mailing list