[llvm] r319230 - SROA: Don't create variable fragments that are outside of the variable.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 28 13:30:38 PST 2017


Author: adrian
Date: Tue Nov 28 13:30:38 2017
New Revision: 319230

URL: http://llvm.org/viewvc/llvm-project?rev=319230&view=rev
Log:
SROA: Don't create variable fragments that are outside of the variable.

An alloca may be larger than a variable that is described to be stored
there. Don't create a dbg.value for fragments that are outside of the
variable.

This fixes PR35447.
https://bugs.llvm.org/show_bug.cgi?id=35447

Added:
    llvm/trunk/test/DebugInfo/Generic/sroa-larger.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/SROA.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=319230&r1=319229&r2=319230&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Tue Nov 28 13:30:38 2017
@@ -4134,6 +4134,15 @@ bool SROA::splitAlloca(AllocaInst &AI, A
                  "new fragment is outside of original fragment");
           Start -= OrigFragment->OffsetInBits;
         }
+
+        // The alloca may be larger than the variable.
+        if (VarSize) {
+          if (Size > *VarSize)
+            Size = *VarSize;
+          if (Size == 0 || Start + Size > *VarSize)
+            continue;
+        }
+
         // Avoid creating a fragment expression that covers the entire variable.
         if (!VarSize || *VarSize != Size) {
           if (auto E =

Added: llvm/trunk/test/DebugInfo/Generic/sroa-larger.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/sroa-larger.ll?rev=319230&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/sroa-larger.ll (added)
+++ llvm/trunk/test/DebugInfo/Generic/sroa-larger.ll Tue Nov 28 13:30:38 2017
@@ -0,0 +1,85 @@
+; RUN: opt -sroa -S -o - %s | FileCheck %s
+; Generated from clang -c  -O2 -g -target x86_64-pc-windows-msvc
+; struct A {
+;   int _Myval2;
+;   A() : _Myval2() {}
+; };
+; struct B {
+;   double buffer[];
+; };
+; struct C {
+;   C(int) {}
+;   A _Mypair;
+; };
+; int getPtr();
+; struct D {
+;   C takePayload() {
+;     C Tmp(getPtr());
+;     return Tmp;
+;   }
+; } Dd;
+; void *operator new(size_t, void *);
+; struct F {
+;   F(D Err) : HasError() {
+;     C *e = (C *)(ErrorStorage.buffer);
+;     new (e) C(Err.takePayload());
+;   }
+;   B ErrorStorage;
+;   bool HasError;
+; };
+; F fn2() { return Dd; }
+; void fn3() { fn2(); }
+source_filename = "test.ll"
+
+%struct.F = type { %struct.B, i8 }
+%struct.B = type { [0 x double], [8 x i8] }
+
+define void @"\01?fn3@@YAXXZ"() local_unnamed_addr !dbg !6 {
+entry:
+  %tmp = alloca %struct.F, align 8
+  %0 = bitcast %struct.F* %tmp to i8*
+  call void @llvm.lifetime.start.p0i8(i64 16, i8* %0)
+  call void @llvm.dbg.declare(metadata %struct.F* %tmp, metadata !10, metadata !DIExpression()), !dbg !14
+  ; CHECK-NOT: !DIExpression(DW_OP_LLVM_fragment, 32, 96)
+  ; CHECK: call void @llvm.dbg.value(metadata i32 0, metadata !10, metadata !DIExpression())
+  %_Myval2.i.i.i.i.i = bitcast %struct.F* %tmp to i32*
+  store i32 0, i32* %_Myval2.i.i.i.i.i, align 8
+  ret void
+}
+
+; Function Attrs: argmemonly nounwind
+declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #0
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+attributes #0 = { argmemonly nounwind }
+attributes #1 = { nounwind readnone speculatable }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 6.0.0 (trunk 319178) (llvm/trunk 319187)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "test.cpp", directory: "/")
+!2 = !{i32 2, !"Dwarf Version", i32 4}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 2}
+!5 = !{i32 7, !"PIC Level", i32 2}
+!6 = distinct !DISubprogram(name: "fn3", linkageName: "\01?fn3@@YAXXZ", scope: !1, file: !1, line: 30, type: !7, isLocal: false, isDefinition: true, scopeLine: 30, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !9)
+!7 = !DISubroutineType(types: !8)
+!8 = !{null}
+!9 = !{}
+!10 = !DILocalVariable(name: "Tmp", scope: !11, file: !1, line: 16, type: !23)
+!11 = distinct !DISubprogram(name: "takePayload", linkageName: "\01?takePayload at D@@QEAA?AUC@@XZ", scope: !12, file: !1, line: 15, type: !7, isLocal: false, isDefinition: true, scopeLine: 15, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !13, variables: !9)
+!12 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "D", file: !1, line: 14, size: 8, elements: !9, identifier: ".?AUD@@")
+!13 = !DISubprogram(name: "takePayload", linkageName: "\01?takePayload at D@@QEAA?AUC@@XZ", scope: !12, file: !1, line: 15, type: !7, isLocal: false, isDefinition: false, scopeLine: 15, flags: DIFlagPrototyped, isOptimized: true)
+!14 = !DILocation(line: 16, column: 7, scope: !11, inlinedAt: !15)
+!15 = distinct !DILocation(line: 24, column: 19, scope: !16, inlinedAt: !20)
+!16 = distinct !DILexicalBlock(scope: !17, file: !1, line: 22, column: 25)
+!17 = distinct !DISubprogram(name: "F", linkageName: "\01??0F@@QEAA at UD@@@Z", scope: !18, file: !1, line: 22, type: !7, isLocal: false, isDefinition: true, scopeLine: 22, flags: DIFlagPrototyped, isOptimized: true, unit: !0, declaration: !19, variables: !9)
+!18 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "F", file: !1, line: 21, size: 128, elements: !9, identifier: ".?AUF@@")
+!19 = !DISubprogram(name: "F", scope: !18, file: !1, line: 22, type: !7, isLocal: false, isDefinition: false, scopeLine: 22, flags: DIFlagPrototyped, isOptimized: true)
+!20 = distinct !DILocation(line: 29, column: 18, scope: !21, inlinedAt: !22)
+!21 = distinct !DISubprogram(name: "fn2", linkageName: "\01?fn2@@YA?AUF@@XZ", scope: !1, file: !1, line: 29, type: !7, isLocal: false, isDefinition: true, scopeLine: 29, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !9)
+!22 = distinct !DILocation(line: 30, column: 14, scope: !6)
+!23 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "C", file: !1, line: 9, size: 32, elements: !9, identifier: ".?AUC@@")




More information about the llvm-commits mailing list