]> granicus.if.org Git - clang/commitdiff
When diagnosing address-space changes, apply array-to-pointer decay first.
authorJohn McCall <rjmccall@apple.com>
Tue, 1 Feb 2011 23:28:01 +0000 (23:28 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 1 Feb 2011 23:28:01 +0000 (23:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124702 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/address_spaces.c

index ab190276af3abd67d67fc85b9bb8c668000fe9c4..c084bb0a80d21a57fa57549ded45355c36a4a917 100644 (file)
@@ -8690,6 +8690,9 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
     DiagKind = diag::ext_typecheck_convert_pointer_void_func;
     break;
   case IncompatiblePointerDiscardsQualifiers: {
+    // Perform array-to-pointer decay if necessary.
+    if (SrcType->isArrayType()) SrcType = Context.getArrayDecayedType(SrcType);
+
     Qualifiers lhq = SrcType->getPointeeType().getQualifiers();
     Qualifiers rhq = DstType->getPointeeType().getQualifiers();
     if (lhq.getAddressSpace() != rhq.getAddressSpace()) {
index 38b51b2912674fac9360bc1910cc0f7ac8cf035c..a53bb4da00034804c00f2988cb9ba1a53e5e9f68 100644 (file)
@@ -39,3 +39,8 @@ void * get_0(void) {
   return base[0];  // expected-error {{returning '__attribute__((address_space(256))) void *' from a function with result type 'void *' changes address space of pointer}}
 }
 
+__attribute__((address_space(1))) char test3_array[10];
+void test3(void) {
+  extern void test3_helper(char *p); // expected-note {{passing argument to parameter 'p' here}}
+  test3_helper(test3_array); // expected-error {{changes address space of pointer}}
+}