Skip to content

Commit 18974a9

Browse files
committed
Diagnose attempt to take address of bitfield members in anonymous structs.
Patch by Jacob Young! Differential Revision: https://reviews.llvm.org/D27263 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300264 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 24a137e commit 18974a9

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

lib/Sema/SemaExpr.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,10 @@ Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
17721772
!Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getLocStart()))
17731773
recordUseOfEvaluatedWeak(E);
17741774

1775-
if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
1775+
FieldDecl *FD = dyn_cast<FieldDecl>(D);
1776+
if (IndirectFieldDecl *IFD = dyn_cast<IndirectFieldDecl>(D))
1777+
FD = IFD->getAnonField();
1778+
if (FD) {
17761779
UnusedPrivateFields.remove(FD);
17771780
// Just in case we're building an illegal pointer-to-member.
17781781
if (FD->isBitField())

test/Sema/expr-address-of.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ char* f7() {
102102
register struct {char* x;} t1 = {"Hello"};
103103
char* dummy1 = &(t1.x[0]);
104104

105-
struct {int a : 10;} t2;
105+
struct {int a : 10; struct{int b : 10;};} t2;
106106
int* dummy2 = &(t2.a); // expected-error {{address of bit-field requested}}
107+
int* dummy3 = &(t2.b); // expected-error {{address of bit-field requested}}
107108

108109
void* t3 = &(*(void*)0);
109110
}

test/SemaCXX/ptrtomember.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ int foo(int S::* ps, S *s)
1313

1414
struct S2 {
1515
int bitfield : 1;
16+
struct {
17+
int anon_bitfield : 1;
18+
};
1619
};
1720

1821
int S2::*pf = &S2::bitfield; // expected-error {{address of bit-field requested}}
22+
int S2::*anon_pf = &S2::anon_bitfield; // expected-error {{address of bit-field requested}}
1923

2024
struct S3 {
2125
void m();

0 commit comments

Comments
 (0)