Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -1346,11 +1346,9 @@ /// Add a Dwarf loclistptr attribute data and value. void DwarfCompileUnit::addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index) { - dwarf::Form Form = dwarf::DW_FORM_data4; - if (DD->getDwarfVersion() == 4) - Form =dwarf::DW_FORM_sec_offset; - if (DD->getDwarfVersion() >= 5) - Form =dwarf::DW_FORM_loclistx; + dwarf::Form Form = (DD->getDwarfVersion() >= 5) + ? dwarf::DW_FORM_loclistx + : DD->getDwarfSectionOffsetForm(); Die.addValue(DIEValueAllocator, Attribute, Form, DIELocList(Index)); } Index: llvm/test/DebugInfo/X86/DW_AT_location-reference.ll =================================================================== --- llvm/test/DebugInfo/X86/DW_AT_location-reference.ll +++ llvm/test/DebugInfo/X86/DW_AT_location-reference.ll @@ -1,8 +1,17 @@ ; RUN: llc -O1 -filetype=obj -mtriple=x86_64-apple-darwin < %s > %t -; RUN: llvm-dwarfdump -v %t | FileCheck %s +; RUN: llvm-dwarfdump -v %t | FileCheck %s --check-prefixes=CHECK,DWARFv4 ; RUN: llvm-objdump -r %t | FileCheck --check-prefix=DARWIN %s + ; RUN: llc -O1 -filetype=obj -mtriple=x86_64-pc-linux-gnu < %s > %t -; RUN: llvm-dwarfdump -v %t | FileCheck %s +; RUN: llvm-dwarfdump -v %t | FileCheck %s --check-prefixes=CHECK,DWARFv4 +; RUN: llvm-objdump -r %t | FileCheck --check-prefix=LINUX %s + +; RUN: llc -dwarf-version=3 -O1 -filetype=obj -mtriple=x86_64-pc-linux-gnu < %s > %t +; RUN: llvm-dwarfdump -debug-info -v %t | FileCheck %s --check-prefixes=CHECK,DWARF32v3 +; RUN: llvm-objdump -r %t | FileCheck --check-prefix=LINUX %s + +; RUN: llc -dwarf64 -dwarf-version=3 -O1 -filetype=obj -mtriple=x86_64-pc-linux-gnu < %s > %t +; RUN: llvm-dwarfdump -debug-info -v %t | FileCheck %s --check-prefixes=CHECK,DWARF64v3 ; RUN: llvm-objdump -r %t | FileCheck --check-prefix=LINUX %s ; PR9493 @@ -31,7 +40,9 @@ ; // The 'x' variable and its symbol reference location ; CHECK: .debug_info contents: ; CHECK: DW_TAG_variable -; CHECK-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x00000000 +; DWARF32v3-NEXT: DW_AT_location [DW_FORM_data4] (0x00000000 +; DWARF64v3-NEXT: DW_AT_location [DW_FORM_data8] (0x00000000 +; DWARFv4-NEXT: DW_AT_location [DW_FORM_sec_offset] (0x00000000 ; Check that the location contains only 4 ranges. ; CHECK-NEXT: [0x{{[0-9a-f]*}}, 0x{{[0-9a-f]*}}) ; CHECK-NEXT: [0x{{[0-9a-f]*}}, 0x{{[0-9a-f]*}})