llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Mark de Wever (mark-de-wever-sonarsource) <details> <summary>Changes</summary> This applies the name restoration as suggested by Richard Smith. Fixes: #<!-- -->54279 --- Full diff: https://github.com/llvm/llvm-project/pull/142338.diff 3 Files Affected: - (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+5) - (modified) clang/test/CodeGenCXX/constructor-init.cpp (+1-1) - (modified) clang/test/SemaTemplate/default-arguments.cpp (+9) ``````````diff diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 174c8fc59e4fa..9853466e01496 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -34,6 +34,7 @@ #include "clang/Sema/SemaSwift.h" #include "clang/Sema/Template.h" #include "clang/Sema/TemplateInstCallback.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/Support/TimeProfiler.h" #include <optional> @@ -5120,6 +5121,10 @@ bool Sema::addInstantiatedParametersToScope( // Simple case: not a parameter pack. assert(FParamIdx < Function->getNumParams()); ParmVarDecl *FunctionParam = Function->getParamDecl(FParamIdx); + DeclarationName name = FunctionParam->getDeclName(); + auto _ = llvm::make_scope_exit([&]() { + FunctionParam->setDeclName(name); + }); FunctionParam->setDeclName(PatternParam->getDeclName()); // If the parameter's type is not dependent, update it to match the type // in the pattern. They can differ in top-level cv-qualifiers, and we want diff --git a/clang/test/CodeGenCXX/constructor-init.cpp b/clang/test/CodeGenCXX/constructor-init.cpp index f191599f360e7..b5f4cc0b3d6c8 100644 --- a/clang/test/CodeGenCXX/constructor-init.cpp +++ b/clang/test/CodeGenCXX/constructor-init.cpp @@ -160,7 +160,7 @@ template<typename T> struct X; // Make sure that the instantiated constructor initializes start and // end properly. -// CHECK-LABEL: define linkonce_odr void @_ZN1XIiEC2ERKS0_(ptr {{[^,]*}} %this, ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %other) unnamed_addr +// CHECK-LABEL: define linkonce_odr void @_ZN1XIiEC2ERKS0_(ptr {{[^,]*}} %this, ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %0) unnamed_addr // CHECK: {{store.*null}} // CHECK: {{store.*null}} // CHECK: ret diff --git a/clang/test/SemaTemplate/default-arguments.cpp b/clang/test/SemaTemplate/default-arguments.cpp index 5ea34c0254ec1..a366c3d8ab722 100644 --- a/clang/test/SemaTemplate/default-arguments.cpp +++ b/clang/test/SemaTemplate/default-arguments.cpp @@ -283,3 +283,12 @@ static_assert(S<short *>().SizeOfT<char>() == sizeof(short *), ""); } // namespace GH68490 #endif + +namespace PR54279 { +// Using a different name for the argument when there is a default argument +// caused a crash. +template <typename T> void f(const T &a, int c = 0); +template <> void f(const int &unused, int) { + f(42); +} +} `````````` </details> https://github.com/llvm/llvm-project/pull/142338 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits