public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "marxin at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/99801] Address sanitizer false positive with pointer to member function.
Date: Mon, 12 Apr 2021 09:29:07 +0000	[thread overview]
Message-ID: <bug-99801-4-ZD88ne5Dkh@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-99801-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99801

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
So let's consider the following example:

$ cat pr99801.C
class Curses_table {
public:
        void draw_row() {};
        void draw_table();
};

void Curses_table::draw_table()
{
  void (Curses_table::*draw_fn) (void) = &Curses_table::draw_row;
        auto Curses_table::*draw_fn2 = &Curses_table::draw_row;
        (this->*draw_fn)();
        (this->*draw_fn2)();
}

int main() {
        Curses_table t;
        t.draw_table();
}

What happens is that we wrongly assign DECL_SIZE_UNIT for draw_fn2 in:

Breakpoint 5, layout_decl (decl=<var_decl 0x7ffff7fbef30 draw_fn>,
known_align=0) at /home/marxin/Programming/gcc/gcc/stor-layout.c:634
(gdb) p debug_tree(type)
 <offset_type 0x7ffff777d690
    type <template_type_parm 0x7ffff777d5e8 auto VOID
        align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff777d5e8
       index 0 level 1 orig_level 1
        chain <type_decl 0x7ffff760ee40 auto>>
    DI
    size <integer_cst 0x7ffff75e1eb8 type <integer_type 0x7ffff75ff0a8
bitsizetype> constant 64>
    unit-size <integer_cst 0x7ffff75e1ed0 type <integer_type 0x7ffff75ff000
sizetype> constant 8>
    align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff777d690 basetype <record_type 0x7ffff777d888 Curses_table>>

while draw_fn is called with:

(gdb) p debug_tree(type)
 <record_type 0x7ffff777d3f0 type_2 TI
    size <integer_cst 0x7ffff75e1f00 type <integer_type 0x7ffff75ff0a8
bitsizetype> constant 128>
    unit-size <integer_cst 0x7ffff75e1f18 type <integer_type 0x7ffff75ff000
sizetype> constant 16>
    align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff777d498
    fields <field_decl 0x7ffff760eab0 __pfn
        type <pointer_type 0x7ffff777d2a0 type <method_type 0x7ffff777d0a8>
            unsigned DI
            size <integer_cst 0x7ffff75e1eb8 constant 64>
            unit-size <integer_cst 0x7ffff75e1ed0 constant 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7ffff777d348>
        unsigned nonaddressable DI
/home/marxin/Programming/testcases/pr99801.C:9:38 size <integer_cst
0x7ffff75e1eb8 64> unit-size <integer_cst 0x7ffff75e1ed0 8>
        align:64 warn_if_not_align:0 offset_align 128
        offset <integer_cst 0x7ffff75e1ee8 constant 0>
        bit-offset <integer_cst 0x7ffff75e1f30 constant 0> context <record_type
0x7ffff777d3f0>
        chain <field_decl 0x7ffff760eb48 __delta type <integer_type
0x7ffff75ff738 long int>
            nonaddressable DI /home/marxin/Programming/testcases/pr99801.C:9:38
size <integer_cst 0x7ffff75e1eb8 64> unit-size <integer_cst 0x7ffff75e1ed0 8>
            align:64 warn_if_not_align:0 offset_align 128 offset <integer_cst
0x7ffff75e1ee8 0> bit-offset <integer_cst 0x7ffff75e1eb8 64> context
<record_type 0x7ffff777d3f0>>> ptrmemfunc fn type <pointer_type 0x7ffff777d2a0>
    chain <type_decl 0x7ffff760ebe0 __ptrmemfunc_type>>

later then the corresponding record_type is set as TREE_TYPE of draw_fn2:

(gdb) bt
#0  0x0000000000a16cd0 in cp_finish_decl (decl=decl@entry=<var_decl
0x7ffff7794510 draw_fn2>, init=<optimized out>, init@entry=<ptrmem_cst
0x7ffff7774b20>, init_const_expr_p=true, asmspec_tree=<optimized out>,
asmspec_tree@entry=<tree 0x0>, flags=5)
    at /home/marxin/Programming/gcc/gcc/cp/decl.c:7744
#1  0x0000000000b06168 in cp_parser_init_declarator (parser=0x7ffff760e7b8,
flags=<optimized out>, decl_specifiers=0x7fffffffd2b0, checks=0x0,
function_definition_allowed_p=<optimized out>, member_p=<optimized out>,
declares_class_or_enum=0, 
    function_definition_p=0x7fffffffd350, maybe_range_for_decl=0x0,
init_loc=0x7fffffffd29c, auto_result=0x7fffffffd3f0) at
/home/marxin/Programming/gcc/gcc/cp/parser.c:21872
#2  0x0000000000ae166d in cp_parser_simple_declaration (parser=0x7ffff760e7b8,
function_definition_allowed_p=<optimized out>, maybe_range_for_decl=0x0) at
/home/marxin/Programming/gcc/gcc/cp/parser.c:14442
#3  0x0000000000ae385b in cp_parser_declaration_statement
(parser=parser@entry=0x7ffff760e7b8) at
/home/marxin/Programming/gcc/gcc/cp/parser.c:13577
#4  0x0000000000ae3ea4 in cp_parser_statement (parser=0x7ffff760e7b8,
in_statement_expr=<tree 0x0>, in_compound=<optimized out>, if_p=<optimized
out>, chain=<optimized out>, loc_after_labels=0x0) at
/home/marxin/Programming/gcc/gcc/cp/parser.c:11808
#5  0x0000000000ae5983 in cp_parser_statement_seq_opt
(parser=parser@entry=0x7ffff760e7b8,
in_statement_expr=in_statement_expr@entry=<tree 0x0>) at
/home/marxin/Programming/gcc/gcc/cp/parser.c:12174

but the DECL_SIZE_UNIT is not adjusted.
@Jason: Can you please take a look?

  parent reply	other threads:[~2021-04-12  9:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-28 16:07 [Bug c++/99801] New: " fsb4000 at yandex dot ru
2021-03-30  7:32 ` [Bug sanitizer/99801] " marxin at gcc dot gnu.org
2021-04-12  9:29 ` marxin at gcc dot gnu.org [this message]
2021-08-16 11:41 ` [Bug c++/99801] " marxin at gcc dot gnu.org
2021-08-16 11:41 ` marxin at gcc dot gnu.org
2021-11-05 16:26 ` marxin at gcc dot gnu.org
2022-12-25  6:52 ` pinskia at gcc dot gnu.org
2022-12-25  6:56 ` pinskia at gcc dot gnu.org

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=bug-99801-4-ZD88ne5Dkh@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).