From nobody Wed May 03 10:41:32 2023 X-Original-To: dev-commits-src-branches@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 4QBD5T2T2Kz49CWQ; Wed, 3 May 2023 10:41:33 +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 4QBD5T1RVtz3R6c; Wed, 3 May 2023 10:41:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683110493; 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=+oqnNuD2IUOqYlYYhqa2Y1IVl5XMeRsiyoPTMfLo7uI=; b=yq77suBcT0vCtLnO4qonUo6xztFHeOE6EZm2ef/I6YGk/pAnFm0n8gfqHVR8uuCiZOel4y eIezHcZqbLOllb6g7PU5VuPR/fusWvt8co3iNdQ9IVN9oe3N9JuuvL0OvOxIxvUxY6yPNx j+4VDORqx5w6iLgqxr9MRBiqhARghumaE9tajbbngeXWgenqSUbIu6ShKCjVzLs+NXIdYs oVVoigZ6bFFyoDFP3gx7L8XAIcXlQJWA95GWl6vxp+lBPL/zCiUAs5kEIGoKlTT/0pUzfh QYmYLqVoO2rH+Pk9eUGZr65QeB+548kHbnxMgYfMNIzEZYpZUDj8leokFXYmGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683110493; 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=+oqnNuD2IUOqYlYYhqa2Y1IVl5XMeRsiyoPTMfLo7uI=; b=BxzYFTTfyjqzOCuI1YknjLYQM85DB9G5FuTcGNS/ul5lF/eeHB15/Oh1/jnVfZYLv4KZCg vCWwjWWB3N0/+0P+MUUKsEAmQidO/EWt+BSIt8mS/BvF25E2ZzbYRrfuJtZR5YCtq2iv3T xOmX8tmhNsVimtZL7LCahRtIBTFMr9rqhwlAQRtoQqX89zmm3FIDjK45F9RwXVQB5ebuqP araUBFROwEwPh1bQo0czPGbMGuzaBPvu5aJtBYUNpJB+5cVDS/0KyKy/KbT6p2sjCxppU8 dAZVjcsFhIcfbz+sspOifqfWSj9s1lZzU5R1VQY4UbfUHhlVMEpQu1D/2M9KsA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683110493; a=rsa-sha256; cv=none; b=E2O+v54ylYgfQp1W8oOzJKwlWzo//fwia2AKrM02swooI3PCeM9FRr5J/9jTPzpTMyO7/5 G+TKfNWg3xKbP19OKTWG9foL9Ud+fokVF5ffaWEm7Gfv7NTRTXl71OQsUN7TNd5hmUWs2G Ihg1w2OgZxD4QxcK4stc/uPHB/R9NDDneR/muz3r2nEeVbzvmA4opPYmmN77c08oyzw1gO ADYNmfDRf4rd0ajsoZiUq10ULfx564Z1C7EHuFQYAY6BgnN+MQx5pPnNxFLIiNim+L1K9l JFc6DShtRmwFiQPIJASCSPlIIiZKaxVssLoUD34aTTiHJZbmK7AAh2OqUfeTNQ== 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 4QBD5T0XS5zRFd; Wed, 3 May 2023 10:41:33 +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 343AfWDP092698; Wed, 3 May 2023 10:41:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 343AfWki092697; Wed, 3 May 2023 10:41:32 GMT (envelope-from git) Date: Wed, 3 May 2023 10:41:32 GMT Message-Id: <202305031041.343AfWki092697@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: 44f4aaee6be3 - stable/12 - Apply clang fix for assertion building emulators/rpcs3 List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/12 X-Git-Reftype: branch X-Git-Commit: 44f4aaee6be33d7e2afe3ce0f0fb856e83da01d7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=44f4aaee6be33d7e2afe3ce0f0fb856e83da01d7 commit 44f4aaee6be33d7e2afe3ce0f0fb856e83da01d7 Author: Dimitry Andric AuthorDate: 2023-04-28 14:08:42 +0000 Commit: Dimitry Andric CommitDate: 2023-05-03 08:25:29 +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 (cherry picked from commit 56f2446575c78d962b6dda5e3310bec078622f3d) --- .../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 d8b2546b81a3..aaec49abfd5b 100644 --- a/contrib/llvm-project/clang/include/clang/Sema/Sema.h +++ b/contrib/llvm-project/clang/include/clang/Sema/Sema.h @@ -1314,6 +1314,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 f04eb9199024..f84b3d9c468d 100644 --- a/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp +++ b/contrib/llvm-project/clang/lib/Sema/SemaExpr.cpp @@ -16642,6 +16642,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(); @@ -16680,10 +16681,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()) @@ -16747,10 +16754,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.