]> granicus.if.org Git - clang/commitdiff
Diagnose attempt to take address of bitfield members in anonymous structs.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 13 Apr 2017 21:49:46 +0000 (21:49 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 13 Apr 2017 21:49:46 +0000 (21:49 +0000)
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

lib/Sema/SemaExpr.cpp
test/Sema/expr-address-of.c
test/SemaCXX/ptrtomember.cpp

index 73baf1a660f81cddc0608f228712d2048558f692..bb174521c72c7cb5be8e98dbc01b50e2b1a1f0ca 100644 (file)
@@ -1772,7 +1772,10 @@ Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK,
       !Diags.isIgnored(diag::warn_arc_repeated_use_of_weak, E->getLocStart()))
       recordUseOfEvaluatedWeak(E);
 
-  if (FieldDecl *FD = dyn_cast<FieldDecl>(D)) {
+  FieldDecl *FD = dyn_cast<FieldDecl>(D);
+  if (IndirectFieldDecl *IFD = dyn_cast<IndirectFieldDecl>(D))
+    FD = IFD->getAnonField();
+  if (FD) {
     UnusedPrivateFields.remove(FD);
     // Just in case we're building an illegal pointer-to-member.
     if (FD->isBitField())
index 32bd0dfdd5b0e56b80056c6896ff2a8b5e495437..480871afad2a59ad37fedc0a845af7f835109a42 100644 (file)
@@ -102,8 +102,9 @@ char* f7() {
   register struct {char* x;} t1 = {"Hello"};
   char* dummy1 = &(t1.x[0]);
 
-  struct {int a : 10;} t2;
+  struct {int a : 10; struct{int b : 10;};} t2;
   int* dummy2 = &(t2.a); // expected-error {{address of bit-field requested}}
+  int* dummy3 = &(t2.b); // expected-error {{address of bit-field requested}}
 
   void* t3 = &(*(void*)0);
 }
index aee535e5593b10ca38cc64ceadc6c2dd29097dc6..d4a4507d02a5c2f180aae23e810b84abc9fa5f18 100644 (file)
@@ -13,9 +13,13 @@ int foo(int S::* ps, S *s)
 
 struct S2 {
   int bitfield : 1;
+  struct {
+    int anon_bitfield : 1;
+  };
 };
 
 int S2::*pf = &S2::bitfield; // expected-error {{address of bit-field requested}}
+int S2::*anon_pf = &S2::anon_bitfield; // expected-error {{address of bit-field requested}}
 
 struct S3 {
   void m();