From owner-svn-src-head@freebsd.org Fri Jul 21 17:59:55 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 85D6FDADB1F; Fri, 21 Jul 2017 17:59:55 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 486E57DD45; Fri, 21 Jul 2017 17:59:55 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v6LHxs3Z046563; Fri, 21 Jul 2017 17:59:54 GMT (envelope-from dim@FreeBSD.org) Received: (from dim@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v6LHxsPX046562; Fri, 21 Jul 2017 17:59:54 GMT (envelope-from dim@FreeBSD.org) Message-Id: <201707211759.v6LHxsPX046562@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dim set sender to dim@FreeBSD.org using -f From: Dimitry Andric Date: Fri, 21 Jul 2017 17:59:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r321342 - head/contrib/llvm/tools/clang/lib/AST X-SVN-Group: head X-SVN-Commit-Author: dim X-SVN-Commit-Paths: head/contrib/llvm/tools/clang/lib/AST X-SVN-Commit-Revision: 321342 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jul 2017 17:59:55 -0000 Author: dim Date: Fri Jul 21 17:59:54 2017 New Revision: 321342 URL: https://svnweb.freebsd.org/changeset/base/321342 Log: Pull in r295886 from upstream clang trunk (by Richard Smith): PR32034: Evaluate _Atomic(T) in-place when T is a class or array type. This is necessary in order for the evaluation of an _Atomic initializer for those types to have an associated object, which an initializer for class or array type needs. This fixes an assertion when building recent versions of LinuxCNC. Reported by: trasz PR: 220883 MFC after: 1 week Modified: head/contrib/llvm/tools/clang/lib/AST/ExprConstant.cpp Modified: head/contrib/llvm/tools/clang/lib/AST/ExprConstant.cpp ============================================================================== --- head/contrib/llvm/tools/clang/lib/AST/ExprConstant.cpp Fri Jul 21 17:58:06 2017 (r321341) +++ head/contrib/llvm/tools/clang/lib/AST/ExprConstant.cpp Fri Jul 21 17:59:54 2017 (r321342) @@ -1404,7 +1404,8 @@ static bool EvaluateIntegerOrLValue(const Expr *E, APV EvalInfo &Info); static bool EvaluateFloat(const Expr *E, APFloat &Result, EvalInfo &Info); static bool EvaluateComplex(const Expr *E, ComplexValue &Res, EvalInfo &Info); -static bool EvaluateAtomic(const Expr *E, APValue &Result, EvalInfo &Info); +static bool EvaluateAtomic(const Expr *E, const LValue *This, APValue &Result, + EvalInfo &Info); static bool EvaluateAsRValue(EvalInfo &Info, const Expr *E, APValue &Result); //===----------------------------------------------------------------------===// @@ -4691,7 +4692,10 @@ class ExprEvaluatorBase (public) case CK_AtomicToNonAtomic: { APValue AtomicVal; - if (!EvaluateAtomic(E->getSubExpr(), AtomicVal, Info)) + // This does not need to be done in place even for class/array types: + // atomic-to-non-atomic conversion implies copying the object + // representation. + if (!Evaluate(AtomicVal, Info, E->getSubExpr())) return false; return DerivedSuccess(AtomicVal, E); } @@ -9565,10 +9569,11 @@ bool ComplexExprEvaluator::VisitInitListExpr(const Ini namespace { class AtomicExprEvaluator : public ExprEvaluatorBase { + const LValue *This; APValue &Result; public: - AtomicExprEvaluator(EvalInfo &Info, APValue &Result) - : ExprEvaluatorBaseTy(Info), Result(Result) {} + AtomicExprEvaluator(EvalInfo &Info, const LValue *This, APValue &Result) + : ExprEvaluatorBaseTy(Info), This(This), Result(Result) {} bool Success(const APValue &V, const Expr *E) { Result = V; @@ -9578,7 +9583,10 @@ class AtomicExprEvaluator : (public) bool ZeroInitialization(const Expr *E) { ImplicitValueInitExpr VIE( E->getType()->castAs()->getValueType()); - return Evaluate(Result, Info, &VIE); + // For atomic-qualified class (and array) types in C++, initialize the + // _Atomic-wrapped subobject directly, in-place. + return This ? EvaluateInPlace(Result, Info, *This, &VIE) + : Evaluate(Result, Info, &VIE); } bool VisitCastExpr(const CastExpr *E) { @@ -9586,15 +9594,17 @@ class AtomicExprEvaluator : (public) default: return ExprEvaluatorBaseTy::VisitCastExpr(E); case CK_NonAtomicToAtomic: - return Evaluate(Result, Info, E->getSubExpr()); + return This ? EvaluateInPlace(Result, Info, *This, E->getSubExpr()) + : Evaluate(Result, Info, E->getSubExpr()); } } }; } // end anonymous namespace -static bool EvaluateAtomic(const Expr *E, APValue &Result, EvalInfo &Info) { +static bool EvaluateAtomic(const Expr *E, const LValue *This, APValue &Result, + EvalInfo &Info) { assert(E->isRValue() && E->getType()->isAtomicType()); - return AtomicExprEvaluator(Info, Result).Visit(E); + return AtomicExprEvaluator(Info, This, Result).Visit(E); } //===----------------------------------------------------------------------===// @@ -9699,8 +9709,17 @@ static bool Evaluate(APValue &Result, EvalInfo &Info, if (!EvaluateVoid(E, Info)) return false; } else if (T->isAtomicType()) { - if (!EvaluateAtomic(E, Result, Info)) - return false; + QualType Unqual = T.getAtomicUnqualifiedType(); + if (Unqual->isArrayType() || Unqual->isRecordType()) { + LValue LV; + LV.set(E, Info.CurrentCall->Index); + APValue &Value = Info.CurrentCall->createTemporary(E, false); + if (!EvaluateAtomic(E, &LV, Value, Info)) + return false; + } else { + if (!EvaluateAtomic(E, nullptr, Result, Info)) + return false; + } } else if (Info.getLangOpts().CPlusPlus11) { Info.FFDiag(E, diag::note_constexpr_nonliteral) << E->getType(); return false; @@ -9725,10 +9744,16 @@ static bool EvaluateInPlace(APValue &Result, EvalInfo if (E->isRValue()) { // Evaluate arrays and record types in-place, so that later initializers can // refer to earlier-initialized members of the object. - if (E->getType()->isArrayType()) + QualType T = E->getType(); + if (T->isArrayType()) return EvaluateArray(E, This, Result, Info); - else if (E->getType()->isRecordType()) + else if (T->isRecordType()) return EvaluateRecord(E, This, Result, Info); + else if (T->isAtomicType()) { + QualType Unqual = T.getAtomicUnqualifiedType(); + if (Unqual->isArrayType() || Unqual->isRecordType()) + return EvaluateAtomic(E, &This, Result, Info); + } } // For any other type, in-place evaluation is unimportant.