llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

'tbaa vtable pointer' attr is missed for member function pointer deref

Open KernelAddress opened this issue 12 years ago • 4 comments

Bugzilla Link 19113
Resolution FIXED
Resolved on Mar 12, 2014 13:29
Version trunk
OS Linux
CC @KernelAddress,@eugenis,@kcc,@zygoloid,@timurrrr

Extended Description

$ clang -v clang version 3.5.0 (203643) Target: x86_64-unknown-linux-gnu

$ cat vptr.cc struct X { virtual void foo(); }; void foo(X *x) { x->foo(); } void bar(X *x, void (X::*fn)()) { (x->*fn)();
}

$ clang++ vptr.cc -O1 -S -emit-llvm

$ cat vptr.ll ; ModuleID = '/tmp/vptr.cc' target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu"

%struct.X = type { i32 (...)** }

; Function Attrs: uwtable define void @​_Z3fooP1X(%struct.X* %x) #​0 { %1 = bitcast %struct.X* %x to void (%struct.X*)*** %2 = load void (%struct.X*)*** %1, align 8, !tbaa !​1 %3 = load void (%struct.X*)** %2, align 8 tail call void %3(%struct.X* %x) ret void }

; Function Attrs: uwtable define void @​_Z3barP1XMS_FvvE(%struct.X* %x, i64 %fn.coerce0, i64 %fn.coerce1) #​0 { %1 = bitcast %struct.X* %x to i8* %2 = getelementptr inbounds i8* %1, i64 %fn.coerce1 %3 = bitcast i8* %2 to %struct.X* %4 = and i64 %fn.coerce0, 1 %5 = icmp eq i64 %4, 0 br i1 %5, label %13, label %6

;

;

;

attributes #​0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

!llvm.ident = !{#0}

!​0 = metadata !{metadata !"clang version 3.5.0 (203643)"} !​1 = metadata !{metadata !​2, metadata !​2, i64 0} !​2 = metadata !{metadata !"vtable pointer", metadata !​3, i64 0} !​3 = metadata !{metadata !"Simple C/C++ TBAA"}

============================================================

vptr load in foo() is marked with !tbaa !​1 vptr load in bar() (%12 = load void (%struct.X*)** %11, align 8) is not marked with !tbaa !​1

This breaks ThreadSanitizer instrumentation pass, and leads to worse race reports.

KernelAddress avatar Mar 12 '14 10:03 KernelAddress

that was quick thanks!

KernelAddress avatar Mar 12 '14 20:03 KernelAddress

Fixed in r203691.

+mren, rsmith who seem to be working with tbaa in the past

KernelAddress avatar Mar 12 '14 10:03 KernelAddress

I've added a disabled test for this issue in r203646.

KernelAddress avatar Mar 12 '14 10:03 KernelAddress