[LLVMbugs] [Bug 10829] New: Possible problem with debug metadata generated for empty 'return' statements

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Sep 1 09:43:25 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=10829

           Summary: Possible problem with debug metadata generated for
                    empty 'return' statements
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: eliben at gmail.com
                CC: llvmbugs at cs.uiuc.edu


Consider this C code:

    void func(char c, char* d)
    {
        *d = c + 1;
        return;
    }

The LLVM IR generated with "clang -g -S -O0 -emit-llvm" is:

    define void @func(i8 signext %c, i8* %d) nounwind {
    entry:
      %c.addr = alloca i8, align 1
      %d.addr = alloca i8*, align 4
      store i8 %c, i8* %c.addr, align 1
      call void @llvm.dbg.declare(metadata !{i8* %c.addr}, metadata !11), !dbg
!13
      store i8* %d, i8** %d.addr, align 4
      call void @llvm.dbg.declare(metadata !{i8** %d.addr}, metadata !14), !dbg
!16
      %tmp = load i8* %c.addr, align 1, !dbg !17
      %conv = sext i8 %tmp to i32, !dbg !17
      %add = add nsw i32 %conv, 1, !dbg !17
      %conv1 = trunc i32 %add to i8, !dbg !17
      %tmp2 = load i8** %d.addr, align 4, !dbg !17
      store i8 %conv1, i8* %tmp2, !dbg !17
      ret void, !dbg !19
    }

Relevant metadata nodes:

    !17 = metadata !{i32 3, i32 5, metadata !18, null}
    !19 = metadata !{i32 5, i32 1, metadata !18, null}

As you can see, the metadata node attached to the 'ret void' instruction
reports line 5, although the 'return' is on line 4. This is an error, which
will cause a breakpoint placed on the 'return' not to stop there.
Some preliminary investigation in the source code of Clang reveals that in all
likeness Clang optimizes away the empty "return" at the end of the function,
using its own return inserted by CodeGenFunction::EmitFunctionEpilog

Examination of emitted AST shows that the return statement appears there, so
the optimization is done after that.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list