Annotation of /trunk/llvm/patches/clang-15.0.7-bitfield-value-capture.patch
Parent Directory | Revision Log
Revision 3753 -
(hide annotations)
(download)
Fri Aug 4 08:32:09 2023 UTC (10 months ago) by niro
File size: 4175 byte(s)
Fri Aug 4 08:32:09 2023 UTC (10 months ago) by niro
File size: 4175 byte(s)
-llcm/clang patches for 15.0.7
1 | niro | 3753 | From a1a71b7dc97b35133425a31ede90c40529f1be9e Mon Sep 17 00:00:00 2001 |
2 | From: Corentin Jabot <corentinjabot@gmail.com> | ||
3 | Date: Thu, 4 Aug 2022 23:02:17 +0200 | ||
4 | Subject: [PATCH] [Clang] Fix capture of values initialized by bitfields | ||
5 | |||
6 | This fixes a regression introduced in 127bf44 | ||
7 | |||
8 | Differential Revision: https://reviews.llvm.org/D131202 | ||
9 | --- | ||
10 | .../clang/Basic/DiagnosticSemaKinds.td | 2 -- | ||
11 | clang/lib/Sema/SemaExpr.cpp | 28 ++----------------- | ||
12 | clang/test/SemaCXX/cxx1z-decomposition.cpp | 6 ++-- | ||
13 | 3 files changed, 5 insertions(+), 31 deletions(-) | ||
14 | |||
15 | diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td | ||
16 | index 550ad5ab73c642..13209d3bff24ff 100644 | ||
17 | --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td | ||
18 | +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td | ||
19 | @@ -9013,8 +9013,6 @@ def ext_ms_anonymous_record : ExtWarn< | ||
20 | def err_reference_to_local_in_enclosing_context : Error< | ||
21 | "reference to local %select{variable|binding}1 %0 declared in enclosing " | ||
22 | "%select{%3|block literal|lambda expression|context}2">; | ||
23 | -def err_bitfield_capture_by_ref : Error< | ||
24 | - "cannot capture a bit-field by reference">; | ||
25 | def err_capture_binding_openmp : Error< | ||
26 | "capturing a structured binding is not yet supported in OpenMP">; | ||
27 | def ext_capture_binding : ExtWarn< | ||
28 | diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp | ||
29 | index 9497c4b5d53004..152f15159fa1f9 100644 | ||
30 | --- a/clang/lib/Sema/SemaExpr.cpp | ||
31 | +++ b/clang/lib/Sema/SemaExpr.cpp | ||
32 | @@ -18533,32 +18533,8 @@ static bool captureInLambda(LambdaScopeInfo *LSI, ValueDecl *Var, | ||
33 | } else { | ||
34 | ByRef = (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref); | ||
35 | } | ||
36 | - // C++20 : [expr.prim.lambda.capture]p12 | ||
37 | - // A bit-field or a member of an anonymous union shall | ||
38 | - // not be captured by reference. | ||
39 | - MemberExpr *ME = nullptr; | ||
40 | - BindingDecl *BD = nullptr; | ||
41 | - if (auto *V = dyn_cast<VarDecl>(Var)) { | ||
42 | - if (V->getInit()) | ||
43 | - ME = dyn_cast<MemberExpr>(V->getInit()->IgnoreImplicit()); | ||
44 | - } else if ((BD = dyn_cast<BindingDecl>(Var))) { | ||
45 | - ME = dyn_cast_or_null<MemberExpr>(BD->getBinding()); | ||
46 | - } | ||
47 | - | ||
48 | - // Capturing a bitfield by reference is not allowed except in OpenMP. | ||
49 | - if (ByRef && ME && | ||
50 | - (isa<BindingDecl>(Var) || !S.LangOpts.OpenMP || | ||
51 | - !S.isOpenMPCapturedDecl(Var))) { | ||
52 | - const auto *FD = dyn_cast_or_null<FieldDecl>(ME->getMemberDecl()); | ||
53 | - if (FD && FD->isBitField()) { | ||
54 | - if (BuildAndDiagnose) { | ||
55 | - S.Diag(Loc, diag::err_bitfield_capture_by_ref) << Var; | ||
56 | - S.Diag(Var->getLocation(), diag::note_entity_declared_at) << Var; | ||
57 | - S.Diag(FD->getLocation(), diag::note_bitfield_decl) << FD; | ||
58 | - } | ||
59 | - Invalid = true; | ||
60 | - } | ||
61 | - } | ||
62 | + | ||
63 | + BindingDecl *BD = dyn_cast<BindingDecl>(Var); | ||
64 | // FIXME: We should support capturing structured bindings in OpenMP. | ||
65 | if (!Invalid && BD && S.LangOpts.OpenMP) { | ||
66 | if (BuildAndDiagnose) { | ||
67 | diff --git a/clang/test/SemaCXX/cxx1z-decomposition.cpp b/clang/test/SemaCXX/cxx1z-decomposition.cpp | ||
68 | index 7165f30dc07030..13fe826759a347 100644 | ||
69 | --- a/clang/test/SemaCXX/cxx1z-decomposition.cpp | ||
70 | +++ b/clang/test/SemaCXX/cxx1z-decomposition.cpp | ||
71 | @@ -84,9 +84,9 @@ void enclosing() { | ||
72 | |||
73 | (void)[outerbit1]{}; // expected-error {{'outerbit1' cannot be captured because it does not have automatic storage duration}} | ||
74 | |||
75 | - auto [bit, var] = S2{1, 1}; // expected-note 4{{'bit' declared here}} | ||
76 | + auto [bit, var] = S2{1, 1}; // expected-note 2{{'bit' declared here}} | ||
77 | |||
78 | - (void)[&bit] { // expected-error {{cannot capture a bit-field by reference}} \ | ||
79 | + (void)[&bit] { // expected-error {{non-const reference cannot bind to bit-field 'a'}} \ | ||
80 | // expected-warning {{C++20}} | ||
81 | return bit; | ||
82 | }; | ||
83 | @@ -96,7 +96,7 @@ void enclosing() { | ||
84 | }; | ||
85 | |||
86 | (void)[&] { return bit + u; } // expected-error {{unnamed variable cannot be implicitly captured in a lambda expression}} \ | ||
87 | - // expected-error {{cannot capture a bit-field by reference}} \ | ||
88 | + // expected-error {{non-const reference cannot bind to bit-field 'a'}} \ | ||
89 | // expected-warning {{C++20}} | ||
90 | (); | ||
91 | } |