133 lines · plain
1; RUN: opt -S -passes=globalopt < %s | FileCheck %s2source_filename = "struct.c"3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"4target triple = "x86_64-unknown-linux-gnu"5 6%struct.mystruct = type { x86_fp80, i32, [12 x i8] }7 8; Generated from:9;10; static struct mystruct {11; long double a;12; int b;13; } static_struct;14; void __attribute__((nodebug)) foo(int in) { static_struct.a = in; }15; void __attribute__((nodebug)) bar(int in) { static_struct.b = in; }16; int main(int argc, char **argv)17; {18; foo(argv[0][1]);19; bar(argv[0][1]);20; return (static_struct.a + static_struct.b) > 0;21; }22;23; using clang -O0 -g2 -S -emit-llvm24 25@static_struct = internal global %struct.mystruct zeroinitializer, align 16, !dbg !026 27; CHECK: @static_struct.0 = internal unnamed_addr global x86_fp80 0xK00000000000000000000, align 16, !dbg ![[EL0:.*]]28; CHECK: @static_struct.1 = internal unnamed_addr global i32 0, align 16, !dbg ![[EL1:.*]]29 30; CHECK: ![[EL0]] = !DIGlobalVariableExpression(var: ![[VAR:.*]], expr: !DIExpression(DW_OP_LLVM_fragment, 0, 128))31; CHECK: ![[VAR]] = distinct !DIGlobalVariable(name: "static_struct"32; CHECK: ![[EL1]] = !DIGlobalVariableExpression(var: ![[VAR]], expr: !DIExpression(DW_OP_LLVM_fragment, 128, 32))33 34; Function Attrs: noinline nounwind optnone uwtable35define void @foo(i32 %in) #0 {36entry:37 %in.addr = alloca i32, align 438 store i32 %in, ptr %in.addr, align 439 %0 = load i32, ptr %in.addr, align 440 %conv = sitofp i32 %0 to x86_fp8041 store x86_fp80 %conv, ptr @static_struct, align 1642 ret void43}44 45; Function Attrs: noinline nounwind optnone uwtable46define void @bar(i32 %in) #0 {47entry:48 %in.addr = alloca i32, align 449 store i32 %in, ptr %in.addr, align 450 %0 = load i32, ptr %in.addr, align 451 store i32 %0, ptr getelementptr inbounds (%struct.mystruct, ptr @static_struct, i32 0, i32 1), align 1652 ret void53}54 55; Function Attrs: noinline nounwind optnone uwtable56define i32 @main(i32 %argc, ptr %argv) #0 !dbg !16 {57entry:58 %retval = alloca i32, align 459 %argc.addr = alloca i32, align 460 %argv.addr = alloca ptr, align 861 store i32 0, ptr %retval, align 462 store i32 %argc, ptr %argc.addr, align 463 call void @llvm.dbg.declare(metadata ptr %argc.addr, metadata !22, metadata !DIExpression()), !dbg !2364 store ptr %argv, ptr %argv.addr, align 865 call void @llvm.dbg.declare(metadata ptr %argv.addr, metadata !24, metadata !DIExpression()), !dbg !2566 %0 = load ptr, ptr %argv.addr, align 8, !dbg !2667 %1 = load ptr, ptr %0, align 8, !dbg !2668 %arrayidx1 = getelementptr inbounds i8, ptr %1, i64 1, !dbg !2669 %2 = load i8, ptr %arrayidx1, align 1, !dbg !2670 %conv = sext i8 %2 to i32, !dbg !2671 call void @foo(i32 %conv), !dbg !2772 %3 = load ptr, ptr %argv.addr, align 8, !dbg !2873 %4 = load ptr, ptr %3, align 8, !dbg !2874 %arrayidx3 = getelementptr inbounds i8, ptr %4, i64 1, !dbg !2875 %5 = load i8, ptr %arrayidx3, align 1, !dbg !2876 %conv4 = sext i8 %5 to i32, !dbg !2877 call void @bar(i32 %conv4), !dbg !2978 %6 = load x86_fp80, ptr @static_struct, align 16, !dbg !3079 %7 = load i32, ptr getelementptr inbounds (%struct.mystruct, ptr @static_struct, i32 0, i32 1), align 16, !dbg !3180 %conv5 = sitofp i32 %7 to x86_fp80, !dbg !3281 %add = fadd x86_fp80 %6, %conv5, !dbg !3382 %cmp = fcmp ogt x86_fp80 %add, 0xK00000000000000000000, !dbg !3483 %conv6 = zext i1 %cmp to i32, !dbg !3484 ret i32 %conv6, !dbg !3585}86 87; Function Attrs: nounwind readnone speculatable88declare void @llvm.dbg.declare(metadata, metadata, metadata) #189 90attributes #0 = { noinline nounwind optnone uwtable }91attributes #1 = { nounwind readnone speculatable }92 93!llvm.dbg.cu = !{!2}94!llvm.module.flags = !{!12, !13, !14}95!llvm.ident = !{!15}96 97!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())98!1 = distinct !DIGlobalVariable(name: "static_struct", scope: !2, file: !3, line: 4, type: !6, isLocal: true, isDefinition: true)99!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)100!3 = !DIFile(filename: "struct.c", directory: "/")101!4 = !{}102!5 = !{!0}103!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "mystruct", file: !3, line: 1, size: 256, elements: !7)104!7 = !{!8, !10}105!8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !3, line: 2, baseType: !9, size: 128)106!9 = !DIBasicType(name: "long double", size: 128, encoding: DW_ATE_float)107!10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !3, line: 3, baseType: !11, size: 32, offset: 128)108!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)109!12 = !{i32 2, !"Dwarf Version", i32 4}110!13 = !{i32 2, !"Debug Info Version", i32 3}111!14 = !{i32 1, !"wchar_size", i32 4}112!15 = !{!"clang version 7.0.0"}113!16 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 7, type: !17, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4)114!17 = !DISubroutineType(types: !18)115!18 = !{!11, !11, !19}116!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)117!20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64)118!21 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)119!22 = !DILocalVariable(name: "argc", arg: 1, scope: !16, file: !3, line: 7, type: !11)120!23 = !DILocation(line: 7, column: 14, scope: !16)121!24 = !DILocalVariable(name: "argv", arg: 2, scope: !16, file: !3, line: 7, type: !19)122!25 = !DILocation(line: 7, column: 27, scope: !16)123!26 = !DILocation(line: 9, column: 9, scope: !16)124!27 = !DILocation(line: 9, column: 5, scope: !16)125!28 = !DILocation(line: 10, column: 9, scope: !16)126!29 = !DILocation(line: 10, column: 5, scope: !16)127!30 = !DILocation(line: 11, column: 27, scope: !16)128!31 = !DILocation(line: 11, column: 45, scope: !16)129!32 = !DILocation(line: 11, column: 31, scope: !16)130!33 = !DILocation(line: 11, column: 29, scope: !16)131!34 = !DILocation(line: 11, column: 48, scope: !16)132!35 = !DILocation(line: 11, column: 5, scope: !16)133