[PATCH] D114908: [clang] Don't call inheritDefaultTemplateArguments() on CXXDeductionGuideDecl's template parameters
Arthur Eubanks via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 1 13:42:06 PST 2021
aeubanks created this revision.
aeubanks added a reviewer: rsmith.
aeubanks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
A CXXDeductionGuideDecl references its class's template parameters
(rather than cloning them). This causes us to currently call
inheritDefaultTemplateArguments() on the class template parameters
twice, which causes crashes because DefaultArgStorage::setInherited()
should only be called once.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D114908
Files:
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/Modules/Inputs/ctad/a.h
clang/test/Modules/Inputs/ctad/b.h
clang/test/Modules/Inputs/ctad/module.modulemap
clang/test/Modules/ctad.cpp
Index: clang/test/Modules/ctad.cpp
===================================================================
--- /dev/null
+++ clang/test/Modules/ctad.cpp
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fno-implicit-modules -x c++ -emit-module %S/Inputs/ctad/module.modulemap -fmodule-name=a -o %t/a.pcm -std=c++17
+// RUN: %clang_cc1 -fmodules -fno-implicit-modules -x c++ -emit-module %S/Inputs/ctad/module.modulemap -fmodule-name=b -o %t/b.pcm -std=c++17
+// RUN: %clang_cc1 -fmodules -fno-implicit-modules -x c++ -emit-llvm -I%S/Inputs/ctad -o - %s -fmodule-file=%t/a.pcm -fmodule-file=%t/b.pcm -std=c++17 | FileCheck %s
+
+// CHECK: @_a = global
+// CHECK: @_b = global
+// CHECK: call void @__cxx_global_var_init()
+// CHECK: call void @__cxx_global_var_init.1()
+
+#include "a.h"
+#include "b.h"
Index: clang/test/Modules/Inputs/ctad/module.modulemap
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/ctad/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
Index: clang/test/Modules/Inputs/ctad/b.h
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/ctad/b.h
@@ -0,0 +1,7 @@
+#pragma once
+
+template<typename T=int> struct A {
+ A(T) {}
+};
+
+A _b(5);
Index: clang/test/Modules/Inputs/ctad/a.h
===================================================================
--- /dev/null
+++ clang/test/Modules/Inputs/ctad/a.h
@@ -0,0 +1,7 @@
+#pragma once
+
+template<typename T=int> struct A {
+ A(T) {}
+};
+
+A _a(2);
Index: clang/lib/Serialization/ASTReaderDecl.cpp
===================================================================
--- clang/lib/Serialization/ASTReaderDecl.cpp
+++ clang/lib/Serialization/ASTReaderDecl.cpp
@@ -3781,9 +3781,13 @@
// If the declaration declares a template, it may inherit default arguments
// from the previous declaration.
- if (auto *TD = dyn_cast<TemplateDecl>(D))
- inheritDefaultTemplateArguments(Reader.getContext(),
- cast<TemplateDecl>(Previous), TD);
+ if (auto *TD = dyn_cast<TemplateDecl>(D)) {
+ // CXXDeductionGuideDecls reference the class template parameters so we need
+ // to make sure not to call this twice on the same template parameters.
+ if (!isa<CXXDeductionGuideDecl>(TD->getTemplatedDecl()))
+ inheritDefaultTemplateArguments(Reader.getContext(),
+ cast<TemplateDecl>(Previous), TD);
+ }
// If any of the declaration in the chain contains an Inheritable attribute,
// it needs to be added to all the declarations in the redeclarable chain.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114908.391128.patch
Type: text/x-patch
Size: 2703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211201/9f23f861/attachment.bin>
More information about the cfe-commits
mailing list