Skip to content

Commit ce38992

Browse files
committedMar 29, 2019
[Sema] Fix a crash when nonnull checking
Summary: - If a parameter is used, nonnull checking needs function prototype to retrieve the corresponding parameter's attributes. However, at the prototype substitution phase when a template is being instantiated, expression may be created and checked without a fully specialized prototype. Under such a scenario, skip nonnull checking on that argument. Reviewers: rjmccall, tra, yaxunl Subscribers: javed.absar, kristof.beyls, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59900 llvm-svn: 357236
1 parent 5fddf09 commit ce38992

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎clang/lib/Sema/SemaChecking.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -11592,6 +11592,9 @@ void Sema::DiagnoseAlwaysNonNullPointer(Expr *E,
1159211592
}
1159311593

1159411594
if (const auto *FD = dyn_cast<FunctionDecl>(PV->getDeclContext())) {
11595+
// Skip function template not specialized yet.
11596+
if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
11597+
return;
1159511598
auto ParamIter = llvm::find(FD->parameters(), PV);
1159611599
assert(ParamIter != FD->param_end());
1159711600
unsigned ParamNo = std::distance(FD->param_begin(), ParamIter);

‎clang/test/SemaCXX/pr30559.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s
2+
3+
template < bool, class > struct A {};
4+
template < class, int > void f () {};
5+
template < class T, int >
6+
decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {};
7+
8+
struct B {};
9+
10+
int main ()
11+
{
12+
f < B, 0 >;
13+
return 0;
14+
}
15+
16+
template <typename T>
17+
auto foo(T x) -> decltype((x == nullptr), *x) {
18+
return *x;
19+
}
20+
21+
void bar() {
22+
foo(new int);
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.