Do not treat @selector as lvalue (unlike g++).
Patch by Nico Weber (pr7390).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106242 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index 1d715b0..e36ae41 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -1194,7 +1194,6 @@
   case ObjCIsaExprClass:
   case StringLiteralClass:  // C99 6.5.1p4
   case ObjCEncodeExprClass: // @encode behaves like its string in every way.
-  case ObjCSelectorExprClass: // @selector
     return LV_Valid;
   case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2))))
     // For vectors, make sure base is an lvalue (i.e. not a function call).
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index ae56018..fa403c7 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -6060,6 +6060,8 @@
       << op->getType() << op->getSourceRange();
     if (isSFINAEContext())
       return QualType();
+  } else if (isa<ObjCSelectorExpr>(op)) {
+      return Context.getPointerType(op->getType());
   } else if (lval != Expr::LV_Valid && lval != Expr::LV_IncompleteVoidType) {
     // C99 6.5.3.2p1
     // The operand must be either an l-value or a function designator
diff --git a/test/CodeGenCXX/sel-address.mm b/test/CodeGenCXX/sel-address.mm
new file mode 100644
index 0000000..c3db9a7
--- /dev/null
+++ b/test/CodeGenCXX/sel-address.mm
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -verify -emit-llvm -o %t
+// pr7390
+
+void f(const SEL& v2) {}
+void g() {
+  f(@selector(dealloc));
+
+  SEL s = @selector(dealloc);
+ SEL* ps = &s;
+
+ @selector(dealloc) = s;  // expected-error {{expression is not assignable}}
+
+ SEL* ps2 = &@selector(dealloc);
+}
diff --git a/test/CodeGenObjCXX/selactor-expr-lvalue.mm b/test/CodeGenObjCXX/selactor-expr-lvalue.mm
index 69b82e9..0305451 100644
--- a/test/CodeGenObjCXX/selactor-expr-lvalue.mm
+++ b/test/CodeGenObjCXX/selactor-expr-lvalue.mm
@@ -2,7 +2,7 @@
 // PR7390
 
 @interface NSObject {}
-- (void)respondsToSelector:(SEL&)s : (SEL*)s1;
+- (void)respondsToSelector:(const SEL&)s : (SEL*)s1;
 - (void) setPriority:(int)p;
 - (void)Meth;
 @end
@@ -12,5 +12,5 @@
     [self respondsToSelector:@selector(setPriority:) : &@selector(setPriority:)];
 }
 - (void) setPriority:(int)p{}
-- (void)respondsToSelector:(SEL&)s : (SEL*)s1 {}
+- (void)respondsToSelector:(const SEL&)s : (SEL*)s1 {}
 @end