From: Abramo Bagnara Date: Mon, 13 Sep 2010 06:50:07 +0000 (+0000) Subject: Congruent diagnostic for void* arithmetic. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=46358457f712a8da89d4e03a17a1d44d35c78b77;p=clang 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 1152da9bdc..9a394aeeb9 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2418,7 +2418,11 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, 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 33465e0aa1..f67a36d66e 100644 --- a/test/CodeGen/pointer-arithmetic.c +++ b/test/CodeGen/pointer-arithmetic.c @@ -9,6 +9,7 @@ int f1(const char *a, char *b) { return b - a; } // 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(int a, FP b) { return a + b; } 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 34f8bbbfcd..aa425a7fd9 100644 --- a/test/Sema/pointer-addition.c +++ b/test/Sema/pointer-addition.c @@ -9,6 +9,7 @@ void a(S* b, void* c) { 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;