[llvm-bugs] [Bug 51708] New: Crash on invalid on NVRO within template instantiation

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Sep 1 19:34:14 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51708

            Bug ID: 51708
           Summary: Crash on invalid on NVRO within template instantiation
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: mizvekov at gmail.com
          Reporter: rtrieu at google.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

This crash was first observed at this revision:
https://github.com/llvm/llvm-project/commit/f2d5fce86e81a8b37fbc0829a1c68b6eb48f8365

As seen in the test case below, the crash happens when the VarDecl being tested
for NVRO is invalid during template instantiation.

Testing shows that in TemplateDeclInstantiator::VisitVarDecl, if the call to
SemaRef.getNamedReturnInfo is skipped when Var->isInvalidDecl(), then the crash
can be avoided.  Although a better fix would be to handle invalid Decl's when
checking alignment.

$ cat test.ii
template <class>
class a
;
template <typename b>
b f() {
  b d;
  return d;
}
auto e = {
  f< a< int > >() };

$ clang test.ii
test.ii:10:3: error: implicit instantiation of undefined template 'a<int>'
  f< a< int > >() };
  ^
test.ii:2:7: note: template is declared here
class a
      ^
test.ii:5:3: error: implicit instantiation of undefined template 'a<int>'
b f() {
  ^
test.ii:10:3: note: in instantiation of function template specialization
'f<a<int>>' requested here
  f< a< int > >() };
  ^
test.ii:2:7: note: template is declared here
class a
      ^
test.ii:6:5: error: implicit instantiation of undefined template 'a<int>'
  b d;
    ^
test.ii:2:7: note: template is declared here
class a
      ^
clang/lib/AST/RecordLayoutBuilder.cpp:3256: const clang::ASTRecordLayout
&clang::ASTContext::getASTRecordLayout(const clang::RecordDecl *) const:
Assertion `D && "Cannot get layout of forward declarations!"' failed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210902/692591bb/attachment.html>


More information about the llvm-bugs mailing list