Skip to content

Commit fbfcfdb

Browse files
committed
[clang] Fix assert() crash when checking undeduced arg alignment
There already was a check for undeduced and incomplete types, but it failed to trigger when outer type (SubstTemplateTypeParm in test) looked fine, but inner type was not. Differential Revision: https://reviews.llvm.org/D100667
1 parent e2a2df2 commit fbfcfdb

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4540,8 +4540,7 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
45404540

45414541
// Find expected alignment, and the actual alignment of the passed object.
45424542
// getTypeAlignInChars requires complete types
4543-
if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() ||
4544-
ParamTy->isUndeducedType() || ArgTy->isUndeducedType())
4543+
if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType())
45454544
return;
45464545

45474546
CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19662,8 +19662,10 @@ ExprResult Sema::CreateRecoveryExpr(SourceLocation Begin, SourceLocation End,
1966219662
if (isSFINAEContext())
1966319663
return ExprError();
1966419664

19665-
if (T.isNull() || !Context.getLangOpts().RecoveryASTType)
19665+
if (T.isNull() || T->isUndeducedType() ||
19666+
!Context.getLangOpts().RecoveryASTType)
1966619667
// We don't know the concrete type, fallback to dependent type.
1966719668
T = Context.DependentTy;
19669+
1966819670
return RecoveryExpr::Create(Context, T, Begin, End, SubExprs);
1966919671
}

clang/test/SemaCXX/recovery-expr-type.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -fsyntax-only -verify
1+
// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -std=gnu++17 -fsyntax-only -verify
22

33
namespace test0 {
44
struct Indestructible {
@@ -26,7 +26,7 @@ namespace test2 {
2626
void foo(); // expected-note 3{{requires 0 arguments}}
2727
void func() {
2828
// verify that "field has incomplete type" diagnostic is suppressed.
29-
typeof(foo(42)) var; // expected-error {{no matching function}}
29+
typeof(foo(42)) var; // expected-error {{no matching function}} \
3030
3131
// FIXME: suppress the "cannot initialize a variable" diagnostic.
3232
int a = foo(1); // expected-error {{no matching function}} \
@@ -116,3 +116,23 @@ int f(); // expected-note {{candidate}}
116116
template<typename T> const int k = f(T()); // expected-error {{no matching function}}
117117
static_assert(k<int> == 1, ""); // expected-note {{instantiation of}}
118118
}
119+
120+
namespace test11 {
121+
// Verify we do not assert()-fail here.
122+
template <class T> void foo(T &t);
123+
template <typename T>
124+
void bar(T t) {
125+
foo(t);
126+
}
127+
128+
template <typename T = void *>
129+
struct S { // expected-note {{candidate}}
130+
S(T t); // expected-note {{candidate}}
131+
~S();
132+
};
133+
template <typename T> S(T t) -> S<void *>;
134+
135+
void baz() {
136+
bar(S(123)); // expected-error {{no matching conversion}}
137+
}
138+
} // namespace test11

0 commit comments

Comments
 (0)