Congruent diagnostic for void* arithmetic.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113740 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 1152da9..9a394ae 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2418,7 +2418,11 @@
     return ExprError();
   }
 
-  if (!ResultType->isDependentType() &&
+  if (ResultType->isVoidType() && !getLangOptions().CPlusPlus) {
+    // GNU extension: subscripting on pointer to void
+    Diag(LLoc, diag::ext_gnu_void_ptr)
+      << BaseExpr->getSourceRange();
+  } else if (!ResultType->isDependentType() &&
       RequireCompleteType(LLoc, ResultType,
                           PDiag(diag::err_subscript_incomplete_type)
                             << BaseExpr->getSourceRange()))
diff --git a/test/CodeGen/pointer-arithmetic.c b/test/CodeGen/pointer-arithmetic.c
index 33465e0..f67a36d 100644
--- a/test/CodeGen/pointer-arithmetic.c
+++ b/test/CodeGen/pointer-arithmetic.c
@@ -9,6 +9,7 @@
 // GNU extensions
 typedef void (*FP)(void);
 void *f2(void *a, int b) { return a + b; }
+void *f2_0(void *a, int b) { return &a[b]; }
 void *f2_1(void *a, int b) { return (a += b); }
 void *f3(int a, void *b) { return a + b; }
 void *f3_1(int a, void *b) { return (a += b); }
@@ -20,3 +21,5 @@
 FP f6_1(int a, FP b) { return (a += b); }
 FP f7(FP a, int b) { return a - b; }
 FP f7_1(FP a, int b) { return (a -= b); }
+void f8(void *a, int b) { return *(a + b); }
+void f8_1(void *a, int b) { return a[b]; }
diff --git a/test/Sema/pointer-addition.c b/test/Sema/pointer-addition.c
index 34f8bbb..aa425a7 100644
--- a/test/Sema/pointer-addition.c
+++ b/test/Sema/pointer-addition.c
@@ -9,6 +9,7 @@
   c += 1;    // expected-warning {{use of GNU void* extension}}
   c--;       // expected-warning {{use of GNU void* extension}}
   c -= 1;    // expected-warning {{use of GNU void* extension}}
+  (void) c[1]; // expected-warning {{use of GNU void* extension}}
   b = 1+b;   // expected-error {{arithmetic on pointer to incomplete type}}
   /* The next couple tests are only pedantic warnings in gcc */
   void (*d)(S*,void*) = a;