Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
sway
llvm source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
clang (assertions trunk)
clang (trunk)
clang 10.0.0
clang 10.0.1
clang 11.0.0
clang 11.0.1
clang 12.0.0
clang 12.0.1
clang 13.0.0
clang 14.0.0
clang 15.0.0
clang 16.0.0
clang 17.0.1
clang 18.1.0
clang 19.1.0
clang 20.1.0
clang 21.1.0
clang 4.0.1
clang 5.0.0
clang 6.0.0
clang 7.0.0
clang 8.0.0
clang 9.0.0
hexagon-clang 16.0.5
llc (assertions trunk)
llc (trunk)
llc 10.0.0
llc 10.0.1
llc 11.0.0
llc 11.0.1
llc 12.0.0
llc 12.0.1
llc 13.0.0
llc 14.0.0
llc 15.0.0
llc 16.0.0
llc 17.0.1
llc 18.1.0
llc 19.1.0
llc 20.1.0
llc 21.1.0
llc 3.2
llc 3.3
llc 3.9.1
llc 4.0.0
llc 4.0.1
llc 5.0.0
llc 6.0.0
llc 7.0.0
llc 8.0.0
llc 9.0.0
opt (assertions trunk)
opt (trunk)
opt 10.0.0
opt 10.0.1
opt 11.0.0
opt 11.0.1
opt 12.0.0
opt 12.0.1
opt 13.0.0
opt 14.0.0
opt 15.0.0
opt 16.0.0
opt 17.0.1
opt 18.1.0
opt 19.1.0
opt 20.1.0
opt 21.1.0
opt 3.2
opt 3.3
opt 3.9.1
opt 4.0.0
opt 4.0.1
opt 5.0.0
opt 6.0.0
opt 7.0.0
opt 8.0.0
opt 9.0.0
Options
Source code
; RUN: llc -filetype=obj -mtriple=riscv32 -O0 -o %t.o < %s ; RUN: llvm-dwarfdump --debug-line %t.o | FileCheck %s --check-prefix=DWARF ; RUN: llvm-objdump -d %t.o | FileCheck %s --check-prefixes=DASM target datalayout = "e-m:e-p:32:32-i64:64-n32-S128" target triple = "riscv32" ; the test, need use clang --target=riscv32 -g -S x.c -o x.s ; can see the assemble ; int global_a = 10; ; __attribute__((noinline)) int foo() { ; int a = global_a; ; int b = 10; ; return a + b; ; } ; ; int main() { ; int a = foo(); ; return a; ; } @global_a = global i32 10, align 4, !dbg !0 ; PE is placed at the end of the function prologue ; DWARF: 0x0000000000000004 3 11 1 0 0 is_stmt prologue_end ; DWARF: 0x0000000000000034 9 11 1 0 0 is_stmt prologue_end ; DASM: 00000000 <foo>: ; DASM: 0: 13 01 01 ff addi sp, sp, -16 ; DASM: 4: 37 05 00 00 lui a0, 0 ; DASM: 8: 03 25 05 00 lw a0, 0(a0) ; DASM: c: 23 26 a1 00 sw a0, 12(sp) ; DASM: 10: 93 05 a0 00 addi a1, zero, 10 ; DASM: 14: 23 24 b1 00 sw a1, 8(sp) ; DASM: 18: 13 05 a5 00 addi a0, a0, 10 ; DASM: 1c: 13 01 01 01 addi sp, sp, 16 ; DASM: 20: 67 80 00 00 ret ; DASM: 00000024 <main>: ; DASM: 24: 13 01 01 ff addi sp, sp, -16 ; DASM: 28: 23 26 11 00 sw ra, 12(sp) ; DASM: 2c: 13 05 00 00 mv a0, zero ; DASM: 30: 23 24 a1 00 sw a0, 8(sp) ; DASM: 34: 97 00 00 00 auipc ra, 0 ; DASM: 38: e7 80 00 00 jalr ra ; DASM: 3c: 23 22 a1 00 sw a0, 4(sp) ; DASM: 40: 83 20 c1 00 lw ra, 12(sp) ; DASM: 44: 13 01 01 01 addi sp, sp, 16 ; DASM: 48: 67 80 00 00 ret define i32 @foo() !dbg !13 { entry: %a = alloca i32, align 4 %b = alloca i32, align 4 call void @llvm.dbg.declare(metadata i32* %a, metadata !16, metadata !DIExpression()), !dbg !17 %0 = load i32, i32* @global_a, align 4, !dbg !18 store i32 %0, i32* %a, align 4, !dbg !17 call void @llvm.dbg.declare(metadata i32* %b, metadata !19, metadata !DIExpression()), !dbg !20 store i32 10, i32* %b, align 4, !dbg !20 %1 = load i32, i32* %a, align 4, !dbg !21 %2 = load i32, i32* %b, align 4, !dbg !22 %add = add nsw i32 %1, %2, !dbg !23 ret i32 %add, !dbg !24 } declare void @llvm.dbg.declare(metadata, metadata, metadata) define i32 @main() !dbg !25 { entry: %retval = alloca i32, align 4 %a = alloca i32, align 4 store i32 0, i32* %retval, align 4 call void @llvm.dbg.declare(metadata i32* %a, metadata !26, metadata !DIExpression()), !dbg !27 %call = call i32 @foo(), !dbg !28 store i32 %call, i32* %a, align 4, !dbg !27 %0 = load i32, i32* %a, align 4, !dbg !29 ret i32 %0, !dbg !30 } !llvm.dbg.cu = !{!2} !llvm.module.flags = !{!7, !8, !9, !10, !11} !llvm.ident = !{!12} !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "global_a", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 12.0.1 (git@code.streamcomputing.com:toolchain/llvm-12.git c2154e7af9bc5f2e9d137a24c86b92a970fbd77b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) !3 = !DIFile(filename: "dwarf.c", directory: "/home/wengliqin/test") !4 = !{} !5 = !{!0} !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) !7 = !{i32 7, !"Dwarf Version", i32 4} !8 = !{i32 2, !"Debug Info Version", i32 3} !9 = !{i32 1, !"wchar_size", i32 4} !10 = !{i32 1, !"target-abi", !"ilp32"} !11 = !{i32 1, !"SmallDataLimit", i32 8} !12 = !{!"clang version 12.0.1 (git@code.streamcomputing.com:toolchain/llvm-12.git c2154e7af9bc5f2e9d137a24c86b92a970fbd77b)"} !13 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !14, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4) !14 = !DISubroutineType(types: !15) !15 = !{!6} !16 = !DILocalVariable(name: "a", scope: !13, file: !3, line: 3, type: !6) !17 = !DILocation(line: 3, column: 7, scope: !13) !18 = !DILocation(line: 3, column: 11, scope: !13) !19 = !DILocalVariable(name: "b", scope: !13, file: !3, line: 4, type: !6) !20 = !DILocation(line: 4, column: 7, scope: !13) !21 = !DILocation(line: 5, column: 10, scope: !13) !22 = !DILocation(line: 5, column: 14, scope: !13) !23 = !DILocation(line: 5, column: 12, scope: !13) !24 = !DILocation(line: 5, column: 3, scope: !13) !25 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 8, type: !14, scopeLine: 8, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4) !26 = !DILocalVariable(name: "a", scope: !25, file: !3, line: 9, type: !6) !27 = !DILocation(line: 9, column: 7, scope: !25) !28 = !DILocation(line: 9, column: 11, scope: !25) !29 = !DILocation(line: 10, column: 10, scope: !25) !30 = !DILocation(line: 10, column: 3, scope: !25)
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree