diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index e41264e55e4c..236827280efb 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -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(); diff --git a/clang/test/SemaCXX/builtin-object-size-cxx14.cpp b/clang/test/SemaCXX/builtin-object-size-cxx14.cpp index 32d752d27365..bc52478e801e 100644 --- a/clang/test/SemaCXX/builtin-object-size-cxx14.cpp +++ b/clang/test/SemaCXX/builtin-object-size-cxx14.cpp @@ -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); +}