Author: Erich Keane Date: 2020-10-12T14:38:04-07:00 New Revision: ac73cafac0e523879b42b305106cd6e67bfb412e
URL: https://github.com/llvm/llvm-project/commit/ac73cafac0e523879b42b305106cd6e67bfb412e DIFF: https://github.com/llvm/llvm-project/commit/ac73cafac0e523879b42b305106cd6e67bfb412e.diff LOG: Ensure TreeTransform considers ParmVarDecls as transformed Decls See PR47804: TreeTransform uses TransformedLocalDecls as a map of declarations that have been transformed already. When doing a "TransformDecl", which happens in the cases of updating a DeclRefExpr's target, the default implementation simply returns the already transformed declaration. However, this was not including ParmVarDecls. SO, any use of TreeTransform that didn't re-implement TransformDecl would NOT properly update the target of a DeclRefExpr, resulting in odd behavior. In the case of Typo-recovery, the result was that a lambda that used its own parameter would cause an error, since it thought that the ParmVarDecl referenced was a different lambda. Additionally, this caused a problem in the AST (a declrefexpr into another scope) such that a future instantiation would cause an assertion. This patch ensures that the ParmVarDecl transforming process records into TransformedLocalDecls so that the DeclRefExpr is ALSO updated. Added: clang/test/SemaCXX/pr47804.cpp Modified: clang/lib/Sema/TreeTransform.h Removed: ################################################################################ diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 8439e72025b8..9d519616856b 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -5479,6 +5479,7 @@ ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( /* DefArg */ nullptr); newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), OldParm->getFunctionScopeIndex() + indexAdjustment); + transformedLocalDecl(OldParm, {newParm}); return newParm; } diff --git a/clang/test/SemaCXX/pr47804.cpp b/clang/test/SemaCXX/pr47804.cpp new file mode 100644 index 000000000000..3ac1de553ffc --- /dev/null +++ b/clang/test/SemaCXX/pr47804.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s -verify + +template <class InputIt, class Pred> +bool all_of(InputIt first, Pred p); + +template <typename T> void load_test() { + // Ensure that this doesn't crash during CorrectDelayedTyposInExpr, + // or any other use of TreeTransform that doesn't implement TransformDecl + // separately. Also, this should only error on 'output', not that 'x' is not + // captured. + // expected-error@+1 {{use of undeclared identifier 'output'}} + all_of(output, [](T x) { return x; }); +} + +int main() { + load_test<int>(); + return 0; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits