[LLVMbugs] [Bug 10170] New: opt std-compile-opts wronly optimizes trap instruction

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jun 22 05:33:07 PDT 2011


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

           Summary: opt std-compile-opts wronly optimizes trap instruction
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: martijn at martijnrutten.com
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=6759)
 --> (http://llvm.org/bugs/attachment.cgi?id=6759)
Source code that triggers the error (returns 2 iso. trap)

opt -std-compile-opts creates wrong code in case of a llvm.trap() instruction
in the following example code 'trap.c' (extracted from a coding bug in the
OpenCV library)

  #include <stdio.h>

  int foo(int **p) {
    if (!p && !*p) return 1; /* trap on *p if p is 0 */
    return 2;
  }

  int main() {
    return foo(NULL);
  }

To reproduce:
Environment: 32 bits Ubuntu 10.4
clang and llvm from svn trunk revision r133615 (2011-06-22)

clang -O1 trap.c -c -emit-llvm -o trap.bc
opt -std-compile-opts trap.bc -o trap.opt.bc
llvm-dis trap.opt.bc

This gives trap.opt.ll (snippet):

  define i32 @foo(i32** %p) nounwind readonly {
  entry:
    %tobool = icmp eq i32** %p, null
    br i1 %tobool, label %land.lhs.true, label %return

  land.lhs.true:                                    ; preds = %entry
    tail call void @llvm.trap()
    unreachable

  return:                                           ; preds = %entry
    ret i32 2
  }

  define i32 @main() nounwind readnone {
  entry:
    ret i32 2
  }

This shows that in main(), the call to foo() is inlined and the result=2 is
returned, whereas it should trigger the trap() instruction. Note that the clang
-O1 command still gives correct code where the call to foo is not inlined.

Interestingly, compilation with clang -O2 trap.c does give the correct result,
where inlining of foo() leads to main() direcly calling the trap() instruction.

-- 
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