public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] testsuite: analyzer: expect alignment warning with -fshort-enums
@ 2023-11-19  7:36 Alexandre Oliva
  2023-11-19 15:13 ` Jeff Law
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Alexandre Oliva @ 2023-11-19  7:36 UTC (permalink / raw)
  To: gcc-patches
  Cc: David Malcolm, Rainer Orth, Mike Stump, Jason Merrill, Nathan Sidwell


On targets that have -fshort-enums enabled by default, the type casts
in the pr108251 analyzer tests warn that the byte-aligned enums may
not be sufficiently aligned to be a struct connection *.  The function
can't know better, the warning is reasonable, the code doesn't
expected enums to be shorter and less aligned than the struct.

Rather than use -fno-short-enums, I decided to embrace the warning on
targets that have short_enums enabled by default.

However, C++ doesn't issue the warning, because even with
-fshort-enums, enumeration types are not TYPE_PACKED, and the
expression is not sufficiently simplified by the C++ front-end for
check_and_warn_address_or_pointer_of_packed_member to identify the
insufficiently aligned pointer.  So don't expect the warning there.

(I've got followup patches in testing to get the same warnings in C++)

Regstrapped on x86_64-linux-gnu, also tested on arm-eabi with default
cpu on trunk, and with tms570 on gcc-13.  Ok to install?


for  gcc/testsuite/ChangeLog

	* c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c:
	Expect "unaligned pointer value" warning on short_enums
	targets, but not in c++.
	* c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c:
	Likewise.
---
 ...-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c |    2 +-
 ...ull-deref-pr108251-smp_fetch_ssl_fc_has_early.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c b/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c
index c46ffe91a6b46..aaa2031b6dca4 100644
--- a/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c
+++ b/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early-O2.c
@@ -61,7 +61,7 @@ static inline enum obj_type obj_type(const enum obj_type *t)
 }
 static inline struct connection *__objt_conn(enum obj_type *t)
 {
- return ((struct connection *)(((char *)(t)) - ((long)&((struct connection *)0)->obj_type)));
+ return ((struct connection *)(((char *)(t)) - ((long)&((struct connection *)0)->obj_type))); /* { dg-warning "unaligned pointer value" "warning" { target { short_enums && { ! c++ } } } } */
 }
 static inline struct connection *objt_conn(enum obj_type *t)
 {
diff --git a/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c b/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c
index ef34a76c50d63..6c96f5a76ef1c 100644
--- a/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c
+++ b/gcc/testsuite/c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early.c
@@ -60,7 +60,7 @@ static inline enum obj_type obj_type(const enum obj_type *t)
 }
 static inline struct connection *__objt_conn(enum obj_type *t)
 {
- return ((struct connection *)(((char *)(t)) - ((long)&((struct connection *)0)->obj_type)));
+ return ((struct connection *)(((char *)(t)) - ((long)&((struct connection *)0)->obj_type))); /* { dg-warning "unaligned pointer value" "warning" { target { short_enums && { ! c++ } } } } */
 }
 static inline struct connection *objt_conn(enum obj_type *t)
 {


-- 
Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
   Free Software Activist                   GNU Toolchain Engineer
More tolerance and less prejudice are key for inclusion and diversity
Excluding neuro-others for not behaving ""normal"" is *not* inclusive

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-11-30  7:21 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-19  7:36 [PATCH] testsuite: analyzer: expect alignment warning with -fshort-enums Alexandre Oliva
2023-11-19 15:13 ` Jeff Law
2023-11-20 22:19   ` David Malcolm
2023-11-20  2:33 ` [PATCH #2/4] c++: mark short-enums as packed Alexandre Oliva
2023-11-20 19:55   ` Jason Merrill
2023-11-22  8:17     ` Alexandre Oliva
2023-11-22 18:12       ` Jason Merrill
2023-11-22 18:26         ` Jason Merrill
2023-11-29  9:39           ` Alexandre Oliva
2023-11-29 19:03             ` Jason Merrill
2023-11-30  7:21               ` Alexandre Oliva
2023-11-20  2:34 ` [PATCH #3/4] warn on cast of pointer to packed plus constant Alexandre Oliva
2023-11-20  2:34 ` [PATCH #4/4] testsuite: discard c++ exclusion on underaligned pointer warning Alexandre Oliva
2023-11-23 20:27   ` Mike Stump

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).