[cfe-dev] Debug information for unconditional branches

Tim Besard tim.besard at elis.ugent.be
Mon Mar 25 04:15:03 PDT 2013


Hi all,

Since revisions 128471 and 128513 (March 2011) Clang does not emit debug
information for unconditional branches anymore, for example when
branching from the end of an else{} to the continuation block
(CodeGen/CGStmt.cpp line 459 in r177848). Why exactly is this?

I'm running into this because I'm identifying loop latches based on
their lexical scope. Normally, loop latches always have debug metadata
attached to them. However, in some cases -simplifycfg can merge the loop
latch with a branch which has no debug metadata attached to it (due to
aforementioned reason) causing the final latch not to have debug
metadata either.

Specifically, I have this testcase:
  while (while_test()) {
    if (if_test()) {
      foo();
    } else {
      bar();
    }
  }

Clang emits the following bytecode for this:
  while.cond:
    %call = call zeroext i1 (...)* @while_test(), !dbg !9
    br i1 %call, label %while.body, label %while.end, !dbg !9
  while.body:
    %call1 = call zeroext i1 (...)* @if_test(), !dbg !10
    br i1 %call1, label %if.then, label %if.else, !dbg !10
  if.then:
    call void (...)* @foo(), !dbg !12
    br label %if.end, !dbg !14
  if.else:
    call void (...)* @bar(), !dbg !15
    br label %if.end
  if.end:
    br label %while.cond, !dbg !17
  while.end:
    ret i32 0, !dbg !18
Note that the unconditional branch at the end of if.else does not have
debug metadata attached to it.

When running -simplifycfg, LLVM merges if.else and if.end as follows:
  if.else:
    call void (...)* @bar(), !dbg !15
    br label %while.cond

The end result of all this is that the loop latch does not have any
metadata attached to it, not only breaking my loop identification, but
presumable also making it impossible to stop at the end of the while
body (something which was possible before running -simplifycfg).

How should this be fixed? Should -simplifycfg have support for
'properly' merging these statements, or should Clang emit debug
statements despite the branch being unconditional?

Sincerely,
-- 
Tim Besard
Computer Systems Lab
Department of Electronics & Information Systems
Ghent University



More information about the cfe-dev mailing list