Clang removes Label name

Hi,

I have some troubles to figure out why clang is removing my label name. As the simple example below shows the label "MLB" is removed and replaced by an integer as an "unnamed value".
Plus, I can see that an unconditional jump is added, as the label seems to be interpreted as the beginning of a BasicBlock. I am compiling without any optimizations (for now), what leave the produced code slower than the input one.

Anyway, the important thinks to me is to keep label name, but I can't figure out where in the code this transformation is done. My guess is, it's done by Clang while parsing, or just after. Could someone gives me some clue about the class/method where this "feature" is ?

Input:
int main() {
    int i=0;
MLB:
    return i;
}

Result:
define i32 @main() #0 {
  %1 = alloca i32, align 4
  %i = alloca i32, align 4
  store i32 0, i32* %1
  store i32 0, i32* %i, align 4
  br label %2

; <label>:2 ; preds = %0
  %3 = load i32* %i, align 4
  ret i32 %3
}

Hi,

So finally I found where the label was evicted. In case it's useful for someone, i needed to add: "Dest.getBlock()->setName(D->getName());" in CGStmt.cpp:360.

About the creation of the BasicBlock, It's in the same method, but as expected it's removed with optimization (O1,O2,O3) and the label name is kept trough CFG optimizations.

Cheers,
Benjamin Rouxel

In LLVM, every block must explicitly specify how control flows out of that block, the order that blocks are printed to text / bitcode has no effect on the control flow whatsoever.
The label forces the creation of a second block, so the first one must end with a branch to it. Since there’s only one code path, LLVM will later merge the two blocks together.