[cfe-commits] r129783 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/ExprClassification.cpp test/Sema/expr-address-of.c

Peter Collingbourne peter at pcc.me.uk
Tue Apr 19 11:51:51 PDT 2011


Author: pcc
Date: Tue Apr 19 13:51:51 2011
New Revision: 129783

URL: http://llvm.org/viewvc/llvm-project?rev=129783&view=rev
Log:
Add a new expression classification, CL_AddressableVoid

CL_AddressableVoid is the expression classification used for void
expressions whose address can be taken, i.e. the result of [], *
or void variable references in C, as opposed to things like the
result of a void function call.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/ExprClassification.cpp
    cfe/trunk/test/Sema/expr-address-of.c

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=129783&r1=129782&r2=129783&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Apr 19 13:51:51 2011
@@ -221,6 +221,7 @@
       CL_XValue,
       CL_Function, // Functions cannot be lvalues in C.
       CL_Void, // Void cannot be an lvalue in C.
+      CL_AddressableVoid, // Void expression whose address can be taken in C.
       CL_DuplicateVectorComponents, // A vector shuffle with dupes.
       CL_MemberFunction, // An expression referring to a member function
       CL_SubObjCPropertySetting,

Modified: cfe/trunk/lib/AST/ExprClassification.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprClassification.cpp?rev=129783&r1=129782&r2=129783&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprClassification.cpp (original)
+++ cfe/trunk/lib/AST/ExprClassification.cpp Tue Apr 19 13:51:51 2011
@@ -61,8 +61,10 @@
     if (TR->isFunctionType() || TR == Ctx.OverloadTy)
       kind = Cl::CL_Function;
     // No void either, but qualified void is OK because it is "other than void".
-    else if (TR->isVoidType() && !Ctx.getCanonicalType(TR).hasQualifiers())
-      kind = Cl::CL_Void;
+    // Void "lvalues" are classified as addressable void values, which are void
+    // expressions whose address can be taken.
+    else if (TR->isVoidType() && !TR.hasQualifiers())
+      kind = (kind == Cl::CL_LValue ? Cl::CL_AddressableVoid : Cl::CL_Void);
   }
 
   // Enable this assertion for testing.
@@ -71,6 +73,7 @@
   case Cl::CL_XValue: assert(getValueKind() == VK_XValue); break;
   case Cl::CL_Function:
   case Cl::CL_Void:
+  case Cl::CL_AddressableVoid:
   case Cl::CL_DuplicateVectorComponents:
   case Cl::CL_MemberFunction:
   case Cl::CL_SubObjCPropertySetting:
@@ -563,7 +566,8 @@
   case Cl::CL_LValue: return LV_Valid;
   case Cl::CL_XValue: return LV_InvalidExpression;
   case Cl::CL_Function: return LV_NotObjectType;
-  case Cl::CL_Void: return LV_IncompleteVoidType;
+  case Cl::CL_Void: return LV_InvalidExpression;
+  case Cl::CL_AddressableVoid: return LV_IncompleteVoidType;
   case Cl::CL_DuplicateVectorComponents: return LV_DuplicateVectorComponents;
   case Cl::CL_MemberFunction: return LV_MemberFunction;
   case Cl::CL_SubObjCPropertySetting: return LV_SubObjCPropertySetting;
@@ -582,7 +586,8 @@
   case Cl::CL_LValue: break;
   case Cl::CL_XValue: return MLV_InvalidExpression;
   case Cl::CL_Function: return MLV_NotObjectType;
-  case Cl::CL_Void: return MLV_IncompleteVoidType;
+  case Cl::CL_Void: return MLV_InvalidExpression;
+  case Cl::CL_AddressableVoid: return MLV_IncompleteVoidType;
   case Cl::CL_DuplicateVectorComponents: return MLV_DuplicateVectorComponents;
   case Cl::CL_MemberFunction: return MLV_MemberFunction;
   case Cl::CL_SubObjCPropertySetting: return MLV_SubObjCPropertySetting;

Modified: cfe/trunk/test/Sema/expr-address-of.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/expr-address-of.c?rev=129783&r1=129782&r2=129783&view=diff
==============================================================================
--- cfe/trunk/test/Sema/expr-address-of.c (original)
+++ cfe/trunk/test/Sema/expr-address-of.c Tue Apr 19 13:51:51 2011
@@ -107,3 +107,14 @@
 
   void* t3 = &(*(void*)0);
 }
+
+void f8() {
+  void *dummy0 = &f8(); // expected-error {{address expression must be an lvalue or a function designator}}
+
+  extern void v;
+  void *dummy1 = &(1 ? v : f8()); // expected-error {{address expression must be an lvalue or a function designator}}
+
+  void *dummy2 = &(f8(), v); // expected-error {{address expression must be an lvalue or a function designator}}
+
+  void *dummy3 = &({ ; }); // expected-error {{address expression must be an lvalue or a function designator}}
+}





More information about the cfe-commits mailing list