From nobody Wed May 3 10:41:10 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 4QBD525Wt7z49C9r; Wed, 3 May 2023 10:41:10 +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 4QBD524zMVz3PZ0; Wed, 3 May 2023 10:41:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683110470; 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=1VMl2IL7xJhzduYtkenpFXS936VO0qBFijss3868g8M=; b=c4Veo9D7+xGrxp6IWyx0vuAq2N0HbFVli1sFYrPiIM1Q8ZNjbScd31KYc2smbkmEyyIlG2 HmOLT9ayzUPP0KtTgarvD5f94FeKy84lCldbl9+y/15dSW9o/GP0sF6ZIgCQjFM1TZGdk5 6tVf8lR4KSUIZORGnFr3pejvsjRW1DCJJbkJg4dBik3qDDnRaae5NafLOdsw/jWOhmCYer SopzytJOVaOtu8xlgG9P3BwkBlFBjEgMD2GYlXqlwSZ14H2cWEZL+FKQccjJS5rQwC/rv+ CF3GEEBc+KBUer48GyyllQ5LuJPxHtpUICC1/hHgdrz7vxv1pdAEMwN9eqtOKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683110470; 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=1VMl2IL7xJhzduYtkenpFXS936VO0qBFijss3868g8M=; b=uY01ffaLT4wvvKM07G06g8LheHh6muljFpvlBKp/9B8DTU79iAxTAPqO7Zablt5JssGgc1 u9KTUAIcGjn7nHCxqFr5OP4JQmgssmXv0O0bc+dqvcqQ3GghGTiEZEXo7rv/M1FIyoSHgr 638v1S5O5gxZqG0C7OhuuXiKVcV5rbNlee3DspF+7Jt1t99Blw6hqcjck0r+rUgy3djBRk z7BVmG5Z8TUf+yWr973dvECpQRK0GvPc1zxP9KM3gatv5ABKddAvMLKpzhTLEVpY4pe0sH egxv2E/VclbU7FX2UF8LGA9XsNLZ6imDVApP11F0aiL0K50Gxh7H4Ps0yLHOAA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683110470; a=rsa-sha256; cv=none; b=Xu3ERPgrYBfr0fd0wn8gsEHkU8sdO5Hb2VyJtRvZgB362EC2DHlagLyCFKtDs81eqPjLdE bC3dUl5JVLoNOgWlLCsFtZBkVVuaTb9DnLoY6QIF5cFzVMTbaPs02+oza6uS2omE7byMOl 511a/VdyZSPtyDjIj37p0iZkrDK0wO86E9DF0U/+X6edC0i7NzhmqxvESdndqq7DxLhhsN L/8hAaYUjRwI/miQ82rja13B4nJPkPUcl3+uuF1lEJhmdjmEp+My6I8gr+aujrg5iEB++/ fETeBmSIArC8SYEC2d74fBGGqw3OIt9yhQ5m8txDpW+JxvRp3JvzRjFYuZ/IzQ== 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 4QBD5241xXzRXJ; Wed, 3 May 2023 10:41:10 +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 343AfAPX092454; Wed, 3 May 2023 10:41:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 343AfAIk092453; Wed, 3 May 2023 10:41:10 GMT (envelope-from git) Date: Wed, 3 May 2023 10:41:10 GMT Message-Id: <202305031041.343AfAIk092453@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: a7e6ae2dc64b - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: a7e6ae2dc64b313520adc6141e4cffb1fa962b66 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=a7e6ae2dc64b313520adc6141e4cffb1fa962b66 commit a7e6ae2dc64b313520adc6141e4cffb1fa962b66 Author: Dimitry Andric AuthorDate: 2023-04-28 14:08:42 +0000 Commit: Dimitry Andric CommitDate: 2023-05-03 08:18:46 +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 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.