Change loadExternalAST to return with either an error or with a valid
ASTUnit pointer which should not be a nullptr.
Details
Diff Detail
- Repository
- rC Clang
Event Timeline
From what I can see, this patch LGTM, but I lack the experience in the CTU department just yet to give any meaningful feedback.
lib/CrossTU/CrossTranslationUnit.cpp | ||
---|---|---|
194 | Would it be worth to add a comment that this function never returns with nullptr on success? |
include/clang/CrossTU/CrossTranslationUnit.h | ||
---|---|---|
134 | Return value description still not accurate: It returns the Expected object, not the pointer itself. | |
lib/CrossTU/CrossTranslationUnit.cpp | ||
194 | Even on failure not. Failure should be Error, success is a non-null pointer. | |
324 | Add explanation text to the assert? |
@Szelethus @balazske Thanks for your review! The meantime I have discussed with @xazax.hun that actually the called ASTUnit::LoadFromASTFile function inside loadExternalAST may return with a nullptr. So, the best is to handle that inside loadExternalAST.
lib/CrossTU/CrossTranslationUnit.cpp | ||
---|---|---|
194 | Yes, you are right. |
Hi Gabor,
There is a code in getExternalAST:
std::unique_ptr<ASTUnit> LoadedUnit(ASTUnit::LoadFromASTFile( ASTFileName, CI.getPCHContainerOperations()->getRawReader(), ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts())); Unit = LoadedUnit.get(); FileASTUnitMap[ASTFileName] = std::move(LoadedUnit);
And ASTUnit::LoadFromASTFile()can return nullptr. Actually, there is a problem in loadExternalAST() - it ignores this fact.
Hi Aleksey,
The first version was indeed not correct. But, I think we handle that case with the latest update (https://reviews.llvm.org/differential/diff/176779/). In loadExternalAST() we have this right before the return:
if (!Unit) return llvm::make_error<IndexError>( index_error_code::failed_to_get_external_ast); return Unit;
So we will never return with a nullptr value in the Expected.
Return value description still not accurate: It returns the Expected object, not the pointer itself.