-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang][ASTImporter] Fix of unchecked Error object #112688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][ASTImporter] Fix of unchecked Error object #112688
Conversation
After a previous fix and commit 30a9cac error handling in function 'importTemplateParameterDefaultArgument' was not correct because std::move was removed from return of an Error object and this caused crash "Error value was Success" in some cases.
|
@llvm/pr-subscribers-clang Author: Balázs Kéri (balazske) ChangesAfter a previous fix and commit 30a9cac error handling in function 'importTemplateParameterDefaultArgument' was not correct because std::move was removed from return of an Error object and this caused crash "Error value was Success" in some cases. Full diff: https://github.com/llvm/llvm-project/pull/112688.diff 1 Files Affected:
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 020a2f396b5aa0..e7a6509167f0a0 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -362,24 +362,24 @@ namespace clang {
template <typename TemplateParmDeclT>
Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
TemplateParmDeclT *ToD) {
- Error Err = Error::success();
if (D->hasDefaultArgument()) {
if (D->defaultArgumentWasInherited()) {
- auto *ToInheritedFrom = const_cast<TemplateParmDeclT *>(
- importChecked(Err, D->getDefaultArgStorage().getInheritedFrom()));
- if (Err)
- return Err;
+ Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
+ import(D->getDefaultArgStorage().getInheritedFrom());
+ if (!ToInheritedFromOrErr)
+ return ToInheritedFromOrErr.takeError();
+ TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
if (!ToInheritedFrom->hasDefaultArgument()) {
// Resolve possible circular dependency between default value of the
// template argument and the template declaration.
- const auto ToInheritedDefaultArg =
- importChecked(Err, D->getDefaultArgStorage()
- .getInheritedFrom()
- ->getDefaultArgument());
- if (Err)
- return Err;
+ Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
+ import(D->getDefaultArgStorage()
+ .getInheritedFrom()
+ ->getDefaultArgument());
+ if (!ToInheritedDefaultArgOrErr)
+ return ToInheritedDefaultArgOrErr.takeError();
ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
- ToInheritedDefaultArg);
+ *ToInheritedDefaultArgOrErr);
}
ToD->setInheritedDefaultArgument(ToD->getASTContext(),
ToInheritedFrom);
@@ -395,7 +395,7 @@ namespace clang {
*ToDefaultArgOrErr);
}
}
- return Err;
+ return Error::success();
}
public:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change itself LGTM, but I'm a bit confused by the commit message.
Do I understand it correctly that the import was crashing (more precisely running into an assertion failure) on some input and this commit prevents this crash? If yes, then this is not an NFC change (but a valuable bugfix 🙂 ), so you should not mark it as NFC.
Also, did the apparently NFC removal of std::move influence anything in the behavior of this code? Do you only mention it because it's a recent modification of this code, or did the crash appear when it was merged?
|
I do not want now to check what is exactly happening, the case is a bit interesting. Normally |
After a previous fix and commit 30a9cac error handling in function 'importTemplateParameterDefaultArgument' was not correct because std::move was removed from return of an Error object and this caused crash "Error value was Success" in some cases.