public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] warn on cast of pointer to packed plus constant
@ 2023-11-19 7:02 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2023-11-19 7:02 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:9d7a231e7496533834e194131a0971a533534d3b
commit 9d7a231e7496533834e194131a0971a533534d3b
Author: Alexandre Oliva <oliva@adacore.com>
Date: Sun Nov 19 01:25:01 2023 -0300
warn on cast of pointer to packed plus constant
c-c++-common/analyzer/null-deref-pr108251-smp-fetch_ssl_fc_has_early.c
gets an unaligned pointer value warning on -fshort-enums targets in C,
but not in C++. The former simplifies the offset-and-cast expression
enough that check_and_warn_address_or_pointer_of_packed_member finds
no more than a type cast of the base pointer, but in C++, the entire
expression, with cast, constant offsetting, and cast again, is
retained, and that's too much for the warning code.
Or rather it was. It's easy enough to take the base pointer from
PLUS_POINTER_EXPR, and a constant offset can't possibly increase
alignment for just any pointer of laxer alignment, so we can safely
disregard the offset.
This should improve the warning even in C, if the packed enum is at a
nonzero offset into the containing struct.
for gcc/c-family/ChangeLog
* c-warn.cc
(check_and_warn_address_or_pointer_of_packed_member): Take the
base pointer from PLUS_POINTER_EXPR when the addend is
constant.
Diff:
---
gcc/c-family/c-warn.cc | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d2938b91043..39f5ddc577c 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3108,9 +3108,17 @@ check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs)
do
{
- while (TREE_CODE (rhs) == COMPOUND_EXPR)
- rhs = TREE_OPERAND (rhs, 1);
- orig_rhs = rhs;
+ do
+ {
+ orig_rhs = rhs;
+ while (TREE_CODE (rhs) == COMPOUND_EXPR)
+ rhs = TREE_OPERAND (rhs, 1);
+ /* Constants can't increase the alignment. */
+ while (TREE_CODE (rhs) == POINTER_PLUS_EXPR
+ && TREE_CONSTANT (TREE_OPERAND (rhs, 1)))
+ rhs = TREE_OPERAND (rhs, 0);
+ }
+ while (orig_rhs != rhs);
STRIP_NOPS (rhs);
nop_p |= orig_rhs != rhs;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] warn on cast of pointer to packed plus constant
@ 2023-11-23 11:46 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2023-11-23 11:46 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:cbcac1b2f5f54c8a85c42f38233271ddaecb9a36
commit cbcac1b2f5f54c8a85c42f38233271ddaecb9a36
Author: Alexandre Oliva <oliva@adacore.com>
Date: Sun Nov 19 01:25:01 2023 -0300
warn on cast of pointer to packed plus constant
c-c++-common/analyzer/null-deref-pr108251-smp-fetch_ssl_fc_has_early.c
gets an unaligned pointer value warning on -fshort-enums targets in C,
but not in C++. The former simplifies the offset-and-cast expression
enough that check_and_warn_address_or_pointer_of_packed_member finds
no more than a type cast of the base pointer, but in C++, the entire
expression, with cast, constant offsetting, and cast again, is
retained, and that's too much for the warning code.
Or rather it was. It's easy enough to take the base pointer from
PLUS_POINTER_EXPR, and a constant offset can't possibly increase
alignment for just any pointer of laxer alignment, so we can safely
disregard the offset.
This should improve the warning even in C, if the packed enum is at a
nonzero offset into the containing struct.
for gcc/c-family/ChangeLog
* c-warn.cc
(check_and_warn_address_or_pointer_of_packed_member): Take the
base pointer from PLUS_POINTER_EXPR when the addend is
constant.
Diff:
---
gcc/c-family/c-warn.cc | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d2938b91043..2ef73d7088f 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3108,10 +3108,20 @@ check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs)
do
{
- while (TREE_CODE (rhs) == COMPOUND_EXPR)
- rhs = TREE_OPERAND (rhs, 1);
- orig_rhs = rhs;
+ do
+ {
+ orig_rhs = rhs;
+ while (TREE_CODE (rhs) == COMPOUND_EXPR)
+ rhs = TREE_OPERAND (rhs, 1);
+ /* Constants can't increase the alignment. */
+ while (TREE_CODE (rhs) == POINTER_PLUS_EXPR
+ && TREE_CONSTANT (TREE_OPERAND (rhs, 1)))
+ rhs = TREE_OPERAND (rhs, 0);
+ }
+ while (orig_rhs != rhs);
STRIP_NOPS (rhs);
+ while (TREE_CODE (rhs) == VIEW_CONVERT_EXPR)
+ rhs = TREE_OPERAND (rhs, 0);
nop_p |= orig_rhs != rhs;
}
while (orig_rhs != rhs);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] warn on cast of pointer to packed plus constant
@ 2023-11-19 8:32 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2023-11-19 8:32 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4ceb7e54d336193af0af006d821217152bdfdd8f
commit 4ceb7e54d336193af0af006d821217152bdfdd8f
Author: Alexandre Oliva <oliva@adacore.com>
Date: Sun Nov 19 01:25:01 2023 -0300
warn on cast of pointer to packed plus constant
c-c++-common/analyzer/null-deref-pr108251-smp-fetch_ssl_fc_has_early.c
gets an unaligned pointer value warning on -fshort-enums targets in C,
but not in C++. The former simplifies the offset-and-cast expression
enough that check_and_warn_address_or_pointer_of_packed_member finds
no more than a type cast of the base pointer, but in C++, the entire
expression, with cast, constant offsetting, and cast again, is
retained, and that's too much for the warning code.
Or rather it was. It's easy enough to take the base pointer from
PLUS_POINTER_EXPR, and a constant offset can't possibly increase
alignment for just any pointer of laxer alignment, so we can safely
disregard the offset.
This should improve the warning even in C, if the packed enum is at a
nonzero offset into the containing struct.
for gcc/c-family/ChangeLog
* c-warn.cc
(check_and_warn_address_or_pointer_of_packed_member): Take the
base pointer from PLUS_POINTER_EXPR when the addend is
constant.
Diff:
---
gcc/c-family/c-warn.cc | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d2938b91043..2ef73d7088f 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3108,10 +3108,20 @@ check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs)
do
{
- while (TREE_CODE (rhs) == COMPOUND_EXPR)
- rhs = TREE_OPERAND (rhs, 1);
- orig_rhs = rhs;
+ do
+ {
+ orig_rhs = rhs;
+ while (TREE_CODE (rhs) == COMPOUND_EXPR)
+ rhs = TREE_OPERAND (rhs, 1);
+ /* Constants can't increase the alignment. */
+ while (TREE_CODE (rhs) == POINTER_PLUS_EXPR
+ && TREE_CONSTANT (TREE_OPERAND (rhs, 1)))
+ rhs = TREE_OPERAND (rhs, 0);
+ }
+ while (orig_rhs != rhs);
STRIP_NOPS (rhs);
+ while (TREE_CODE (rhs) == VIEW_CONVERT_EXPR)
+ rhs = TREE_OPERAND (rhs, 0);
nop_p |= orig_rhs != rhs;
}
while (orig_rhs != rhs);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] warn on cast of pointer to packed plus constant
@ 2023-11-19 8:18 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2023-11-19 8:18 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:75749d7bfe815368fc388740d9b1ac0ae9d568f0
commit 75749d7bfe815368fc388740d9b1ac0ae9d568f0
Author: Alexandre Oliva <oliva@adacore.com>
Date: Sun Nov 19 01:25:01 2023 -0300
warn on cast of pointer to packed plus constant
c-c++-common/analyzer/null-deref-pr108251-smp-fetch_ssl_fc_has_early.c
gets an unaligned pointer value warning on -fshort-enums targets in C,
but not in C++. The former simplifies the offset-and-cast expression
enough that check_and_warn_address_or_pointer_of_packed_member finds
no more than a type cast of the base pointer, but in C++, the entire
expression, with cast, constant offsetting, and cast again, is
retained, and that's too much for the warning code.
Or rather it was. It's easy enough to take the base pointer from
PLUS_POINTER_EXPR, and a constant offset can't possibly increase
alignment for just any pointer of laxer alignment, so we can safely
disregard the offset.
This should improve the warning even in C, if the packed enum is at a
nonzero offset into the containing struct.
for gcc/c-family/ChangeLog
* c-warn.cc
(check_and_warn_address_or_pointer_of_packed_member): Take the
base pointer from PLUS_POINTER_EXPR when the addend is
constant.
Diff:
---
gcc/c-family/c-warn.cc | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d2938b91043..6c7f174de72 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3108,10 +3108,19 @@ check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs)
do
{
- while (TREE_CODE (rhs) == COMPOUND_EXPR)
- rhs = TREE_OPERAND (rhs, 1);
- orig_rhs = rhs;
+ do
+ {
+ orig_rhs = rhs;
+ while (TREE_CODE (rhs) == COMPOUND_EXPR)
+ rhs = TREE_OPERAND (rhs, 1);
+ /* Constants can't increase the alignment. */
+ while (TREE_CODE (rhs) == POINTER_PLUS_EXPR
+ && TREE_CONSTANT (TREE_OPERAND (rhs, 1)))
+ rhs = TREE_OPERAND (rhs, 0);
+ }
+ while (orig_rhs != rhs);
STRIP_NOPS (rhs);
+ STRIP_TYPE_NOPS (rhs);
nop_p |= orig_rhs != rhs;
}
while (orig_rhs != rhs);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] warn on cast of pointer to packed plus constant
@ 2023-11-19 8:11 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2023-11-19 8:11 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b61f690f5c17a41c628186f41013876e21428738
commit b61f690f5c17a41c628186f41013876e21428738
Author: Alexandre Oliva <oliva@adacore.com>
Date: Sun Nov 19 01:25:01 2023 -0300
warn on cast of pointer to packed plus constant
c-c++-common/analyzer/null-deref-pr108251-smp-fetch_ssl_fc_has_early.c
gets an unaligned pointer value warning on -fshort-enums targets in C,
but not in C++. The former simplifies the offset-and-cast expression
enough that check_and_warn_address_or_pointer_of_packed_member finds
no more than a type cast of the base pointer, but in C++, the entire
expression, with cast, constant offsetting, and cast again, is
retained, and that's too much for the warning code.
Or rather it was. It's easy enough to take the base pointer from
PLUS_POINTER_EXPR, and a constant offset can't possibly increase
alignment for just any pointer of laxer alignment, so we can safely
disregard the offset.
This should improve the warning even in C, if the packed enum is at a
nonzero offset into the containing struct.
for gcc/c-family/ChangeLog
* c-warn.cc
(check_and_warn_address_or_pointer_of_packed_member): Take the
base pointer from PLUS_POINTER_EXPR when the addend is
constant.
Diff:
---
gcc/c-family/c-warn.cc | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d2938b91043..3ca06fe5443 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3108,10 +3108,20 @@ check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs)
do
{
- while (TREE_CODE (rhs) == COMPOUND_EXPR)
- rhs = TREE_OPERAND (rhs, 1);
- orig_rhs = rhs;
+ do
+ {
+ orig_rhs = rhs;
+ while (TREE_CODE (rhs) == COMPOUND_EXPR)
+ rhs = TREE_OPERAND (rhs, 1);
+ /* Constants can't increase the alignment. */
+ while (TREE_CODE (rhs) == POINTER_PLUS_EXPR
+ && TREE_CONSTANT (TREE_OPERAND (rhs, 1)))
+ rhs = TREE_OPERAND (rhs, 0);
+ }
+ while (orig_rhs != rhs);
STRIP_NOPS (rhs);
+ STRIP_USELESS_TYPE_CONVERSION (rhs);
+ STRIP_ANY_LOCATION_WRAPPER (rhs);
nop_p |= orig_rhs != rhs;
}
while (orig_rhs != rhs);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [gcc(refs/users/aoliva/heads/testme)] warn on cast of pointer to packed plus constant
@ 2023-11-19 6:31 Alexandre Oliva
0 siblings, 0 replies; 6+ messages in thread
From: Alexandre Oliva @ 2023-11-19 6:31 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c50d78d2eb189e6cdcf5b2c341f9cf76e3fb7dc1
commit c50d78d2eb189e6cdcf5b2c341f9cf76e3fb7dc1
Author: Alexandre Oliva <oliva@adacore.com>
Date: Sun Nov 19 01:25:01 2023 -0300
warn on cast of pointer to packed plus constant
gcc.dg/analyzer/null-deref-pr108251-smp-fetch_ssl_fc_has_early.c gets
an unaligned pointer value warning on -fshort-enums targets in C, but
not in C++. The former simplifies the offset-and-cast expression
enough that check_and_warn_address_or_pointer_of_packed_member finds
no more than a type cast of the base pointer, but in C++, the entire
expression, with cast, constant offsetting, and cast again, is
retained, and that's too much for the warning code.
Or rather it was. It's easy enough to take the base pointer from
PLUS_POINTER_EXPR, and a constant offset can't possibly increase
alignment for just any pointer of laxer alignment, so we can safely
disregard the offset.
for gcc/c-family/ChangeLog
* c-warn.cc
(check_and_warn_address_or_pointer_of_packed_member): Take the
base pointer from PLUS_POINTER_EXPR when the addend is
constant.
Diff:
---
gcc/c-family/c-warn.cc | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index d2938b91043..c705f43e5c3 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3108,9 +3108,17 @@ check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs)
do
{
- while (TREE_CODE (rhs) == COMPOUND_EXPR)
- rhs = TREE_OPERAND (rhs, 1);
- orig_rhs = rhs;
+ do
+ {
+ orig_rhs = rhs;
+ while (TREE_CODE (rhs) == COMPOUND_EXPR)
+ rhs = TREE_OPERAND (rhs, 1);
+ /* Constants can't increase the alignment. */
+ while (TREE_CODE (rhs) == POINTER_PLUS_EXPR
+ && CONSTANT_CLASS_P (TREE_OPERAND (rhs, 1)))
+ rhs = TREE_OPERAND (rhs, 0);
+ }
+ while (orig_rhs != rhs);
STRIP_NOPS (rhs);
nop_p |= orig_rhs != rhs;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-11-23 11:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-19 7:02 [gcc(refs/users/aoliva/heads/testme)] warn on cast of pointer to packed plus constant Alexandre Oliva
-- strict thread matches above, loose matches on Subject: below --
2023-11-23 11:46 Alexandre Oliva
2023-11-19 8:32 Alexandre Oliva
2023-11-19 8:18 Alexandre Oliva
2023-11-19 8:11 Alexandre Oliva
2023-11-19 6:31 Alexandre Oliva
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).