[llvm-bugs] [Bug 26846] New: UBSan fails to deduplicate reports from template instantiations

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 4 17:06:39 PST 2016


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: unassignedclangbugs at nondot.org
          Reporter: vonosmas at gmail.com
                CC: llvm-bugs at lists.llvm.org, richard-llvm at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160305/2d8c67fb/attachment.html>


More information about the llvm-bugs mailing list