https://llvm.org/bugs/show_bug.cgi?id=26846

            Bug ID: 26846
           Summary: UBSan fails to deduplicate reports from template
                    instantiations
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangb...@nondot.org
          Reporter: vonos...@gmail.com
                CC: llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk
    Classification: Unclassified

Arguably, it should.

$ cat tmp/a.cc
#include <stdio.h>

struct C {
  void print(int x) { fprintf(stderr, "This is %d\n", x); }
};

template <typename T>
void f(C* c, T t) {
  c->print((int)t);
}

int main() {
  C* c = NULL;
  f<int>(c, 2);
  f<double>(c, 3.0);
  return 0;
}
$ ./bin/clang++ -fsanitize=null tmp/a.cc -O1 ; ./a.out
tmp/a.cc:9:3: runtime error: member call on null pointer of type 'C'
This is 2
tmp/a.cc:9:3: runtime error: member call on null pointer of type 'C'
This is 3

Sadly, we print the error twice for the exact same source location and type.
This what deduplication was implemented for, but for some reason it's not
triggering here, although the "static data" we pass to the handlers is exactly
the same:

$ ./bin/clang++ -fsanitize=null tmp/a.cc -O1 -S -emit-llvm -o a.ll
$ cat a.ll
<...>
@.src = private unnamed_addr constant [9 x i8] c"tmp/a.cc\00", align 1
@0 = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x
i8] c"'C'\00" }
@1 = private unnamed_addr global { { [9 x i8]*, i32, i32 }, { i16, i16, [4 x
i8] }*, i64, i8 } { { [9 x i8]*, i32, i32 } { [9 x i8]* @.src, i32 9, i32 3 },
{ i16, i16, [4 x i8] }* @0, i64 0, i8 4 }               
<....>
@2 = private unnamed_addr global { { [9 x i8]*, i32, i32 }, { i16, i16, [4 x
i8] }*, i64, i8 } { { [9 x i8]*, i32, i32 } { [9 x i8]* @.src, i32 9, i32 3 },
{ i16, i16, [4 x i8] }* @0, i64 0, i8 4 }


define linkonce_odr void @_Z1fIiEvP1CT_(%struct.C* %c, i32 %t) #1 comdat {
  <...>
  tail call void @__ubsan_handle_type_mismatch(i8* bitcast ({ { [9 x i8]*, i32,
i32 }, { i16, i16, [4 x i8] }*, i64, i8 }* @1 to i8*), i64 %1) #4, !nosanitize
!1 
  <...>
}

define linkonce_odr void @_Z1fIdEvP1CT_(%struct.C* %c, double %t) #1 comdat {
  <...>
  tail call void @__ubsan_handle_type_mismatch(i8* bitcast ({ { [9 x i8]*, i32,
i32 }, { i16, i16, [4 x i8] }*, i64, i8 }* @2 to i8*), i64 %1) #4, !nosanitize
!1
  <...>
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to