r360998 - Fix crash if, during evaluation of __builtin_object_size, we try to load
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Fri May 17 01:01:35 PDT 2019
Author: rsmith
Date: Fri May 17 01:01:34 2019
New Revision: 360998
URL: http://llvm.org/viewvc/llvm-project?rev=360998&view=rev
Log:
Fix crash if, during evaluation of __builtin_object_size, we try to load
through an invalid base.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=360998&r1=360997&r2=360998&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri May 17 01:01:34 2019
@@ -3285,6 +3285,11 @@ static bool AreElementsOfSameArray(QualT
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();
Modified: cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp?rev=360998&r1=360997&r2=360998&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp (original)
+++ cfe/trunk/test/SemaCXX/builtin-object-size-cxx14.cpp Fri May 17 01:01:34 2019
@@ -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);
+}
More information about the cfe-commits
mailing list