[llvm] r254696 - Move a call to getGlobalContext out of lib/LTO.

Steven Wu via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 7 09:50:17 PST 2015


Hi Rafael

I should have notice this earlier but this commit breaks the case that LTOCodeGenerator owns a module that is created in the context that it also owns. Moving the context out to the parent class change the destruction order for OwnedModule and OwnedContext. In the original case, OwnedModule gets destructed then the OwnedContext, but now the order is reversed. If the OwnedModule is created in the OwnedContext, it causes segfault when destructing OwnedModule.
I do like this cleanup but I can't find a elegant way to fix this as well. Let me know if you have any suggestions.

Thanks

Steven

> On Dec 3, 2015, at 6:42 PM, Rafael Espindola via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Author: rafael
> Date: Thu Dec  3 20:42:28 2015
> New Revision: 254696
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=254696&view=rev
> Log:
> Move a call to getGlobalContext out of lib/LTO.
> 
> Modified:
>    llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
>    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
>    llvm/trunk/tools/llvm-lto/llvm-lto.cpp
>    llvm/trunk/tools/lto/lto.cpp
> 
> Modified: llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h?rev=254696&r1=254695&r2=254696&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h (original)
> +++ llvm/trunk/include/llvm/LTO/LTOCodeGenerator.h Thu Dec  3 20:42:28 2015
> @@ -62,8 +62,7 @@ namespace llvm {
> struct LTOCodeGenerator {
>   static const char *getVersionString();
> 
> -  LTOCodeGenerator();
> -  LTOCodeGenerator(std::unique_ptr<LLVMContext> Context);
> +  LTOCodeGenerator(LLVMContext &Context);
>   ~LTOCodeGenerator();
> 
>   /// Merge given module.  Return true on success.
> @@ -168,7 +167,6 @@ private:
> 
>   typedef StringMap<uint8_t> StringSet;
> 
> -  std::unique_ptr<LLVMContext> OwnedContext;
>   LLVMContext &Context;
>   std::unique_ptr<Module> MergedModule;
>   std::unique_ptr<Linker> IRLinker;
> 
> Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=254696&r1=254695&r2=254696&view=diff
> ==============================================================================
> --- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
> +++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Thu Dec  3 20:42:28 2015
> @@ -64,19 +64,12 @@ const char* LTOCodeGenerator::getVersion
> #endif
> }
> 
> -LTOCodeGenerator::LTOCodeGenerator()
> -    : Context(getGlobalContext()),
> +LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
> +    : Context(Context),
>       MergedModule(new Module("ld-temp.o", Context)),
>       IRLinker(new Linker(*MergedModule)) {
>   initializeLTOPasses();
> }
> -
> -LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
> -    : OwnedContext(std::move(Context)), Context(*OwnedContext),
> -      MergedModule(new Module("ld-temp.o", *OwnedContext)),
> -      IRLinker(new Linker(*MergedModule)) {
> -  initializeLTOPasses();
> -}
> 
> LTOCodeGenerator::~LTOCodeGenerator() {}
> 
> 
> Modified: llvm/trunk/tools/llvm-lto/llvm-lto.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto/llvm-lto.cpp?rev=254696&r1=254695&r2=254696&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-lto/llvm-lto.cpp (original)
> +++ llvm/trunk/tools/llvm-lto/llvm-lto.cpp Thu Dec  3 20:42:28 2015
> @@ -257,7 +257,7 @@ int main(int argc, char **argv) {
> 
>   unsigned BaseArg = 0;
> 
> -  LTOCodeGenerator CodeGen;
> +  LTOCodeGenerator CodeGen(getGlobalContext());
> 
>   if (UseDiagnosticHandler)
>     CodeGen.setDiagnosticHandler(handleDiagnostics, nullptr);
> 
> Modified: llvm/trunk/tools/lto/lto.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/lto.cpp?rev=254696&r1=254695&r2=254696&view=diff
> ==============================================================================
> --- llvm/trunk/tools/lto/lto.cpp (original)
> +++ llvm/trunk/tools/lto/lto.cpp Thu Dec  3 20:42:28 2015
> @@ -95,13 +95,14 @@ static void handleLibLTODiagnostic(lto_c
> // libLTO API semantics, which require that the code generator owns the object
> // file.
> struct LibLTOCodeGenerator : LTOCodeGenerator {
> -  LibLTOCodeGenerator() {
> +  LibLTOCodeGenerator() : LTOCodeGenerator(getGlobalContext()) {
>     setDiagnosticHandler(handleLibLTODiagnostic, nullptr); }
>   LibLTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
> -      : LTOCodeGenerator(std::move(Context)) {
> +      : LTOCodeGenerator(*Context), OwnedContext(std::move(Context)) {
>     setDiagnosticHandler(handleLibLTODiagnostic, nullptr); }
> 
>   std::unique_ptr<MemoryBuffer> NativeObjectFile;
> +  std::unique_ptr<LLVMContext> OwnedContext;
> };
> 
> }
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list