[PATCH] D134461: [Clang] Warn when trying to deferencing void pointers in C

Jun Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 23 20:36:00 PDT 2022


junaire added inline comments.


================
Comment at: clang/test/C/drs/dr1xx.c:140
   /* The behavior changed between C89 and C99. */
-  (void)&*p; /* c89only-warning {{ISO C forbids taking the address of an expression of type 'void'}} */
+  (void)&*p; /* c89only-warning {{ISO C forbids taking the address of an expression of type 'void'}} c89only-warning {{ISO C does not allow indirection on operand of type 'void *'}} */
   /* The behavior of all three of these is undefined. */
----------------
aaron.ballman wrote:
> Can you switch all of the warning changes in this file to use this style where each expected diagnostic is on its own line? That makes it easier to notice which diagnostics happen on the line (it's easy to lose sight of the trailing expected diagnostics otherwise).
> Yes, basically, the language rule is that &*void_ptr is well defined in C99 and later

IIUC, you mean this should be warned in C89 mode, right?


================
Comment at: clang/test/C/drs/dr1xx.c:143
+  (void)*p; /* expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}*/
+  (void)&(*p); /* c89only-warning {{ISO C forbids taking the address of an expression of type 'void'}} expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}*/
+  (void)(i ? *p : *p); /* expected-warning {{ISO C does not allow indirection on operand of type 'void *'}} expected-warning {{ISO C does not allow indirection on operand of type 'void *'}}*/
----------------
aaron.ballman wrote:
> This looks wrong to me -- this should be an `expected-warning` instead of a `c89only-warning`, same as two lines above, right?
I'm a bit confused. Maybe I made the trailing comments too hard to read. This is an `expected-warning`, `c89only-warning` is for `ISO C forbids taking the address of an expression of type 'void'`, which is not part of this patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134461/new/

https://reviews.llvm.org/D134461



More information about the cfe-commits mailing list