Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on invalid on NVRO within template instantiation #51050

Closed
Weverything opened this issue Sep 2, 2021 · 5 comments
Closed

Crash on invalid on NVRO within template instantiation #51050

Weverything opened this issue Sep 2, 2021 · 5 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@Weverything
Copy link
Contributor

Bugzilla Link 51708
Resolution FIXED
Resolved on Sep 07, 2021 10:49
Version trunk
OS Linux
Blocks #50580
CC @zygoloid,@tstellar
Fixed by commit(s) d98c34f c30b281

Extended Description

This crash was first observed at this revision:
f2d5fce

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 a
;
template
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'
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'
b f() {
^
test.ii:10:3: note: in instantiation of function template specialization 'f<a>' 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'
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.

@Weverything
Copy link
Contributor Author

assigned to @mizvekov

@mizvekov
Copy link
Contributor

mizvekov commented Sep 2, 2021

FYI this also affects clang before that patch if the variable's alignment is explicitly specified:

template <class>
class a
;
template <typename b>
b f() {
  alignas(1) b d;
  return d;
}
auto e = {
  f< a< int > >() };

Example on clang-12: https://godbolt.org/z/E8zx1xn3T

@mizvekov
Copy link
Contributor

mizvekov commented Sep 2, 2021

Fix in review at https://reviews.llvm.org/D109191

@mizvekov
Copy link
Contributor

mizvekov commented Sep 3, 2021

Fixed by d98c34f

@tstellar
Copy link
Collaborator

tstellar commented Sep 7, 2021

Merged: c30b281

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants