This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug sanitizer/64336] New: Template functions are not instrumented at -O0 and -Og


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]