[LLVMbugs] [Bug 2830] New: Cpp Backend doesn' t generate correct code for Switch instructions

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Fri Sep 26 02:19:03 PDT 2008


           Summary: Cpp Backend doesn't generate correct code for Switch
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: miscompilation
          Severity: normal
          Priority: P2
         Component: Backend: C
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: bobby at sharedrealm.com
                CC: llvmbugs at cs.uiuc.edu

Created an attachment (id=2039)
 --> (http://llvm.org/bugs/attachment.cgi?id=2039)
bitcode containing switch insturction with 'i32 0' case statement.

I am trying to compile some bitcode to LLVM API calls using the Cpp backend:
llc -march=cpp --cppgen=program -o test.cpp test.bc

Compiling the generated C++ code fails with this error:

test.cpp: In function 'llvm::Module* makeLLVMModule()':
test.cpp:148: error: invalid conversion from 'llvm::Constant*' to
test.cpp:148: error:   initializing argument 1 of 'void
llvm::SwitchInst::addCase(llvm::ConstantInt*, llvm::BasicBlock*)'

The problem is with this LLVM IR code:
  switch i32 %1, label %bb5 [
    i32 0, label %bb6
    i32 1, label %bb2

The 'i32' constants '0' & '1' are defined with this c++ code:
  // Constant Definitions
  Constant* const_int32_7 = Constant::getNullValue(IntegerType::get(32));
  ConstantInt* const_int32_8 = ConstantInt::get(APInt(32,  "1", 1, 10));

and the switch instruction is created with this code:

    SwitchInst* void_11 = SwitchInst::Create(int32_10, label_bb5, 3,
    void_11->addCase(const_int32_7, label_bb6);
    void_11->addCase(const_int32_8, label_bb2);

The 'addCase' method accepts a llvm::ConstantInt* as it's first argument, but
the 'i32 0' constant was created as just an 'llvm::Constant*'

P.S. Can someone add a "Backend: Cpp" Component to Bugzilla.

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