You may want to try adding this code (copy/pasted from llc.cpp): // Initialize targets first, so that --version shows registered targets. InitializeAllTargets(); InitializeAllTargetMCs(); InitializeAllAsmPrinters(); InitializeAllAsmParsers(); // Initialize codegen and IR passes used by llc so that the -print-after, // -print-before, and -stop-after options work. PassRegistry *Registry = PassRegistry::getPassRegistry(); initializeCore(*Registry); initializeCodeGen(*Registry); initializeLoopStrengthReducePass(*Registry); initializeLowerIntrinsicsPass(*Registry); initializeUnreachableBlockElimPass(*Registry); -- Mehdi> On Mar 24, 2016, at 9:59 AM, Lorenzo Laneve <lore97drk at icloud.com> wrote: > > Update: > Sorry my bad. I built llvm and tried it with debugging version. > It was an assertion (IR/LegacyPassManager.cpp:764) saying that it expects all immutable passes to be initialized. > > On Mar 24, 2016, at 2:00 AM, Lorenzo Laneve <lore97drk at icloud.com <mailto:lore97drk at icloud.com>> wrote: > >> I’m using LLVM 3.8.0, and no, it’s the precompiled version >> That’s why it doesn’t give me enough info for debug >> >>> On 24 Mar 2016, at 1:53 AM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote: >>> >>> This code path is not likely to crash usually. Did you build LLVM yourself? Which version are you using and can you reduce the test case to be "minimal" so that someone can reproduce? >>> (for instance you don't need a module to create a pass manager) >>> >>> -- >>> Mehdi >>> >>>> On Mar 23, 2016, at 5:50 PM, Lorenzo Laneve <lore97drk at icloud.com <mailto:lore97drk at icloud.com>> wrote: >>>> >>>> Sorry, that's a pure crash I think, assertions are not triggered. >>>> Xcode doesn’t map those 2 functions to line numbers because they’re in precompiled libraries >>>> >>>> >>>> On Mar 24, 2016, at 1:44 AM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote: >>>> >>>>> >>>>>> On Mar 23, 2016, at 5:41 PM, Lorenzo Laneve <lore97drk at icloud.com <mailto:lore97drk at icloud.com>> wrote: >>>>>> >>>>>> The stack trace: >>>>>> llvm::PMTopLevelManager::addImmutablePass(llvm::ImmutablePass*) >>>>>> llvm::PMTopLevelManager::schedulePass(llvm::Pass*) >>>>>> moduleToObjectFile(llvm::Module*,std::string&,llvm::LLVMContext&) >>>>> >>>>> >>>>> Without mapping to line numbers this is not very helpful: moduleToObjectFile never calls schedulePass. >>>>> >>>>> Also you didn't answer my previous question about the crash. >>>>> >>>>> >>>>>> Sometimes it doesn't crash because TargetRegistry::lookupTarget() returns an error which says it doesn't support the current target >>>>> >>>>> Do you mean that running it multiple time does not always produce the same behavior in the call to lookupTarget? >>>>> That's unexpected and I'd be worried about my program. >>>>> >>>>> -- >>>>> Mehdi >>>>> >>>>> >>>>> >>>>>> >>>>>> On Mar 24, 2016, at 1:14 AM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote: >>>>>> >>>>>>> Assuming you are talking about this line: >>>>>>> >>>>>>> passmanager.add(tliwp); >>>>>>> >>>>>>> I don't see anything obviously wrong. >>>>>>> Are you hitting an assertion or a pure crash? (if LLVM not built with assertions, please rebuild). >>>>>>> What does your debugger gives you as a stracktrace? >>>>>>> >>>>>>> -- >>>>>>> Mehdi >>>>>>> >>>>>>> >>>>>>> >>>>>>>> On Mar 23, 2016, at 3:44 PM, Lorenzo Laneve via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote: >>>>>>>> >>>>>>>> Sorry in advance for the stupid question, i still don’t understand some concepts like passes. >>>>>>>> I took a piece of code from llc, and I used it to write a function that creates an object (or assembly) file from an IR module. >>>>>>>> It compiles without any problems. But program crashes when it reaches add() method of the pass manager. >>>>>>>> Can you help me figuring out what’s the problem please? here is my function >>>>>>>> >>>>>>>> >>>>>>>> int moduleToObjectFile(llvm::Module *module, std::string &srcname, llvm::LLVMContext &Context) { >>>>>>>> SMDiagnostic error; >>>>>>>> Triple moduletriple = Triple(module->getTargetTriple()); >>>>>>>> >>>>>>>> if (moduletriple.getTriple().empty()) >>>>>>>> moduletriple.setTriple(sys::getDefaultTargetTriple()); >>>>>>>> >>>>>>>> std::string lookuperror; >>>>>>>> const Target *moduletarget = TargetRegistry::lookupTarget(MArch, moduletriple, lookuperror); >>>>>>>> >>>>>>>> if (!moduletarget) { >>>>>>>> errs() << lookuperror; >>>>>>>> return 1; >>>>>>>> } >>>>>>>> >>>>>>>> std::string cpuname = getCPUStr(), >>>>>>>> ftrlist = getFeaturesStr(); >>>>>>>> >>>>>>>> CodeGenOpt::Level OLvl = CodeGenOpt::Default; >>>>>>>> switch ('2') { >>>>>>>> default: >>>>>>>> errs() << "invalid optimization level.\n"; >>>>>>>> return 1; >>>>>>>> case ' ': break; >>>>>>>> case '0': OLvl = CodeGenOpt::None; break; >>>>>>>> case '1': OLvl = CodeGenOpt::Less; break; >>>>>>>> case '2': OLvl = CodeGenOpt::Default; break; >>>>>>>> case '3': OLvl = CodeGenOpt::Aggressive; break; >>>>>>>> } >>>>>>>> >>>>>>>> TargetOptions targetopts = InitTargetOptionsFromCodeGenFlags(); >>>>>>>> >>>>>>>> std::unique_ptr<TargetMachine> tmachine(moduletarget->createTargetMachine(moduletriple.getTriple(), cpuname, ftrlist, targetopts, Reloc::Default, CodeModel::Default, OLvl)); >>>>>>>> >>>>>>>> assert(tmachine && "Could not allocate target machine!"); >>>>>>>> >>>>>>>> assert(module && "Should have exited if we didn't have a module!"); >>>>>>>> if (FloatABIForCalls != FloatABI::Default) >>>>>>>> targetopts.FloatABIType = FloatABIForCalls; >>>>>>>> >>>>>>>> >>>>>>>> std::unique_ptr<tool_output_file> objoutstream = getOutputFileStream(module, srcname); >>>>>>>> if (!objoutstream) return 1; >>>>>>>> >>>>>>>> legacy::PassManager passmanager; >>>>>>>> >>>>>>>> TargetLibraryInfoImpl TLII(moduletriple); >>>>>>>> >>>>>>>> TargetLibraryInfoWrapperPass *tliwp = new TargetLibraryInfoWrapperPass(TLII); >>>>>>>> >>>>>>>> passmanager.add(tliwp); >>>>>>>> >>>>>>>> module->setDataLayout(tmachine->createDataLayout()); >>>>>>>> >>>>>>>> setFunctionAttributes(cpuname, ftrlist, *module); >>>>>>>> >>>>>>>> if (RelaxAll.getNumOccurrences() > 0 && >>>>>>>> FileType != TargetMachine::CGFT_ObjectFile) >>>>>>>> errs() << "warning: ignoring -mc-relax-all because filetype != obj"; >>>>>>>> >>>>>>>> { >>>>>>>> raw_pwrite_stream *outstream = &objoutstream->os(); >>>>>>>> >>>>>>>> SmallVector<char, 0> filebuf; >>>>>>>> std::unique_ptr<raw_svector_ostream> BOS; >>>>>>>> if ((FileType != TargetMachine::CGFT_AssemblyFile && !objoutstream->os().supportsSeeking())) { >>>>>>>> BOS = make_unique<raw_svector_ostream>(filebuf); >>>>>>>> outstream = BOS.get(); >>>>>>>> } >>>>>>>> >>>>>>>> AnalysisID StartBeforeID = nullptr; >>>>>>>> AnalysisID StartAfterID = nullptr; >>>>>>>> AnalysisID StopAfterID = nullptr; >>>>>>>> const PassRegistry *PR = PassRegistry::getPassRegistry(); >>>>>>>> if (!RunPass.empty()) { >>>>>>>> if (!StartAfter.empty() || !StopAfter.empty()) { >>>>>>>> errs() << "start-after and/or stop-after passes are redundant when run-pass is specified.\n"; >>>>>>>> return 1; >>>>>>>> } >>>>>>>> const PassInfo *PI = PR->getPassInfo(RunPass); >>>>>>>> if (!PI) { >>>>>>>> errs() << "run-pass pass is not registered.\n"; >>>>>>>> return 1; >>>>>>>> } >>>>>>>> StopAfterID = StartBeforeID = PI->getTypeInfo(); >>>>>>>> } else { >>>>>>>> if (!StartAfter.empty()) { >>>>>>>> const PassInfo *PI = PR->getPassInfo(StartAfter); >>>>>>>> if (!PI) { >>>>>>>> errs() << "start-after pass is not registered.\n"; >>>>>>>> return 1; >>>>>>>> } >>>>>>>> StartAfterID = PI->getTypeInfo(); >>>>>>>> } >>>>>>>> if (!StopAfter.empty()) { >>>>>>>> const PassInfo *PI = PR->getPassInfo(StopAfter); >>>>>>>> if (!PI) { >>>>>>>> errs() << "stop-after pass is not registered.\n"; >>>>>>>> return 1; >>>>>>>> } >>>>>>>> StopAfterID = PI->getTypeInfo(); >>>>>>>> } >>>>>>>> } >>>>>>>> >>>>>>>> if (tmachine->addPassesToEmitFile(passmanager, *outstream, FileType, false, StartBeforeID, StartAfterID, StopAfterID)) { >>>>>>>> errs() << "target does not support generation of this file type!\n"; >>>>>>>> return 1; >>>>>>>> } >>>>>>>> >>>>>>>> passmanager.run(*module); >>>>>>>> >>>>>>>> if (BOS) { >>>>>>>> objoutstream->os() << filebuf; >>>>>>>> } >>>>>>>> } >>>>>>>> >>>>>>>> objoutstream->keep(); >>>>>>>> >>>>>>>> return 0; >>>>>>>> } >>>>>>>> _______________________________________________ >>>>>>>> LLVM Developers mailing list >>>>>>>> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> >>>>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev> >>>>>>> >>>>> >>> >>-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160324/57acc956/attachment-0001.html>
Those lines of code are in a function that is called before calling the moduleToObjectFile() function> On Mar 24, 2016, at 6:07 PM, Mehdi Amini <mehdi.amini at apple.com> wrote: > > You may want to try adding this code (copy/pasted from llc.cpp): > > // Initialize targets first, so that --version shows registered targets. > InitializeAllTargets(); > InitializeAllTargetMCs(); > InitializeAllAsmPrinters(); > InitializeAllAsmParsers(); > > // Initialize codegen and IR passes used by llc so that the -print-after, > // -print-before, and -stop-after options work. > PassRegistry *Registry = PassRegistry::getPassRegistry(); > initializeCore(*Registry); > initializeCodeGen(*Registry); > initializeLoopStrengthReducePass(*Registry); > initializeLowerIntrinsicsPass(*Registry); > initializeUnreachableBlockElimPass(*Registry); > > > -- > Mehdi > > > >> On Mar 24, 2016, at 9:59 AM, Lorenzo Laneve <lore97drk at icloud.com> wrote: >> >> Update: >> Sorry my bad. I built llvm and tried it with debugging version. >> It was an assertion (IR/LegacyPassManager.cpp:764) saying that it expects all immutable passes to be initialized. >> >>> On Mar 24, 2016, at 2:00 AM, Lorenzo Laneve <lore97drk at icloud.com> wrote: >>> >>> I’m using LLVM 3.8.0, and no, it’s the precompiled version >>> That’s why it doesn’t give me enough info for debug >>> >>>> On 24 Mar 2016, at 1:53 AM, Mehdi Amini <mehdi.amini at apple.com> wrote: >>>> >>>> This code path is not likely to crash usually. Did you build LLVM yourself? Which version are you using and can you reduce the test case to be "minimal" so that someone can reproduce? >>>> (for instance you don't need a module to create a pass manager) >>>> >>>> -- >>>> Mehdi >>>> >>>>> On Mar 23, 2016, at 5:50 PM, Lorenzo Laneve <lore97drk at icloud.com> wrote: >>>>> >>>>> Sorry, that's a pure crash I think, assertions are not triggered. >>>>> Xcode doesn’t map those 2 functions to line numbers because they’re in precompiled libraries >>>>> >>>>> >>>>> On Mar 24, 2016, at 1:44 AM, Mehdi Amini <mehdi.amini at apple.com> wrote: >>>>> >>>>>> >>>>>>> On Mar 23, 2016, at 5:41 PM, Lorenzo Laneve <lore97drk at icloud.com> wrote: >>>>>>> >>>>>>> The stack trace: >>>>>>> llvm::PMTopLevelManager::addImmutablePass(llvm::ImmutablePass*) >>>>>>> llvm::PMTopLevelManager::schedulePass(llvm::Pass*) >>>>>>> moduleToObjectFile(llvm::Module*,std::string&,llvm::LLVMContext&) >>>>>> >>>>>> >>>>>> Without mapping to line numbers this is not very helpful: moduleToObjectFile never calls schedulePass. >>>>>> >>>>>> Also you didn't answer my previous question about the crash. >>>>>> >>>>>> >>>>>>> Sometimes it doesn't crash because TargetRegistry::lookupTarget() returns an error which says it doesn't support the current target >>>>>> >>>>>> Do you mean that running it multiple time does not always produce the same behavior in the call to lookupTarget? >>>>>> That's unexpected and I'd be worried about my program. >>>>>> >>>>>> -- >>>>>> Mehdi >>>>>> >>>>>> >>>>>> >>>>>>> >>>>>>>> On Mar 24, 2016, at 1:14 AM, Mehdi Amini <mehdi.amini at apple.com> wrote: >>>>>>>> >>>>>>>> Assuming you are talking about this line: >>>>>>>> >>>>>>>> passmanager.add(tliwp); >>>>>>>> >>>>>>>> I don't see anything obviously wrong. >>>>>>>> Are you hitting an assertion or a pure crash? (if LLVM not built with assertions, please rebuild). >>>>>>>> What does your debugger gives you as a stracktrace? >>>>>>>> >>>>>>>> -- >>>>>>>> Mehdi >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> On Mar 23, 2016, at 3:44 PM, Lorenzo Laneve via llvm-dev <llvm-dev at lists.llvm.org> wrote: >>>>>>>>> >>>>>>>>> Sorry in advance for the stupid question, i still don’t understand some concepts like passes. >>>>>>>>> I took a piece of code from llc, and I used it to write a function that creates an object (or assembly) file from an IR module. >>>>>>>>> It compiles without any problems. But program crashes when it reaches add() method of the pass manager. >>>>>>>>> Can you help me figuring out what’s the problem please? here is my function >>>>>>>>> >>>>>>>>> >>>>>>>>> int moduleToObjectFile(llvm::Module *module, std::string &srcname, llvm::LLVMContext &Context) { >>>>>>>>> SMDiagnostic error; >>>>>>>>> Triple moduletriple = Triple(module->getTargetTriple()); >>>>>>>>> >>>>>>>>> if (moduletriple.getTriple().empty()) >>>>>>>>> moduletriple.setTriple(sys::getDefaultTargetTriple()); >>>>>>>>> >>>>>>>>> std::string lookuperror; >>>>>>>>> const Target *moduletarget = TargetRegistry::lookupTarget(MArch, moduletriple, lookuperror); >>>>>>>>> >>>>>>>>> if (!moduletarget) { >>>>>>>>> errs() << lookuperror; >>>>>>>>> return 1; >>>>>>>>> } >>>>>>>>> >>>>>>>>> std::string cpuname = getCPUStr(), >>>>>>>>> ftrlist = getFeaturesStr(); >>>>>>>>> >>>>>>>>> CodeGenOpt::Level OLvl = CodeGenOpt::Default; >>>>>>>>> switch ('2') { >>>>>>>>> default: >>>>>>>>> errs() << "invalid optimization level.\n"; >>>>>>>>> return 1; >>>>>>>>> case ' ': break; >>>>>>>>> case '0': OLvl = CodeGenOpt::None; break; >>>>>>>>> case '1': OLvl = CodeGenOpt::Less; break; >>>>>>>>> case '2': OLvl = CodeGenOpt::Default; break; >>>>>>>>> case '3': OLvl = CodeGenOpt::Aggressive; break; >>>>>>>>> } >>>>>>>>> >>>>>>>>> TargetOptions targetopts = InitTargetOptionsFromCodeGenFlags(); >>>>>>>>> >>>>>>>>> std::unique_ptr<TargetMachine> tmachine(moduletarget->createTargetMachine(moduletriple.getTriple(), cpuname, ftrlist, targetopts, Reloc::Default, CodeModel::Default, OLvl)); >>>>>>>>> >>>>>>>>> assert(tmachine && "Could not allocate target machine!"); >>>>>>>>> >>>>>>>>> assert(module && "Should have exited if we didn't have a module!"); >>>>>>>>> if (FloatABIForCalls != FloatABI::Default) >>>>>>>>> targetopts.FloatABIType = FloatABIForCalls; >>>>>>>>> >>>>>>>>> >>>>>>>>> std::unique_ptr<tool_output_file> objoutstream = getOutputFileStream(module, srcname); >>>>>>>>> if (!objoutstream) return 1; >>>>>>>>> >>>>>>>>> legacy::PassManager passmanager; >>>>>>>>> >>>>>>>>> TargetLibraryInfoImpl TLII(moduletriple); >>>>>>>>> >>>>>>>>> TargetLibraryInfoWrapperPass *tliwp = new TargetLibraryInfoWrapperPass(TLII); >>>>>>>>> >>>>>>>>> passmanager.add(tliwp); >>>>>>>>> >>>>>>>>> module->setDataLayout(tmachine->createDataLayout()); >>>>>>>>> >>>>>>>>> setFunctionAttributes(cpuname, ftrlist, *module); >>>>>>>>> >>>>>>>>> if (RelaxAll.getNumOccurrences() > 0 && >>>>>>>>> FileType != TargetMachine::CGFT_ObjectFile) >>>>>>>>> errs() << "warning: ignoring -mc-relax-all because filetype != obj"; >>>>>>>>> >>>>>>>>> { >>>>>>>>> raw_pwrite_stream *outstream = &objoutstream->os(); >>>>>>>>> >>>>>>>>> SmallVector<char, 0> filebuf; >>>>>>>>> std::unique_ptr<raw_svector_ostream> BOS; >>>>>>>>> if ((FileType != TargetMachine::CGFT_AssemblyFile && !objoutstream->os().supportsSeeking())) { >>>>>>>>> BOS = make_unique<raw_svector_ostream>(filebuf); >>>>>>>>> outstream = BOS.get(); >>>>>>>>> } >>>>>>>>> >>>>>>>>> AnalysisID StartBeforeID = nullptr; >>>>>>>>> AnalysisID StartAfterID = nullptr; >>>>>>>>> AnalysisID StopAfterID = nullptr; >>>>>>>>> const PassRegistry *PR = PassRegistry::getPassRegistry(); >>>>>>>>> if (!RunPass.empty()) { >>>>>>>>> if (!StartAfter.empty() || !StopAfter.empty()) { >>>>>>>>> errs() << "start-after and/or stop-after passes are redundant when run-pass is specified.\n"; >>>>>>>>> return 1; >>>>>>>>> } >>>>>>>>> const PassInfo *PI = PR->getPassInfo(RunPass); >>>>>>>>> if (!PI) { >>>>>>>>> errs() << "run-pass pass is not registered.\n"; >>>>>>>>> return 1; >>>>>>>>> } >>>>>>>>> StopAfterID = StartBeforeID = PI->getTypeInfo(); >>>>>>>>> } else { >>>>>>>>> if (!StartAfter.empty()) { >>>>>>>>> const PassInfo *PI = PR->getPassInfo(StartAfter); >>>>>>>>> if (!PI) { >>>>>>>>> errs() << "start-after pass is not registered.\n"; >>>>>>>>> return 1; >>>>>>>>> } >>>>>>>>> StartAfterID = PI->getTypeInfo(); >>>>>>>>> } >>>>>>>>> if (!StopAfter.empty()) { >>>>>>>>> const PassInfo *PI = PR->getPassInfo(StopAfter); >>>>>>>>> if (!PI) { >>>>>>>>> errs() << "stop-after pass is not registered.\n"; >>>>>>>>> return 1; >>>>>>>>> } >>>>>>>>> StopAfterID = PI->getTypeInfo(); >>>>>>>>> } >>>>>>>>> } >>>>>>>>> >>>>>>>>> if (tmachine->addPassesToEmitFile(passmanager, *outstream, FileType, false, StartBeforeID, StartAfterID, StopAfterID)) { >>>>>>>>> errs() << "target does not support generation of this file type!\n"; >>>>>>>>> return 1; >>>>>>>>> } >>>>>>>>> >>>>>>>>> passmanager.run(*module); >>>>>>>>> >>>>>>>>> if (BOS) { >>>>>>>>> objoutstream->os() << filebuf; >>>>>>>>> } >>>>>>>>> } >>>>>>>>> >>>>>>>>> objoutstream->keep(); >>>>>>>>> >>>>>>>>> return 0; >>>>>>>>> } >>>>>>>>> _______________________________________________ >>>>>>>>> LLVM Developers mailing list >>>>>>>>> llvm-dev at lists.llvm.org >>>>>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160324/c8620476/attachment-0001.html>
So we come back to my earlier comment: can you produce a one-file, < 100 lines that reproduce the issue? -- Mehdi> On Mar 24, 2016, at 10:16 AM, Lorenzo Laneve <lore97drk at icloud.com> wrote: > > Those lines of code are in a function that is called before calling the moduleToObjectFile() function > > On Mar 24, 2016, at 6:07 PM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote: > >> You may want to try adding this code (copy/pasted from llc.cpp): >> >> // Initialize targets first, so that --version shows registered targets. >> InitializeAllTargets(); >> InitializeAllTargetMCs(); >> InitializeAllAsmPrinters(); >> InitializeAllAsmParsers(); >> >> // Initialize codegen and IR passes used by llc so that the -print-after, >> // -print-before, and -stop-after options work. >> PassRegistry *Registry = PassRegistry::getPassRegistry(); >> initializeCore(*Registry); >> initializeCodeGen(*Registry); >> initializeLoopStrengthReducePass(*Registry); >> initializeLowerIntrinsicsPass(*Registry); >> initializeUnreachableBlockElimPass(*Registry); >> >> >> -- >> Mehdi >> >> >> >>> On Mar 24, 2016, at 9:59 AM, Lorenzo Laneve <lore97drk at icloud.com <mailto:lore97drk at icloud.com>> wrote: >>> >>> Update: >>> Sorry my bad. I built llvm and tried it with debugging version. >>> It was an assertion (IR/LegacyPassManager.cpp:764) saying that it expects all immutable passes to be initialized. >>> >>> On Mar 24, 2016, at 2:00 AM, Lorenzo Laneve <lore97drk at icloud.com <mailto:lore97drk at icloud.com>> wrote: >>> >>>> I’m using LLVM 3.8.0, and no, it’s the precompiled version >>>> That’s why it doesn’t give me enough info for debug >>>> >>>>> On 24 Mar 2016, at 1:53 AM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote: >>>>> >>>>> This code path is not likely to crash usually. Did you build LLVM yourself? Which version are you using and can you reduce the test case to be "minimal" so that someone can reproduce? >>>>> (for instance you don't need a module to create a pass manager) >>>>> >>>>> -- >>>>> Mehdi >>>>> >>>>>> On Mar 23, 2016, at 5:50 PM, Lorenzo Laneve <lore97drk at icloud.com <mailto:lore97drk at icloud.com>> wrote: >>>>>> >>>>>> Sorry, that's a pure crash I think, assertions are not triggered. >>>>>> Xcode doesn’t map those 2 functions to line numbers because they’re in precompiled libraries >>>>>> >>>>>> >>>>>> On Mar 24, 2016, at 1:44 AM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote: >>>>>> >>>>>>> >>>>>>>> On Mar 23, 2016, at 5:41 PM, Lorenzo Laneve <lore97drk at icloud.com <mailto:lore97drk at icloud.com>> wrote: >>>>>>>> >>>>>>>> The stack trace: >>>>>>>> llvm::PMTopLevelManager::addImmutablePass(llvm::ImmutablePass*) >>>>>>>> llvm::PMTopLevelManager::schedulePass(llvm::Pass*) >>>>>>>> moduleToObjectFile(llvm::Module*,std::string&,llvm::LLVMContext&) >>>>>>> >>>>>>> >>>>>>> Without mapping to line numbers this is not very helpful: moduleToObjectFile never calls schedulePass. >>>>>>> >>>>>>> Also you didn't answer my previous question about the crash. >>>>>>> >>>>>>> >>>>>>>> Sometimes it doesn't crash because TargetRegistry::lookupTarget() returns an error which says it doesn't support the current target >>>>>>> >>>>>>> Do you mean that running it multiple time does not always produce the same behavior in the call to lookupTarget? >>>>>>> That's unexpected and I'd be worried about my program. >>>>>>> >>>>>>> -- >>>>>>> Mehdi >>>>>>> >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> On Mar 24, 2016, at 1:14 AM, Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote: >>>>>>>> >>>>>>>>> Assuming you are talking about this line: >>>>>>>>> >>>>>>>>> passmanager.add(tliwp); >>>>>>>>> >>>>>>>>> I don't see anything obviously wrong. >>>>>>>>> Are you hitting an assertion or a pure crash? (if LLVM not built with assertions, please rebuild). >>>>>>>>> What does your debugger gives you as a stracktrace? >>>>>>>>> >>>>>>>>> -- >>>>>>>>> Mehdi >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> On Mar 23, 2016, at 3:44 PM, Lorenzo Laneve via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote: >>>>>>>>>> >>>>>>>>>> Sorry in advance for the stupid question, i still don’t understand some concepts like passes. >>>>>>>>>> I took a piece of code from llc, and I used it to write a function that creates an object (or assembly) file from an IR module. >>>>>>>>>> It compiles without any problems. But program crashes when it reaches add() method of the pass manager. >>>>>>>>>> Can you help me figuring out what’s the problem please? here is my function >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> int moduleToObjectFile(llvm::Module *module, std::string &srcname, llvm::LLVMContext &Context) { >>>>>>>>>> SMDiagnostic error; >>>>>>>>>> Triple moduletriple = Triple(module->getTargetTriple()); >>>>>>>>>> >>>>>>>>>> if (moduletriple.getTriple().empty()) >>>>>>>>>> moduletriple.setTriple(sys::getDefaultTargetTriple()); >>>>>>>>>> >>>>>>>>>> std::string lookuperror; >>>>>>>>>> const Target *moduletarget = TargetRegistry::lookupTarget(MArch, moduletriple, lookuperror); >>>>>>>>>> >>>>>>>>>> if (!moduletarget) { >>>>>>>>>> errs() << lookuperror; >>>>>>>>>> return 1; >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> std::string cpuname = getCPUStr(), >>>>>>>>>> ftrlist = getFeaturesStr(); >>>>>>>>>> >>>>>>>>>> CodeGenOpt::Level OLvl = CodeGenOpt::Default; >>>>>>>>>> switch ('2') { >>>>>>>>>> default: >>>>>>>>>> errs() << "invalid optimization level.\n"; >>>>>>>>>> return 1; >>>>>>>>>> case ' ': break; >>>>>>>>>> case '0': OLvl = CodeGenOpt::None; break; >>>>>>>>>> case '1': OLvl = CodeGenOpt::Less; break; >>>>>>>>>> case '2': OLvl = CodeGenOpt::Default; break; >>>>>>>>>> case '3': OLvl = CodeGenOpt::Aggressive; break; >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> TargetOptions targetopts = InitTargetOptionsFromCodeGenFlags(); >>>>>>>>>> >>>>>>>>>> std::unique_ptr<TargetMachine> tmachine(moduletarget->createTargetMachine(moduletriple.getTriple(), cpuname, ftrlist, targetopts, Reloc::Default, CodeModel::Default, OLvl)); >>>>>>>>>> >>>>>>>>>> assert(tmachine && "Could not allocate target machine!"); >>>>>>>>>> >>>>>>>>>> assert(module && "Should have exited if we didn't have a module!"); >>>>>>>>>> if (FloatABIForCalls != FloatABI::Default) >>>>>>>>>> targetopts.FloatABIType = FloatABIForCalls; >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> std::unique_ptr<tool_output_file> objoutstream = getOutputFileStream(module, srcname); >>>>>>>>>> if (!objoutstream) return 1; >>>>>>>>>> >>>>>>>>>> legacy::PassManager passmanager; >>>>>>>>>> >>>>>>>>>> TargetLibraryInfoImpl TLII(moduletriple); >>>>>>>>>> >>>>>>>>>> TargetLibraryInfoWrapperPass *tliwp = new TargetLibraryInfoWrapperPass(TLII); >>>>>>>>>> >>>>>>>>>> passmanager.add(tliwp); >>>>>>>>>> >>>>>>>>>> module->setDataLayout(tmachine->createDataLayout()); >>>>>>>>>> >>>>>>>>>> setFunctionAttributes(cpuname, ftrlist, *module); >>>>>>>>>> >>>>>>>>>> if (RelaxAll.getNumOccurrences() > 0 && >>>>>>>>>> FileType != TargetMachine::CGFT_ObjectFile) >>>>>>>>>> errs() << "warning: ignoring -mc-relax-all because filetype != obj"; >>>>>>>>>> >>>>>>>>>> { >>>>>>>>>> raw_pwrite_stream *outstream = &objoutstream->os(); >>>>>>>>>> >>>>>>>>>> SmallVector<char, 0> filebuf; >>>>>>>>>> std::unique_ptr<raw_svector_ostream> BOS; >>>>>>>>>> if ((FileType != TargetMachine::CGFT_AssemblyFile && !objoutstream->os().supportsSeeking())) { >>>>>>>>>> BOS = make_unique<raw_svector_ostream>(filebuf); >>>>>>>>>> outstream = BOS.get(); >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> AnalysisID StartBeforeID = nullptr; >>>>>>>>>> AnalysisID StartAfterID = nullptr; >>>>>>>>>> AnalysisID StopAfterID = nullptr; >>>>>>>>>> const PassRegistry *PR = PassRegistry::getPassRegistry(); >>>>>>>>>> if (!RunPass.empty()) { >>>>>>>>>> if (!StartAfter.empty() || !StopAfter.empty()) { >>>>>>>>>> errs() << "start-after and/or stop-after passes are redundant when run-pass is specified.\n"; >>>>>>>>>> return 1; >>>>>>>>>> } >>>>>>>>>> const PassInfo *PI = PR->getPassInfo(RunPass); >>>>>>>>>> if (!PI) { >>>>>>>>>> errs() << "run-pass pass is not registered.\n"; >>>>>>>>>> return 1; >>>>>>>>>> } >>>>>>>>>> StopAfterID = StartBeforeID = PI->getTypeInfo(); >>>>>>>>>> } else { >>>>>>>>>> if (!StartAfter.empty()) { >>>>>>>>>> const PassInfo *PI = PR->getPassInfo(StartAfter); >>>>>>>>>> if (!PI) { >>>>>>>>>> errs() << "start-after pass is not registered.\n"; >>>>>>>>>> return 1; >>>>>>>>>> } >>>>>>>>>> StartAfterID = PI->getTypeInfo(); >>>>>>>>>> } >>>>>>>>>> if (!StopAfter.empty()) { >>>>>>>>>> const PassInfo *PI = PR->getPassInfo(StopAfter); >>>>>>>>>> if (!PI) { >>>>>>>>>> errs() << "stop-after pass is not registered.\n"; >>>>>>>>>> return 1; >>>>>>>>>> } >>>>>>>>>> StopAfterID = PI->getTypeInfo(); >>>>>>>>>> } >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> if (tmachine->addPassesToEmitFile(passmanager, *outstream, FileType, false, StartBeforeID, StartAfterID, StopAfterID)) { >>>>>>>>>> errs() << "target does not support generation of this file type!\n"; >>>>>>>>>> return 1; >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> passmanager.run(*module); >>>>>>>>>> >>>>>>>>>> if (BOS) { >>>>>>>>>> objoutstream->os() << filebuf; >>>>>>>>>> } >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> objoutstream->keep(); >>>>>>>>>> >>>>>>>>>> return 0; >>>>>>>>>> } >>>>>>>>>> _______________________________________________ >>>>>>>>>> LLVM Developers mailing list >>>>>>>>>> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> >>>>>>>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev> >>>>>>>>> >>>>>>> >>>>> >>>> >>-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160324/691db722/attachment.html>