Index: lib/Transforms/Scalar/SROA.cpp =================================================================== --- lib/Transforms/Scalar/SROA.cpp +++ lib/Transforms/Scalar/SROA.cpp @@ -4029,6 +4029,8 @@ NewAI = new AllocaInst( SliceTy, AI.getType()->getAddressSpace(), nullptr, Alignment, AI.getName() + ".sroa." + Twine(P.begin() - AS.begin()), &AI); + // Copy the old AI debug location over to the new one + NewAI->setDebugLoc(AI.getDebugLoc()); ++NumNewAllocas; } Index: test/Transforms/SROA/alloca-debugloc.ll =================================================================== --- /dev/null +++ test/Transforms/SROA/alloca-debugloc.ll @@ -0,0 +1,29 @@ +; RUN: opt -debugify -instcombine -sroa -S < %s | FileCheck %s + +; Check that when sroa rewrites the alloca partition +; for the baz vector, it preserves the original DebugLocation + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" + +define dso_local void @foo() { +entry: + %baz = alloca [6 x i32], align 16 + %qaz = alloca i32, align 4 + %0 = bitcast [6 x i32]* %baz to i8* + call void @llvm.memset.p0i8.i64(i8* align 16 %0, i8 0, i64 24, i1 false) + %arrayidx = getelementptr inbounds [6 x i32], [6 x i32]* %baz, i64 0, i64 2 + %1 = load i32, i32* %arrayidx, align 8 + %call = call i32 @bar(i32 %1) + %arraydecay = getelementptr inbounds [6 x i32], [6 x i32]* %baz, i32 0, i32 0 + %2 = ptrtoint i32* %arraydecay to i32 + store i32 %2, i32* %qaz, align 4 + ret void +} + +declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1) +declare dso_local i32 @bar(i32) + +; CHECK: entry: +; CHECK-NEXT: {{.*}} = alloca {{.*}} !dbg ![[DbgLoc:[0-9]+]] + +; CHECK: ![[DbgLoc]] = !DILocation(