Skip to content

Commit 7b0396f

Browse files
authored
[Clang][Sema] Fix crash when type used in return statement contains errors (#79788)
In Sema in `BuildReturnStmt(...)` when we try to determine is the type is move eligible or copy elidable we don't currently check of the init of the `VarDecl` contain errors or not. This can lead to a crash since we may send a type that is not complete into `getTypeInfo(...)` which does not allow this. This fixes: #63244 #79745
1 parent 2073782 commit 7b0396f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ Bug Fixes to C++ Support
138138
- Fixed deducing auto& from const int in template parameters of partial
139139
specializations.
140140
(`#77189 <https://github.com/llvm/llvm-project/issues/77189>`_)
141+
- Fix for crash when using a erroneous type in a return statement.
142+
Fixes (`#63244 <https://github.com/llvm/llvm-project/issues/63244>`_)
143+
and (`#79745 <https://github.com/llvm/llvm-project/issues/79745>`_)
141144

142145
Bug Fixes to AST Handling
143146
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,6 +3391,8 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *&E,
33913391
const auto *VD = dyn_cast<VarDecl>(DR->getDecl());
33923392
if (!VD)
33933393
return NamedReturnInfo();
3394+
if (VD->getInit() && VD->getInit()->containsErrors())
3395+
return NamedReturnInfo();
33943396
NamedReturnInfo Res = getNamedReturnInfo(VD);
33953397
if (Res.Candidate && !E->isXValue() &&
33963398
(Mode == SimplerImplicitMoveMode::ForceOn ||

clang/test/SemaCXX/deduced-return-type-cxx14.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,3 +724,12 @@ struct DeducedTargetTypeOfConversionFunction {
724724
// since-cxx20-error@-1 {{'decltype(auto)' not allowed in declaration of conversion function template}}
725725
#endif
726726
};
727+
728+
namespace GH79745 {
729+
template <typename = int> struct a; // expected-note {{template is declared here}}
730+
auto f() {
731+
a c; // cxx20_23-error {{implicit instantiation of undefined template}} \
732+
// cxx14-error {{use of class template 'a' requires template arguments}}
733+
return c;
734+
}
735+
}

0 commit comments

Comments
 (0)