LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1492 - Wrong arguments for main() trigger assert in lli
Summary: Wrong arguments for main() trigger assert in lli
Status: RESOLVED FIXED
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Anton Korobeynikov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-03 11:37 PDT by Maarten ter Huurne
Modified: 2010-02-22 12:46 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maarten ter Huurne 2007-06-03 11:37:59 PDT
This program contains a bug: (argv and argc are swapped)

int main(char** argv, int argc) {
	return 0;
}

I compile it to bytecode like this:

$ llvm-g++ --emit-llvm -o wrongmain.bc -c wrongmain.cc

And then run it in the LLVM interpreter like this:

$ lli wrongmain.bc

Which triggers the following assertion:

lli: Instructions.cpp:210: void llvm::CallInst::init(llvm::Value*, 
llvm::Value* const*, unsigned int): Assertion `(i >= FTy->getNumParams() || 
FTy->getParamType(i) == Params[i]->getType()) && "Calling a function with a 
bad signature!"' failed.
lli((anonymous namespace)::PrintStackTrace()+0x19)[0x847fcb9]
/lib/libc.so.6(abort+0x101)[0xb7ce7801]
/lib/libc.so.6(__assert_fail+0xfb)[0xb7cdf7bb]
lli(llvm::CallInst::init(llvm::Value*, llvm::Value* const*, unsigned 
int)+0x181)[0x841adb1]
Aborted

I'm using LLVM 2.0 and its g++ front-end, compiled from source with GCC 4.1.3.
Comment 1 Anton Korobeynikov 2007-06-03 11:44:29 PDT
This is not a bug. lli cannot know, whether arguments are swapped, dropped, etc.
It supports all 3 types of main():

- int main(void)
- int main(argc, argv)
- int main(argc, argv, envp)
Comment 2 Maarten ter Huurne 2007-06-03 11:52:28 PDT
Of course the program is wrong, but I think lli should report that with an 
error message instead of an assert. If I had compiled the LLVM tools with 
asserts off (-DNDEBUG), something undefined could have happened.
Comment 3 Chris Lattner 2007-06-03 13:17:47 PDT
I agree with Maarten.  lli should check that the types are right and refuse to run the program if not.
Comment 4 Anton Korobeynikov 2007-06-03 13:25:19 PDT
Mine