From: Shengyu Huang <kumom.huang@gmail.com>
To: David Malcolm <dmalcolm@redhat.com>
Cc: GCC Development <gcc@gcc.gnu.org>
Subject: Re: [GSoC][Static Analyzer] Some questions and request for a small patch to work on
Date: Wed, 1 Mar 2023 12:16:31 +0100 [thread overview]
Message-ID: <5BF6D475-B981-4B7C-A86B-BCCEF629AC19@gmail.com> (raw)
In-Reply-To: <f8461d624d14670de2a183b58c4066b9b10e24b8.camel@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4232 bytes --]
Hi Dave,
> On 1 Mar 2023, at 00:59, David Malcolm <dmalcolm@redhat.com> wrote:
>
> Did you get it to output your messages?
>
Yes, I chose to emit the warning before the supergraph or exploded graph is created (I guess this is enough, right?). I checked out from the trunk a week ago, and I checked out from the latest trunk just now and built from modified source again, by adding a line in the following code in analyzer/engine.cc:
FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node) {
node->get_untransformed_body ();
warning_at (DECL_SOURCE_LOCATION (node->decl), 0, "hello world, I’m compiling %qE", node->decl); // ADDED
}
Compiling my own test script without optimizations, I got the output (surprisingly no warning from -Wanalyzer-shift-count-negative anymore):
test.c: In function 'main':
test.c:42:9: warning: left shift count is negative [-Wshift-count-negative]
42 | b = b << -1;
| ^~
test.c: At top level:
test.c:36:5: warning: hello world, I'm compiling 'main'
36 | int main()
| ^~~~
test.c:27:6: warning: hello world, I'm compiling 're'
27 | void re (int c)
| ^~
test.c:12:6: warning: hello world, I'm compiling 'f'
12 | void f (unsigned long *p, int r, int i)
| ^
test.c:9:5: warning: hello world, I'm compiling 'fun2'
9 | int fun2()
| ^~~~
test.c:4:5: warning: hello world, I'm compiling 'fun1'
4 | int fun1()
| ^~~~
test.c: In function 'main':
test.c:40:8: warning: use of uninitialized value 'a' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
40 | int* c = a;
| ^
'main': events 1-3
|
| 38 | int* a;
| | ^
| | |
| | (1) region created on stack here
| | (2) capacity: 8 bytes
| 39 | int b = 'c';
| 40 | int* c = a;
| | ~
| | |
| | (3) use of uninitialized value 'a' here
|
~~
If I compiled it with -O2, I got additionally
test.c: In function 'f':
test.c:20:34: warning: shift by count ('64') >= precision of type ('64') [-Wanalyzer-shift-count-overflow]
20 | p[i--] = b + 1 >= 64 ? 0UL : 1UL << (b + 1);
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
'f': events 1-5
|
| 16 | while (i >= 0)
| | ~~^~~~
| | |
| | (1) following 'true' branch (when 'i >= 0')...
| 17 | {
| 18 | if (n > b)
| | ~
| | |
| | (2) ...to here
| | (3) following 'true' branch (when 'b < n')...
| 19 | {
| 20 | p[i--] = b + 1 >= 64 ? 0UL : 1UL << (b + 1);
| | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| | | |
| | | (4) ...to here
| | (5) shift by count '64' here
|
which is documented as a false positive in PR98447.
>
> The next thing to do might be to try stepping through the code in the
> debugger; that's often a good way to learn about a new codebase. See:
> https://gcc-newbies-guide.readthedocs.io/en/latest/debugging.html
> and maybe have a look at the support scripts mentioned on that page.
>
I did try to use gdb more to inspect the internals, but one thing I noticed when using it is that I got `??()` in the backtrace, which I’ve never seen before. Some online sources say it happened due to “corrupted stack”, but I don’t know how that can happen either…However, after pulling changes from the trunk and rebuilding from the source, “??()” disappeared and now I can step through the execution without any problem (previously `step` and `continue` did not work as expected…). Do you have any clues what happened so that I can fix it myself later if that happens again?
Best,
Shengyu
> BTW, are you building trunk, or GCC 12? I've made a *lot* of changes
> to the analyzer in trunk, so it would be good for you to be working
> with something that's reasonably up-to-date.
next prev parent reply other threads:[~2023-03-01 11:16 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-21 21:26 Shengyu Huang
2023-02-21 22:55 ` David Malcolm
2023-02-22 14:03 ` Jonathan Wakely
2023-02-23 11:17 ` James K. Lowden
2023-02-23 16:30 ` Jonathan Wakely
2023-02-22 14:11 ` Shengyu Huang
2023-02-22 14:53 ` Iain Sandoe
2023-02-22 15:13 ` Iain Sandoe
2023-02-27 13:35 ` Shengyu Huang
2023-02-27 13:45 ` Iain Sandoe
2023-02-27 13:51 ` Shengyu Huang
2023-02-27 13:49 ` Iain Sandoe
2023-02-27 14:01 ` Floyd, Paul
2023-02-22 15:43 ` David Malcolm
2023-02-28 9:18 ` Shengyu Huang
2023-02-28 23:59 ` David Malcolm
2023-03-01 11:16 ` Shengyu Huang [this message]
2023-03-01 13:48 ` David Malcolm
2023-02-28 14:46 ` [GSoC][Static Analyzer] Ideas for proposal Shengyu Huang
2023-03-01 0:22 ` David Malcolm
2023-03-12 22:20 ` Shengyu Huang
2023-03-13 15:51 ` David Malcolm
2023-03-20 17:28 ` [GSoC][Static Analyzer] First proposal draft and a few more questions/requests Shengyu Huang
2023-03-20 22:50 ` David Malcolm
2023-03-26 16:03 ` Shengyu Huang
2023-03-26 17:14 ` David Malcolm
2023-03-26 21:46 ` Shengyu Huang
2023-04-01 14:19 ` Shengyu Huang
2023-04-02 22:53 ` David Malcolm
2023-04-03 0:02 ` Shengyu Huang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5BF6D475-B981-4B7C-A86B-BCCEF629AC19@gmail.com \
--to=kumom.huang@gmail.com \
--cc=dmalcolm@redhat.com \
--cc=gcc@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).