[cfe-commits] r117842 - in /cfe/trunk: lib/AST/Expr.cpp test/SemaCXX/ptrtomember.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Sat Oct 30 12:52:22 PDT 2010


Author: akirtzidis
Date: Sat Oct 30 14:52:22 2010
New Revision: 117842

URL: http://llvm.org/viewvc/llvm-project?rev=117842&view=rev
Log:
Emit an error when trying to form a pointer-to-member to a bitfield.

As a bonus, avoids a crash on the IRGen side due to accepting invalid code.

Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/SemaCXX/ptrtomember.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=117842&r1=117841&r2=117842&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sat Oct 30 14:52:22 2010
@@ -1930,6 +1930,11 @@
       if (Field->isBitField())
         return Field;
 
+  if (DeclRefExpr *DeclRef = dyn_cast<DeclRefExpr>(E))
+    if (FieldDecl *Field = dyn_cast<FieldDecl>(DeclRef->getDecl()))
+      if (Field->isBitField())
+        return Field;
+
   if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E))
     if (BinOp->isAssignmentOp() && BinOp->getLHS())
       return BinOp->getLHS()->getBitField();

Modified: cfe/trunk/test/SemaCXX/ptrtomember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ptrtomember.cpp?rev=117842&r1=117841&r2=117842&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ptrtomember.cpp (original)
+++ cfe/trunk/test/SemaCXX/ptrtomember.cpp Sat Oct 30 14:52:22 2010
@@ -11,3 +11,8 @@
     return (s->*ps)(1); // expected-error {{called object type 'int' is not a function or function pointer}}
 }
 
+struct S2 {
+  int bitfield : 1;
+};
+
+int S2::*pf = &S2::bitfield; // expected-error {{address of bit-field requested}}





More information about the cfe-commits mailing list