From nobody Fri Apr 28 14:13:21 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q7F294DG3z48Wck; Fri, 28 Apr 2023 14:13:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q7F293KqGz3xJJ; Fri, 28 Apr 2023 14:13:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682691201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VR+XoJyGEVIthKNIOG9tTpPP7IsCvMHKbc709/wBKSw=; b=eZNjH5xkpOgjCkgHzAuP17paTJzGGKGW0W8REitvahOujOYIsChdYXb3UJekpFbNGbVScQ 23ZEfaKSwUpH/DDunmHCSmUY+uLZ2xl2MP2TyUYePCcL2kq/c3Hntjkt4p3uTpvDmprkQR dCqjgtjyNMyE4G7XaMC0Uwia8NwTXhDKZB59HVn7Vs4dykGogOXaFOBWhpb5YSAfT1h56M iTN5b8U9nNbeJQl5LV/rMqB9Bt/9Z14/6J8NlzL+/9vrtw7u6Q1HrPaKb1rzkijBVG1W8A GuRQ0+jxhhPG8OOgtUf6dTQtj7TAqXJE5ub5kbOMKG8yEPH8Zx0j8VXr+tDvXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682691201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VR+XoJyGEVIthKNIOG9tTpPP7IsCvMHKbc709/wBKSw=; b=UScM2Fvz96azBycDfy3BlfVf5wU5WijNH8zBbYAFc2NTBqpb4xiD5JpxJSVITxAlYtKK2e EV4y9wNjMVMektk4VxhMYOSab7bi023A/84toLtAsEAsSQc3oLyBvTQvvfbwSGzgjiLrUV j1uBTxu0ez9Tb6APNDqKQ6cva+AN8Y94KhRsCBHkziQCOMQ2U7T++VxuWOvzaO3XcIhxwo uFgvBYqsOHekGbWauFxz5gAQIh50pyCNjUwG9obnhoL44JGMjzWUf+jyQ9E2oXv/EAEBLd 2Lt+RZWcDCdBxmAOPj9FvSILSqw1pwgYykPML7rM3LqBgTmAlt+o0j00rO2k+w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682691201; a=rsa-sha256; cv=none; b=HINGjU4EhSzZLQZ8YcRXU56G/MCvJjFX6RVMhQO32GLesQ+jfWVEZoTIvvtHK9RSIdSkLs 8WiHdhMvGQt6crL4VC02CW78m0163c098TjypP7fK2ai/QKTxhwxfm10Pkek5V3usQzUlF 5WMKC8osfms1U2LUyeI4jW8T2x2dUMXU3syK0Vam0Yg36a9JJGJK3HVEGN1tP/ARu/yW86 h3nf6Lzobc5LC31YujQidW3imDGTEqx3FvBAByO+zFkoqFnAGwb8T3nzyAcUgrkII2qJ4A CzRNIYTe3vp8D6i7Nlxd9d6Yu4MY5xColxtavhUaiscwMokXkkCxNm7RhB46iQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Q7F292MVLz12bm; Fri, 28 Apr 2023 14:13:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33SEDLlp046431; Fri, 28 Apr 2023 14:13:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33SEDLe5046430; Fri, 28 Apr 2023 14:13:21 GMT (envelope-from git) Date: Fri, 28 Apr 2023 14:13:21 GMT Message-Id: <202304281413.33SEDLe5046430@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dimitry Andric Subject: git: 56f2446575c7 - main - Apply clang fix for assertion building emulators/rpcs3 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 56f2446575c78d962b6dda5e3310bec078622f3d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=56f2446575c78d962b6dda5e3310bec078622f3d commit 56f2446575c78d962b6dda5e3310bec078622f3d Author: Dimitry Andric AuthorDate: 2023-04-28 14:08:42 +0000 Commit: Dimitry Andric CommitDate: 2023-04-28 14:09:45 +0000 Apply clang fix for assertion building emulators/rpcs3 Merge commit a5e1a93ea10f from llvm-project (by Mariya Podchishchaeva): [clang] Fix crash when handling nested immediate invocations Before this patch it was expected that if there was several immediate invocations they all belong to the same expression evaluation context. During parsing of non local variable initializer a new evaluation context is pushed, so code like this ``` namespace scope { struct channel { consteval channel(const char* name) noexcept { } }; consteval const char* make_channel_name(const char* name) { return name;} channel rsx_log(make_channel_name("rsx_log")); } ``` produced a nested immediate invocation whose subexpressions are attached to different expression evaluation contexts. The constructor call belongs to TU context and `make_channel_name` call to context of variable initializer. This patch removes this assumption and adds tracking of previously failed immediate invocations, so it is possible when handling an immediate invocation th check that its subexpressions from possibly another evaluation context contains errors and not produce duplicate diagnostics. Fixes https://github.com/llvm/llvm-project/issues/58207 Reviewed By: aaron.ballman, shafik Differential Revision: https://reviews.llvm.org/D146234 PR: 269489 MFC after: 3 days --- .../llvm-project/clang/include/clang/Sema/Sema.h | 3 +++ contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp | 26 +++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/contrib/llvm-project/clang/include/clang/Sema/Sema.h b/contrib/llvm-project/clang/include/clang/Sema/Sema.h index 681a76dfa56a..53257a1bb028 100644 --- a/contrib/llvm-project/clang/include/clang/Sema/Sema.h +++ b/contrib/llvm-project/clang/include/clang/Sema/Sema.h @@ -1365,6 +1365,9 @@ public: /// A stack of expression evaluation contexts. SmallVector ExprEvalContexts; + // Set of failed immediate invocations to avoid double diagnosing. + llvm::SmallPtrSet FailedImmediateInvocations; + /// Emit a warning for all pending noderef expressions that we recorded. void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec); diff --git a/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp b/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp index 83081bbf0aa0..a8fe9a68c8cb 100644 --- a/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp +++ b/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp @@ -17529,6 +17529,7 @@ static void EvaluateAndDiagnoseImmediateInvocation( bool Result = CE->EvaluateAsConstantExpr( Eval, SemaRef.getASTContext(), ConstantExprKind::ImmediateInvocation); if (!Result || !Notes.empty()) { + SemaRef.FailedImmediateInvocations.insert(CE); Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit(); if (auto *FunctionalCast = dyn_cast(InnerExpr)) InnerExpr = FunctionalCast->getSubExpr(); @@ -17567,10 +17568,16 @@ static void RemoveNestedImmediateInvocation( [E](Sema::ImmediateInvocationCandidate Elem) { return Elem.getPointer() == E; }); - assert(It != IISet.rend() && - "ConstantExpr marked IsImmediateInvocation should " - "be present"); - It->setInt(1); // Mark as deleted + // It is possible that some subexpression of the current immediate + // invocation was handled from another expression evaluation context. Do + // not handle the current immediate invocation if some of its + // subexpressions failed before. + if (It == IISet.rend()) { + if (SemaRef.FailedImmediateInvocations.contains(E)) + CurrentII->setInt(1); + } else { + It->setInt(1); // Mark as deleted + } } ExprResult TransformConstantExpr(ConstantExpr *E) { if (!E->isImmediateInvocation()) @@ -17639,10 +17646,13 @@ HandleImmediateInvocations(Sema &SemaRef, SemaRef.RebuildingImmediateInvocation) return; - /// When we have more then 1 ImmediateInvocationCandidates we need to check - /// for nested ImmediateInvocationCandidates. when we have only 1 we only - /// need to remove ReferenceToConsteval in the immediate invocation. - if (Rec.ImmediateInvocationCandidates.size() > 1) { + /// When we have more than 1 ImmediateInvocationCandidates or previously + /// failed immediate invocations, we need to check for nested + /// ImmediateInvocationCandidates in order to avoid duplicate diagnostics. + /// Otherwise we only need to remove ReferenceToConsteval in the immediate + /// invocation. + if (Rec.ImmediateInvocationCandidates.size() > 1 || + !SemaRef.FailedImmediateInvocations.empty()) { /// Prevent sema calls during the tree transform from adding pointers that /// are already in the sets.