[cfe-commits] r113740 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CodeGen/pointer-arithmetic.c test/Sema/pointer-addition.c
Abramo Bagnara
abramo.bagnara at gmail.com
Sun Sep 12 23:50:07 PDT 2010
Author: abramo
Date: Mon Sep 13 01:50:07 2010
New Revision: 113740
URL: http://llvm.org/viewvc/llvm-project?rev=113740&view=rev
Log:
Congruent diagnostic for void* arithmetic.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CodeGen/pointer-arithmetic.c
cfe/trunk/test/Sema/pointer-addition.c
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=113740&r1=113739&r2=113740&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Sep 13 01:50:07 2010
@@ -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()))
Modified: cfe/trunk/test/CodeGen/pointer-arithmetic.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pointer-arithmetic.c?rev=113740&r1=113739&r2=113740&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/pointer-arithmetic.c (original)
+++ cfe/trunk/test/CodeGen/pointer-arithmetic.c Mon Sep 13 01:50:07 2010
@@ -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]; }
Modified: cfe/trunk/test/Sema/pointer-addition.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/pointer-addition.c?rev=113740&r1=113739&r2=113740&view=diff
==============================================================================
--- cfe/trunk/test/Sema/pointer-addition.c (original)
+++ cfe/trunk/test/Sema/pointer-addition.c Mon Sep 13 01:50:07 2010
@@ -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;
More information about the cfe-commits
mailing list