[PATCH] D100667: [clang] Fix assert() crash when checking undeduced arg alignment
Adam Czachorowski via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 26 07:48:57 PDT 2021
adamcz updated this revision to Diff 340527.
adamcz added a comment.
Added a fix in CreateRecoveryExpr
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100667/new/
https://reviews.llvm.org/D100667
Files:
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx17-undeduced-alignment.cpp
Index: clang/test/SemaCXX/cxx17-undeduced-alignment.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/cxx17-undeduced-alignment.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s
+//
+// Verifies that clang no longer crashes on undeduced, sugared types.
+
+template <class T> void foo(T &t);
+template <typename T>
+void bar(T t) {
+ foo(t);
+}
+
+template <typename T = void *>
+struct S { // expected-note {{candidate}}
+ S(T t); // expected-note {{candidate}}
+ ~S();
+};
+template <typename T> S(T t) -> S<void *>;
+
+void baz() {
+ // S(123) is undeduced, but when passed to foo() via bar() it is wrapped in
+ // SubstTemplateTypeParm, for which isUndeduced() is false.
+ bar(S(123)); // expected-error {{no matching conversion}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -19661,8 +19661,13 @@
if (isSFINAEContext())
return ExprError();
- if (T.isNull() || !Context.getLangOpts().RecoveryASTType)
+ if (T.isNull() || T->isUndeducedType() ||
+ !Context.getLangOpts().RecoveryASTType)
// We don't know the concrete type, fallback to dependent type.
T = Context.DependentTy;
+ else if (const auto *U = T->getUnqualifiedDesugaredType())
+ if (U->isUndeducedType())
+ T = Context.DependentTy;
+
return RecoveryExpr::Create(Context, T, Begin, End, SubExprs);
}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4540,8 +4540,15 @@
// Find expected alignment, and the actual alignment of the passed object.
// getTypeAlignInChars requires complete types
- if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() ||
- ParamTy->isUndeducedType() || ArgTy->isUndeducedType())
+ auto CheckTypeOK = [](QualType Ty) {
+ if (Ty->isIncompleteType() || Ty->isUndeducedType())
+ return false;
+ if (const auto *DesugaredTy = Ty->getUnqualifiedDesugaredType())
+ if (DesugaredTy->isIncompleteType() || DesugaredTy->isUndeducedType())
+ return false;
+ return true;
+ };
+ if (!CheckTypeOK(ParamTy) || !CheckTypeOK(ArgTy))
return;
CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100667.340527.patch
Type: text/x-patch
Size: 2417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210426/9340beaf/attachment.bin>
More information about the cfe-commits
mailing list