r314328 - [OpenMP] Fix memory leak when translating arguments
Jonas Hahnfeld via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 27 11:12:31 PDT 2017
Author: hahnfeld
Date: Wed Sep 27 11:12:31 2017
New Revision: 314328
URL: http://llvm.org/viewvc/llvm-project?rev=314328&view=rev
Log:
[OpenMP] Fix memory leak when translating arguments
Parsing the argument after -Xopenmp-target allocates memory that needs
to be freed. Associate it with the final DerivedArgList after we know
which one will be used.
Differential Revision: https://reviews.llvm.org/D38257
Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/Compilation.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/test/Driver/openmp-offload-gpu.c
Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=314328&r1=314327&r2=314328&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Wed Sep 27 11:12:31 2017
@@ -249,9 +249,10 @@ public:
///
/// \param DeviceOffloadKind - The device offload kind used for the
/// translation.
- virtual llvm::opt::DerivedArgList *
- TranslateOpenMPTargetArgs(const llvm::opt::DerivedArgList &Args,
- Action::OffloadKind DeviceOffloadKind) const;
+ virtual llvm::opt::DerivedArgList *TranslateOpenMPTargetArgs(
+ const llvm::opt::DerivedArgList &Args,
+ Action::OffloadKind DeviceOffloadKind,
+ SmallVector<llvm::opt::Arg *, 4> &AllocatedArgs) const;
/// Choose a tool to use to handle the action \p JA.
///
Modified: cfe/trunk/lib/Driver/Compilation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Compilation.cpp?rev=314328&r1=314327&r2=314328&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Compilation.cpp (original)
+++ cfe/trunk/lib/Driver/Compilation.cpp Wed Sep 27 11:12:31 2017
@@ -51,9 +51,10 @@ Compilation::getArgsForToolChain(const T
DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
if (!Entry) {
+ SmallVector<Arg *, 4> AllocatedArgs;
// Translate OpenMP toolchain arguments provided via the -Xopenmp-target flags.
- DerivedArgList *OpenMPArgs = TC->TranslateOpenMPTargetArgs(*TranslatedArgs,
- DeviceOffloadKind);
+ DerivedArgList *OpenMPArgs = TC->TranslateOpenMPTargetArgs(
+ *TranslatedArgs, DeviceOffloadKind, AllocatedArgs);
if (!OpenMPArgs) {
Entry = TC->TranslateArgs(*TranslatedArgs, BoundArch, DeviceOffloadKind);
} else {
@@ -63,6 +64,11 @@ Compilation::getArgsForToolChain(const T
if (!Entry)
Entry = TranslatedArgs;
+
+ // Add allocated arguments to the final DAL.
+ for (auto ArgPtr : AllocatedArgs) {
+ Entry->AddSynthesizedArg(ArgPtr);
+ }
}
return *Entry;
Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=314328&r1=314327&r2=314328&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Wed Sep 27 11:12:31 2017
@@ -800,9 +800,10 @@ ToolChain::computeMSVCVersion(const Driv
return VersionTuple();
}
-llvm::opt::DerivedArgList *
-ToolChain::TranslateOpenMPTargetArgs(const llvm::opt::DerivedArgList &Args,
- Action::OffloadKind DeviceOffloadKind) const {
+llvm::opt::DerivedArgList *ToolChain::TranslateOpenMPTargetArgs(
+ const llvm::opt::DerivedArgList &Args,
+ Action::OffloadKind DeviceOffloadKind,
+ SmallVector<llvm::opt::Arg *, 4> &AllocatedArgs) const {
if (DeviceOffloadKind == Action::OFK_OpenMP) {
DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
const OptTable &Opts = getDriver().getOpts();
@@ -854,6 +855,7 @@ ToolChain::TranslateOpenMPTargetArgs(con
}
XOpenMPTargetArg->setBaseArg(A);
A = XOpenMPTargetArg.release();
+ AllocatedArgs.push_back(A);
DAL->append(A);
NewArgAdded = true;
}
Modified: cfe/trunk/test/Driver/openmp-offload-gpu.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/openmp-offload-gpu.c?rev=314328&r1=314327&r2=314328&view=diff
==============================================================================
--- cfe/trunk/test/Driver/openmp-offload-gpu.c (original)
+++ cfe/trunk/test/Driver/openmp-offload-gpu.c Wed Sep 27 11:12:31 2017
@@ -2,9 +2,6 @@
/// Perform several driver tests for OpenMP offloading
///
-// Until this test is stabilized on all local configurations.
-// UNSUPPORTED: linux
-
// REQUIRES: clang-driver
// REQUIRES: x86-registered-target
// REQUIRES: powerpc-registered-target
More information about the cfe-commits
mailing list