Merge remote-tracking branch 'origin/swift-3.1-branch' into stable

* origin/swift-3.1-branch:
  [CodeCompletion] Show protocol properties that are accessed through qualified id
  [Sema] Handle transparent_union attributes in C mode only
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td
index e12450b..f1af6fc 100644
--- a/include/clang/Basic/Attr.td
+++ b/include/clang/Basic/Attr.td
@@ -1596,6 +1596,7 @@
   let Spellings = [GCC<"transparent_union">];
 //  let Subjects = SubjectList<[Record, TypedefName]>;
   let Documentation = [Undocumented];
+  let LangOpts = [COnly];
 }
 
 def Unavailable : InheritableAttr {
diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp
index 36babc4..d235479 100644
--- a/lib/Sema/SemaCodeComplete.cpp
+++ b/lib/Sema/SemaCodeComplete.cpp
@@ -3720,20 +3720,21 @@
           Results.AddResult(Result("template"));
       }
     }
-  } else if (!IsArrow && BaseType->getAsObjCInterfacePointerType()) {
+  } else if (!IsArrow && BaseType->isObjCObjectPointerType()) {
     // Objective-C property reference.
     AddedPropertiesSet AddedProperties;
-    
-    // Add property results based on our interface.
-    const ObjCObjectPointerType *ObjCPtr
-      = BaseType->getAsObjCInterfacePointerType();
-    assert(ObjCPtr && "Non-NULL pointer guaranteed above!");
-    AddObjCProperties(CCContext, ObjCPtr->getInterfaceDecl(), true,
-                      /*AllowNullaryMethods=*/true, CurContext, 
-                      AddedProperties, Results);
-    
+
+    if (const ObjCObjectPointerType *ObjCPtr =
+            BaseType->getAsObjCInterfacePointerType()) {
+      // Add property results based on our interface.
+      assert(ObjCPtr && "Non-NULL pointer guaranteed above!");
+      AddObjCProperties(CCContext, ObjCPtr->getInterfaceDecl(), true,
+                        /*AllowNullaryMethods=*/true, CurContext,
+                        AddedProperties, Results);
+    }
+
     // Add properties from the protocols in a qualified interface.
-    for (auto *I : ObjCPtr->quals())
+    for (auto *I : BaseType->getAs<ObjCObjectPointerType>()->quals())
       AddObjCProperties(CCContext, I, true, /*AllowNullaryMethods=*/true,
                         CurContext, AddedProperties, Results);
   } else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||
diff --git a/test/CodeCompletion/objc-protocol-member-access.m b/test/CodeCompletion/objc-protocol-member-access.m
new file mode 100644
index 0000000..0ed5538
--- /dev/null
+++ b/test/CodeCompletion/objc-protocol-member-access.m
@@ -0,0 +1,24 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+@protocol Bar
+@property (readonly) int bar;
+@end
+
+@protocol Foo <Bar>
+
+@property (nonatomic, readonly) int foo;
+- (void)foobar: (int)x;
+
+@end
+
+int getFoo(id object) {
+  id<Foo> modelObject = (id<Foo>)object;
+  int foo = modelObject.;
+  return foo;
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:17:25 %s -o - | FileCheck %s
+// CHECK: bar : [#int#]bar
+// CHECK: foo : [#int#]foo
+// CHECK-NOT: foobar
diff --git a/test/SemaCXX/attr-gnu.cpp b/test/SemaCXX/attr-gnu.cpp
index b4e9f46..a553f0d 100644
--- a/test/SemaCXX/attr-gnu.cpp
+++ b/test/SemaCXX/attr-gnu.cpp
@@ -27,3 +27,19 @@
   void test3() __attribute__((cf_unknown_transfer)) override {} // Ok, not known to GCC.
 };
 }
+
+template<typename T>
+union Tu { T b; } __attribute__((transparent_union)); // expected-warning {{'transparent_union' attribute ignored}}
+
+template<typename T>
+union Tu2 { int x; T b; } __attribute__((transparent_union)); // expected-warning {{'transparent_union' attribute ignored}}
+
+union Tu3 { int x; } __attribute((transparent_union)); // expected-warning {{'transparent_union' attribute ignored}}
+
+void tuTest1(Tu<int> u); // expected-note {{candidate function not viable: no known conversion from 'int' to 'Tu<int>' for 1st argument}}
+void tuTest2(Tu3 u); // expected-note {{candidate function not viable: no known conversion from 'int' to 'Tu3' for 1st argument}}
+void tu() {
+  int x = 2;
+  tuTest1(x); // expected-error {{no matching function for call to 'tuTest1'}}
+  tuTest2(x); // expected-error {{no matching function for call to 'tuTest2'}}
+}