* [Bug middle-end/90404] No warning on attempts to modify a const object
[not found] <bug-90404-4@http.gcc.gnu.org/bugzilla/>
@ 2020-03-16 16:54 ` msebor at gcc dot gnu.org
2020-03-16 19:04 ` msebor at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-03-16 16:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90404
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.0
Component|c |middle-end
--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
No progress for GCC 10. I plan to work on it for GCC 11.
Here's a test case where the fact that the modification is invalid is less
obvious and doesn't trigger a warning. The dump shows how the code emitted by
GCC makes assumptions that make the undefined behavior manifest without ever
causing the program to crash at runtime.
$ cat x.C && gcc -O2 -S -Wall -Wextra -Wcast-qual -Wpedantic
-fdump-tree-optimized=/dev/stdout x.C
const char a[] = "012.45";
int f (void)
{
char *p = __builtin_strchr (a, '.');
*p = 0;
if (__builtin_strlen (p) != 3) // folded to false
__builtin_abort ();
return a[3] == 0; // also folded to false
}
;; Function f (_Z1fv, funcdef_no=0, decl_uid=2328, cgraph_uid=1,
symbol_order=1)
f ()
{
<bb 2> [local count: 1073741824]:
return 0;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/90404] No warning on attempts to modify a const object
[not found] <bug-90404-4@http.gcc.gnu.org/bugzilla/>
2020-03-16 16:54 ` [Bug middle-end/90404] No warning on attempts to modify a const object msebor at gcc dot gnu.org
@ 2020-03-16 19:04 ` msebor at gcc dot gnu.org
2020-03-24 21:59 ` msebor at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-03-16 19:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90404
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=94169
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
See also pr94169 for a related class of problems that would be worth warning
on.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/90404] No warning on attempts to modify a const object
[not found] <bug-90404-4@http.gcc.gnu.org/bugzilla/>
2020-03-16 16:54 ` [Bug middle-end/90404] No warning on attempts to modify a const object msebor at gcc dot gnu.org
2020-03-16 19:04 ` msebor at gcc dot gnu.org
@ 2020-03-24 21:59 ` msebor at gcc dot gnu.org
2020-10-12 16:06 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-03-24 21:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90404
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=94313
--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
See also pr94313 which shows how reliably diagnosing some of these invalid
stores is made challenging by optimizations that remove them.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/90404] No warning on attempts to modify a const object
[not found] <bug-90404-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2020-03-24 21:59 ` msebor at gcc dot gnu.org
@ 2020-10-12 16:06 ` cvs-commit at gcc dot gnu.org
2021-04-27 11:38 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-12 16:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90404
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by David Malcolm <dmalcolm@gcc.gnu.org>:
https://gcc.gnu.org/g:3175d40fc52fb8eb3c3b18cc343d773da24434fb
commit r11-3829-g3175d40fc52fb8eb3c3b18cc343d773da24434fb
Author: David Malcolm <dmalcolm@redhat.com>
Date: Wed Oct 7 18:34:09 2020 -0400
analyzer: add warnings about writes to constant regions [PR95007]
This patch adds two new warnings:
-Wanalyzer-write-to-const
-Wanalyzer-write-to-string-literal
for code paths where the analyzer detects a write to a constant region.
As noted in the documentation part of the patch, the analyzer doesn't
prioritize detection of such writes, in that the state-merging logic
will blithely lose the distinction between const and non-const regions.
Hence false negatives are likely to arise due to state-merging.
However, if the analyzer does happen to spot such a write, it seems worth
reporting, hence this patch.
gcc/analyzer/ChangeLog:
* analyzer.opt (Wanalyzer-write-to-const): New.
(Wanalyzer-write-to-string-literal): New.
* region-model-impl-calls.cc (region_model::impl_call_memcpy):
Call check_for_writable_region.
(region_model::impl_call_memset): Likewise.
(region_model::impl_call_strcpy): Likewise.
* region-model.cc (class write_to_const_diagnostic): New.
(class write_to_string_literal_diagnostic): New.
(region_model::check_for_writable_region): New.
(region_model::set_value): Call check_for_writable_region.
* region-model.h (region_model::check_for_writable_region): New
decl.
gcc/ChangeLog:
* doc/invoke.texi: Document -Wanalyzer-write-to-const and
-Wanalyzer-write-to-string-literal.
gcc/testsuite/ChangeLog:
PR c/83347
PR middle-end/90404
PR analyzer/95007
* gcc.dg/analyzer/write-to-const-1.c: New test.
* gcc.dg/analyzer/write-to-string-literal-1.c: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/90404] No warning on attempts to modify a const object
[not found] <bug-90404-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2020-10-12 16:06 ` cvs-commit at gcc dot gnu.org
@ 2021-04-27 11:38 ` jakub at gcc dot gnu.org
2021-06-16 15:51 ` jamborm at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-27 11:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90404
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.0 |11.2
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.1 has been released, retargeting bugs to GCC 11.2.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/90404] No warning on attempts to modify a const object
[not found] <bug-90404-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2021-04-27 11:38 ` jakub at gcc dot gnu.org
@ 2021-06-16 15:51 ` jamborm at gcc dot gnu.org
2021-07-28 7:04 ` rguenth at gcc dot gnu.org
2022-01-26 17:49 ` msebor at gcc dot gnu.org
7 siblings, 0 replies; 8+ messages in thread
From: jamborm at gcc dot gnu.org @ 2021-06-16 15:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90404
Martin Jambor <jamborm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jamborm at gcc dot gnu.org
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=100994
--- Comment #9 from Martin Jambor <jamborm at gcc dot gnu.org> ---
As discussed on the mailing list, such warning should also catch situations
like the testcase in pr100994 comment #4.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/90404] No warning on attempts to modify a const object
[not found] <bug-90404-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2021-06-16 15:51 ` jamborm at gcc dot gnu.org
@ 2021-07-28 7:04 ` rguenth at gcc dot gnu.org
2022-01-26 17:49 ` msebor at gcc dot gnu.org
7 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-28 7:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90404
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.2 |---
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug middle-end/90404] No warning on attempts to modify a const object
[not found] <bug-90404-4@http.gcc.gnu.org/bugzilla/>
` (6 preceding siblings ...)
2021-07-28 7:04 ` rguenth at gcc dot gnu.org
@ 2022-01-26 17:49 ` msebor at gcc dot gnu.org
7 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-26 17:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90404
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
Assignee|msebor at gcc dot gnu.org |unassigned at gcc dot gnu.org
--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'm not working on this anymore.
^ permalink raw reply [flat|nested] 8+ messages in thread