public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/64336] New: Template functions are not instrumented at -O0 and -Og
@ 2014-12-17  7:21 bernd.edlinger at hotmail dot de
  2014-12-17  9:03 ` [Bug sanitizer/64336] " bernd.edlinger at hotmail dot de
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: bernd.edlinger at hotmail dot de @ 2014-12-17  7:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64336
           Summary: Template functions are not instrumented at -O0 and -Og
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bernd.edlinger at hotmail dot de
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org

I noticed that all template functions/classes do not emit any
tsan warnings at -O0 and -Og, only for -O1/-O2/-O3.

That happens because these are not insrumented at all.


cat test.cpp
#include <pthread.h>

template <class x>
void
foo (x &val)
{
  val++;
}

int v;

void *
tf (void *)
{
  foo (v);
  return NULL;
}

int
main ()
{
  pthread_t th;
  if (pthread_create (&th, NULL, tf, NULL))
    return 0;
  foo (v);
  pthread_join (th, NULL);
  return 0;
}
//EOF

g++ -g -fsanitize=thread test.cpp

./a.out #prints nothing.

this is what is generated for foo<int>

_Z3fooIiEvRT_:
.LFB12:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        movq    %rdi, -8(%rbp)
        movq    -8(%rbp), %rax
        movl    (%rax), %eax
        leal    1(%rax), %edx
        movq    -8(%rbp), %rax
        movl    %edx, (%rax)
        nop
        popq    %rbp
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc


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

* [Bug sanitizer/64336] Template functions are not instrumented at -O0 and -Og
  2014-12-17  7:21 [Bug sanitizer/64336] New: Template functions are not instrumented at -O0 and -Og bernd.edlinger at hotmail dot de
@ 2014-12-17  9:03 ` bernd.edlinger at hotmail dot de
  2014-12-17  9:49 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: bernd.edlinger at hotmail dot de @ 2014-12-17  9:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
hmm...


in this example at tsan.c, instrument_expr()
is exiting twice here:

  if (TREE_READONLY (base)
      || (TREE_CODE (base) == VAR_DECL
          && DECL_HARD_REGISTER (base)))
    return false;


because TREE_READONLY (base) == true !


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

* [Bug sanitizer/64336] Template functions are not instrumented at -O0 and -Og
  2014-12-17  7:21 [Bug sanitizer/64336] New: Template functions are not instrumented at -O0 and -Og bernd.edlinger at hotmail dot de
  2014-12-17  9:03 ` [Bug sanitizer/64336] " bernd.edlinger at hotmail dot de
@ 2014-12-17  9:49 ` jakub at gcc dot gnu.org
  2015-01-08  9:21 ` jakub at gcc dot gnu.org
  2015-01-08  9:57 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-12-17  9:49 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-12-17
     Ever confirmed|0                           |1

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This sounds like a bug in whatever sets TREE_READONLY on the MEM_REF.
Apparently build2_stat sets read_only = 1 and clears it if the arguments aren't
read-only, but that of course makes no sense for MEM_REF, even if the arguments
are TREE_READONLY, that has nothing to do with TREE_READONLY of the MEM_REF
itself.  So, perhaps:
--- gcc/tree.c.jj 2014-12-15 10:36:23.000000000 +0100
+++ gcc/tree.c 2014-12-17 10:48:07.216729576 +0100
@@ -4352,7 +4352,7 @@ build2_stat (enum tree_code code, tree t
      arguments are as well.  */
   constant = (TREE_CODE_CLASS (code) == tcc_comparison
       || TREE_CODE_CLASS (code) == tcc_binary);
-  read_only = 1;
+  read_only = TREE_CODE_CLASS (code) != tcc_reference;
   side_effects = TREE_SIDE_EFFECTS (t);

   PROCESS_ARG (0);

?  INDIRECT_REF in build1_stat also sets TREE_READONLY to 0...


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

* [Bug sanitizer/64336] Template functions are not instrumented at -O0 and -Og
  2014-12-17  7:21 [Bug sanitizer/64336] New: Template functions are not instrumented at -O0 and -Og bernd.edlinger at hotmail dot de
  2014-12-17  9:03 ` [Bug sanitizer/64336] " bernd.edlinger at hotmail dot de
  2014-12-17  9:49 ` jakub at gcc dot gnu.org
@ 2015-01-08  9:21 ` jakub at gcc dot gnu.org
  2015-01-08  9:57 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-01-08  9:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Author: jakub
Date: Thu Jan  8 09:20:24 2015
New Revision: 219339

URL: https://gcc.gnu.org/viewcvs?rev=219339&root=gcc&view=rev
Log:
    PR sanitizer/64336
    * tree.c (build2_stat): Fix up initialization of TREE_READONLY
    and TREE_THIS_VOLATILE for MEM_REFs.
    (build5_stat): Fix up initialization of TREE_READONLY and
    TREE_THIS_VOLATILE for TARGET_MEM_REFs.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree.c


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

* [Bug sanitizer/64336] Template functions are not instrumented at -O0 and -Og
  2014-12-17  7:21 [Bug sanitizer/64336] New: Template functions are not instrumented at -O0 and -Og bernd.edlinger at hotmail dot de
                   ` (2 preceding siblings ...)
  2015-01-08  9:21 ` jakub at gcc dot gnu.org
@ 2015-01-08  9:57 ` jakub at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-01-08  9:57 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Should be fixed now.


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

end of thread, other threads:[~2015-01-08  9:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-17  7:21 [Bug sanitizer/64336] New: Template functions are not instrumented at -O0 and -Og bernd.edlinger at hotmail dot de
2014-12-17  9:03 ` [Bug sanitizer/64336] " bernd.edlinger at hotmail dot de
2014-12-17  9:49 ` jakub at gcc dot gnu.org
2015-01-08  9:21 ` jakub at gcc dot gnu.org
2015-01-08  9:57 ` jakub at gcc dot gnu.org

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).