[PATCH] D59900: [Sema] Fix a crash when nonnull checking

Michael Liao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 27 13:39:35 PDT 2019


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 <typename T>
+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<FunctionDecl>(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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59900.192514.patch
Type: text/x-patch
Size: 1037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190327/ff27d3f5/attachment.bin>


More information about the cfe-commits mailing list