[PATCH] D59900: [Sema] Fix a crash when nonnull checking
This revision was automatically updated to reflect the committed changes. Closed by commit rL357236: [Sema] Fix a crash when nonnull checking (authored by hliao, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D59900?vs=192514=192776#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59900/new/ https://reviews.llvm.org/D59900 Files: cfe/trunk/lib/Sema/SemaChecking.cpp cfe/trunk/test/SemaCXX/pr30559.cpp Index: cfe/trunk/test/SemaCXX/pr30559.cpp === --- cfe/trunk/test/SemaCXX/pr30559.cpp +++ cfe/trunk/test/SemaCXX/pr30559.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s + +template < bool, class > struct A {}; +template < class, int > void f () {}; +template < class T, int > +decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {}; + +struct B {}; + +int main () +{ + f < B, 0 >; + return 0; +} + +template +auto foo(T x) -> decltype((x == nullptr), *x) { + return *x; +} + +void bar() { + foo(new int); +} Index: cfe/trunk/lib/Sema/SemaChecking.cpp === --- cfe/trunk/lib/Sema/SemaChecking.cpp +++ cfe/trunk/lib/Sema/SemaChecking.cpp @@ -11592,6 +11592,9 @@ } if (const auto *FD = dyn_cast(PV->getDeclContext())) { +// Skip function template not specialized yet. +if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) + return; auto ParamIter = llvm::find(FD->parameters(), PV); assert(ParamIter != FD->param_end()); unsigned ParamNo = std::distance(FD->param_begin(), ParamIter); Index: cfe/trunk/test/SemaCXX/pr30559.cpp === --- cfe/trunk/test/SemaCXX/pr30559.cpp +++ cfe/trunk/test/SemaCXX/pr30559.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only %s + +template < bool, class > struct A {}; +template < class, int > void f () {}; +template < class T, int > +decltype (f < T, 1 >) f (T t, typename A < t == 0, int >::type) {}; + +struct B {}; + +int main () +{ + f < B, 0 >; + return 0; +} + +template +auto foo(T x) -> decltype((x == nullptr), *x) { + return *x; +} + +void bar() { + foo(new int); +} Index: cfe/trunk/lib/Sema/SemaChecking.cpp === --- cfe/trunk/lib/Sema/SemaChecking.cpp +++ cfe/trunk/lib/Sema/SemaChecking.cpp @@ -11592,6 +11592,9 @@ } if (const auto *FD = dyn_cast(PV->getDeclContext())) { +// Skip function template not specialized yet. +if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) + return; auto ParamIter = llvm::find(FD->parameters(), PV); assert(ParamIter != FD->param_end()); unsigned ParamNo = std::distance(FD->param_begin(), ParamIter); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59900: [Sema] Fix a crash when nonnull checking
hliao added a comment. just search bugzilla and, fortunately, found this issue is reported 2+ years ago @ https://bugs.llvm.org/show_bug.cgi?id=30559. I will revise the test case to PR30559 and move it into test/SemaCXX/nonnull.cpp Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59900/new/ https://reviews.llvm.org/D59900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59900: [Sema] Fix a crash when nonnull checking
tra added inline comments. Comment at: clang/test/SemaTemplate/decltype.cpp:1 +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// no crash & no diag Rakete wrote: > test/SemaCXX/nonnull.cpp would be a better place to put this test. `test/SemaCXX/nonnull.cpp` tests `attribute((nonnull))`. Placing this test there would be... odd. The test could use a more descriptive name, though. Just `decltype` is way too generic. `early-func-template-decltype`? Or PR-somthing-something, if there's a bug for this crasher. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59900/new/ https://reviews.llvm.org/D59900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59900: [Sema] Fix a crash when nonnull checking
Rakete accepted this revision. Rakete added a comment. This revision is now accepted and ready to land. Otherwise LGTM. Comment at: clang/test/SemaTemplate/decltype.cpp:1 +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// no crash & no diag test/SemaCXX/nonnull.cpp would be a better place to put this test. Comment at: clang/test/SemaTemplate/decltype.cpp:2 +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// no crash & no diag + This is redundant :) Comment at: clang/test/SemaTemplate/decltype.cpp:4 + +// expected-no-diagnostics +template If you move the test as above you can drop this line. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59900/new/ https://reviews.llvm.org/D59900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59900: [Sema] Fix a crash when nonnull checking
hliao added a comment. just explain what's the issue is and hope that help reviewers to get this fix quick. - In `Sema::DiagnoseAlwaysNonNullPointer`, we issue warnings if a `nonnull` parameter is used in null checking. It need the function declaration to check parameter attributes. That usually works but fails if that function decl is not ready yet. - In template instantiation, we first create the function prototype followed by instantiating the function body. When the function prototype is being formed, we may create binary or other expressions for semantic checking. But, in that phase, i.e. `Sema::SubstFunctionDeclType`, we don't have the a fully specialized function prototype yet to check the parameter number and run into the assertion @ line 11596. Hope that help to get the picture of this fix. Thanks. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59900/new/ https://reviews.llvm.org/D59900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59900: [Sema] Fix a crash when nonnull checking
jlebar added a comment. I uh... I also think this is an @rsmith question, I have no idea. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59900/new/ https://reviews.llvm.org/D59900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59900: [Sema] Fix a crash when nonnull checking
tra added subscribers: jlebar, rsmith. tra added a comment. @rsmith, @jlebar I'm out of my depth here and could use some language lawyering help. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59900/new/ https://reviews.llvm.org/D59900 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59900: [Sema] Fix a crash when nonnull checking
hliao created this revision. hliao added reviewers: rjmccall, tra, yaxunl. Herald added subscribers: cfe-commits, kristof.beyls, javed.absar. Herald added a project: clang. - Non-null checking is triggered during prototype substitution from a template instantiation, if expressions in `decltype` contains nullptr chcking. Skip non-null checking in that case as the protype is not finalized yet. Also, the nullptr checking in `decltype` is only used for type inspection instead of codegen. Ignoring that is harmless. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D59900 Files: clang/lib/Sema/SemaChecking.cpp clang/test/SemaTemplate/decltype.cpp Index: clang/test/SemaTemplate/decltype.cpp === --- /dev/null +++ clang/test/SemaTemplate/decltype.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// no crash & no diag + +// expected-no-diagnostics +template +auto foo(T x) -> decltype((x == nullptr), *x) { + return *x; +} + +void bar() { + foo(new int); +} Index: clang/lib/Sema/SemaChecking.cpp === --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -11592,6 +11592,9 @@ } if (const auto *FD = dyn_cast(PV->getDeclContext())) { +// Skip function template not specialized yet. +if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) + return; auto ParamIter = llvm::find(FD->parameters(), PV); assert(ParamIter != FD->param_end()); unsigned ParamNo = std::distance(FD->param_begin(), ParamIter); Index: clang/test/SemaTemplate/decltype.cpp === --- /dev/null +++ clang/test/SemaTemplate/decltype.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s +// no crash & no diag + +// expected-no-diagnostics +template +auto foo(T x) -> decltype((x == nullptr), *x) { + return *x; +} + +void bar() { + foo(new int); +} Index: clang/lib/Sema/SemaChecking.cpp === --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -11592,6 +11592,9 @@ } if (const auto *FD = dyn_cast(PV->getDeclContext())) { +// Skip function template not specialized yet. +if (FD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) + return; auto ParamIter = llvm::find(FD->parameters(), PV); assert(ParamIter != FD->param_end()); unsigned ParamNo = std::distance(FD->param_begin(), ParamIter); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits