[PATCH] D142699: [AsmParser] Avoid instantiating LLVMContext if not needed. NFC

Yevgeny Rouban via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 21 01:55:47 PDT 2023


yrouban updated this revision to Diff 506875.
yrouban added a comment.

The deleted copy constructor LLVMContext(LLVMContext &) got its
parameter changed to const to allow the latest clang compiler to
instantiatiate template std::optional<LLVMContext>.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D142699/new/

https://reviews.llvm.org/D142699

Files:
  llvm/include/llvm/IR/LLVMContext.h
  llvm/lib/AsmParser/Parser.cpp


Index: llvm/lib/AsmParser/Parser.cpp
===================================================================
--- llvm/lib/AsmParser/Parser.cpp
+++ llvm/lib/AsmParser/Parser.cpp
@@ -28,9 +28,9 @@
   std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(F);
   SM.AddNewSourceBuffer(std::move(Buf), SMLoc());
 
-  LLVMContext Context;
+  std::optional<LLVMContext> OptContext;
   return LLParser(F.getBuffer(), SM, Err, M, Index,
-                  M ? M->getContext() : Context, Slots)
+                  M ? M->getContext() : OptContext.emplace(), Slots)
       .Run(UpgradeDebugInfo, DataLayoutCallback);
 }
 
Index: llvm/include/llvm/IR/LLVMContext.h
===================================================================
--- llvm/include/llvm/IR/LLVMContext.h
+++ llvm/include/llvm/IR/LLVMContext.h
@@ -68,7 +68,7 @@
 public:
   LLVMContextImpl *const pImpl;
   LLVMContext();
-  LLVMContext(LLVMContext &) = delete;
+  LLVMContext(const LLVMContext &) = delete;
   LLVMContext &operator=(const LLVMContext &) = delete;
   ~LLVMContext();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142699.506875.patch
Type: text/x-patch
Size: 1046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230321/5d7d395c/attachment.bin>


More information about the llvm-commits mailing list