Fix crash if, during evaluation of __builtin_object_size, we try to load

through an invalid base.

llvm-svn: 360998
This commit is contained in:
Richard Smith 2019-05-17 08:01:34 +00:00
parent 77483765eb
commit 51ce8444f0
2 changed files with 12 additions and 0 deletions

View File

@ -3285,6 +3285,11 @@ static bool AreElementsOfSameArray(QualType ObjType,
static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E,
AccessKinds AK, const LValue &LVal,
QualType LValType) {
if (LVal.InvalidBase) {
Info.FFDiag(E);
return CompleteObject();
}
if (!LVal.Base) {
Info.FFDiag(E, diag::note_constexpr_access_null) << AK;
return CompleteObject();

View File

@ -97,3 +97,10 @@ void tooSmallBuf() {
copy5CharsIntoStrict(small.buf); // expected-error{{no matching function for call}}
}
}
namespace InvalidBase {
// Ensure this doesn't crash.
struct S { const char *name; };
S invalid_base();
constexpr long bos_name = __builtin_object_size(invalid_base().name, 1);
}