While fixing up some DWARF line number issues for Xtensa, I discovered a problem with the ia64 port of GAS. Basically, the features tested by the lns-common-1 test are broken but no one noticed because that test doesn't run on ia64. I've included an ia64-specific variant of the lns-common-1 test that demonstrates the problem. (I'm not at all familiar with ia64 assembly code, so I just made this up by looking at some other ia64 tests.) The cause of the problem is that GAS for ia64 collects the line number information, stores it in association with machine instructions, and then later calls dwarf2_gen_line_info. It does not use dwarf2_emit_insn, which is responsible for clearing the loc_directive_seen flag and several other flags associated with the line information. The patch fixes this by providing a new function to clear these flags, and by using that function in the ia64 port. I have a patch to make the Xtensa port handle line numbers in the same way as ia64, and I would also like to use this new function there. The patch also fixes a minor issue related to clearing the loc_directive_seen flag. That flag is not cleared when debug_type is set to DEBUG_DWARF2. Daniel J. recently added a check for consecutive .loc directives, and I believe that check will not cause a lot of extra calls to dwarf2_emit_insn with DEBUG_DWARF2, since the flag never gets cleared. Is this OK? gas/ * dwarf2dbg.c (dwarf2_consume_line_info): New. (dwarf2_emit_insn): Use it here. (dwarf2_directive_loc): Fix check for consecutive .loc directives when debug_type is DEBUG_DWARF2. * dwarf2dbg.h (dwarf2_consume_line_info): New prototype. * config/tc-ia64.c (ia64_flush_insns): Call dwarf2_consume_line_info. (md_assemble): Likewise. gas/testsuite/ * gas/lns/lns.exp: Run lns-common-1 with alternate source for ia64. * gas/lns/lns-common-1-ia64.s: New file.