Index: cfe/trunk/lib/CodeGen/CGClass.cpp =================================================================== --- cfe/trunk/lib/CodeGen/CGClass.cpp +++ cfe/trunk/lib/CodeGen/CGClass.cpp @@ -2031,7 +2031,7 @@ /*ParamsToSkip*/ 0, Order); EmitCXXConstructorCall(D, Type, ForVirtualBase, Delegating, This, Args, - Overlap); + Overlap, E->getExprLoc()); } static bool canEmitDelegateCallArgs(CodeGenFunction &CGF, @@ -2064,14 +2064,14 @@ bool Delegating, Address This, CallArgList &Args, - AggValueSlot::Overlap_t Overlap) { + AggValueSlot::Overlap_t Overlap, + SourceLocation Loc) { const CXXRecordDecl *ClassDecl = D->getParent(); // C++11 [class.mfct.non-static]p2: // If a non-static member function of a class X is called for an object that // is not of type X, or of a type derived from X, the behavior is undefined. - // FIXME: Provide a source location here. - EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, SourceLocation(), + EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, Loc, This.getPointer(), getContext().getRecordType(ClassDecl)); if (D->isTrivial() && D->isDefaultConstructor()) { @@ -2180,7 +2180,8 @@ } EmitCXXConstructorCall(D, Ctor_Base, ForVirtualBase, /*Delegating*/false, - This, Args, AggValueSlot::MayOverlap); + This, Args, AggValueSlot::MayOverlap, + E->getLocation()); } void CodeGenFunction::EmitInlinedInheritingCXXConstructorCall( @@ -2277,7 +2278,7 @@ /*ParamsToSkip*/ 1); EmitCXXConstructorCall(D, Ctor_Complete, false, false, This, Args, - AggValueSlot::MayOverlap); + AggValueSlot::MayOverlap, E->getExprLoc()); } void @@ -2313,7 +2314,7 @@ EmitCXXConstructorCall(Ctor, CtorType, /*ForVirtualBase=*/false, /*Delegating=*/true, This, DelegateArgs, - AggValueSlot::MayOverlap); + AggValueSlot::MayOverlap, Loc); } namespace { Index: cfe/trunk/lib/CodeGen/CodeGenFunction.h =================================================================== --- cfe/trunk/lib/CodeGen/CodeGenFunction.h +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h @@ -2362,7 +2362,8 @@ void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type, bool ForVirtualBase, bool Delegating, Address This, CallArgList &Args, - AggValueSlot::Overlap_t Overlap); + AggValueSlot::Overlap_t Overlap, + SourceLocation Loc); /// Emit assumption load for all bases. Requires to be be called only on /// most-derived class and not under construction of the object. Index: cfe/trunk/test/CodeGenCXX/ubsan-ctor-srcloc.cpp =================================================================== --- cfe/trunk/test/CodeGenCXX/ubsan-ctor-srcloc.cpp +++ cfe/trunk/test/CodeGenCXX/ubsan-ctor-srcloc.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux -emit-llvm -fsanitize=alignment -fblocks %s -o %t.ll +// RUN: FileCheck -check-prefix=ZEROINIT < %t.ll %s +// RUN: FileCheck -check-prefix=SRCLOC < %t.ll %s +// ZEROINIT-NOT: @{{.+}} = private unnamed_addr global {{.+}} zeroinitializer + +struct A { + A(int); + int k; +}; + +struct B : A { + B(); + B(const B &); +// SRCLOC-DAG: @{{.+}} = private unnamed_addr global {{.+}} @.src, i32 [[@LINE+1]], i32 12 } + using A::A; + void f() const; +}; + +// SRCLOC-DAG: @{{.+}} = private unnamed_addr global {{.+}} @.src, i32 [[@LINE+1]], i32 10 } +B::B() : A(1) {} + +void foo() { + B b(2); +// SRCLOC-DAG: @{{.+}} = private unnamed_addr global {{.+}} @.src, i32 [[@LINE+1]], i32 5 } + ^{b.f();}(); +}