[clang] [clang][Driver] Use shared_ptr in the Compilation class (PR #116406)

David Truby via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 2 06:13:23 PST 2024


================
@@ -63,41 +56,39 @@ Compilation::getArgsForToolChain(const ToolChain *TC, StringRef BoundArch,
   if (!TC)
     TC = &DefaultToolChain;
 
-  DerivedArgList *&Entry = TCArgs[{TC, BoundArch, DeviceOffloadKind}];
+  std::shared_ptr<DerivedArgList> &Entry =
+      TCArgs[{TC, BoundArch, DeviceOffloadKind}];
   if (!Entry) {
     SmallVector<Arg *, 4> AllocatedArgs;
-    DerivedArgList *OpenMPArgs = nullptr;
+    std::shared_ptr<DerivedArgList> OpenMPArgs;
     // Translate OpenMP toolchain arguments provided via the -Xopenmp-target flags.
     if (DeviceOffloadKind == Action::OFK_OpenMP) {
       const ToolChain *HostTC = getSingleOffloadToolChain<Action::OFK_Host>();
       bool SameTripleAsHost = (TC->getTriple() == HostTC->getTriple());
-      OpenMPArgs = TC->TranslateOpenMPTargetArgs(
-          *TranslatedArgs, SameTripleAsHost, AllocatedArgs);
+      OpenMPArgs.reset(TC->TranslateOpenMPTargetArgs(
+          *TranslatedArgs, SameTripleAsHost, AllocatedArgs));
     }
 
-    DerivedArgList *NewDAL = nullptr;
+    std::shared_ptr<DerivedArgList> NewDAL;
----------------
DavidTruby wrote:

```suggestion
    std::unique_ptr<DerivedArgList> NewDAL;
```

https://github.com/llvm/llvm-project/pull/116406


More information about the cfe-commits mailing list