Closed llvmbot closed 1 year ago
It really doesn't like my function
/**
static u16_t new_query_id(u8_t i) {
u8_t j,k; for(j = 0; j<DNS_MAX_RAND_ATTEMPT; j++) { bool clash; u16_t r; r = LWIP_RAND(); clash = false; for (k = 0; k < DNS_TABLE_SIZE; ++k) { if( (k != i) && (dns_table[k].state != DNS_STATE_UNUSED) && (dns_table[k].queryID == r) ) { clash = true; break; } } / we found an unused ID / if(!clash) return r; }
LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("Too many clashin random IDs\n", ));
/ could not find a unique random number / / either bad luck, or broken rand function / / use sequence number instead / return dns_table[i].seqno;
/ If not using random numbers, the / / sequence number is better than nothing / return dns_table[i].seqno;
}
Once I put the inner loop in it crashes. It seems to be a non local crash as the message says its working on a function elsewhere at the time.
I got this to compile by breaking out the inner loop into its own function, and then calling that via a global or volatile function pointer. That was the only way I could find to break the death grip your optimiser had on the inner loop.
/**
static bool check_rand(u16_t r, int i) { u8_t j; for (j = 0; j < DNS_TABLE_SIZE; ++j) { if( (j != i) && (dns_table[j].state != DNS_STATE_UNUSED) && (dns_table[j].queryID == r) ) { return false; } } / no clashes, its good / return true; }
/*
*/
/**
typedef bool (*check_fn)(u16_t r, int i); static volatile check_fn rand_check = check_rand;
static u16_t new_query_id(int i) {
u8_t j;
for(j = 0; j<DNS_MAX_RAND_ATTEMPT; j++) { u16_t r; r = LWIP_RAND(); / This used to be a nested loop, but it crashed llvm / if((rand_check)(r, i)) { / we found an unused ID */ return r; } }
LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("Too many clashin random IDs\n", ));
/ could not find a unique random number / / either bad luck, or broken rand function / / use sequence number instead /
/ If not using random numbers, the / / sequence number is better than nothing / return dns_table[i].seqno; }
I've found the line which seems to cause the crash.
In the code below, adding the "pEntry->queryID = new_query_id(i);" line seems to do it. BTW, the code is from LWIP: http://savannah.nongnu.org/projects/lwip/
static void dns_check_entry(u8_t i) { err_t err; struct dns_table_entry *pEntry = &dns_table[i];
LWIP_ASSERT("array index out of bounds", i < DNS_TABLE_SIZE);
switch(pEntry->state) {
case DNS_STATE_NEW: {
/* initialize new entry */
pEntry->state = DNS_STATE_ASKING;
pEntry->numdns = 0;
pEntry->tmr = 1;
pEntry->retries = 0;
//pEntry->queryID = new_query_id(i);
/* send DNS packet for this entry */
err = dns_send(pEntry->numdns, pEntry->name, pEntry->queryID);
if (err != ERR_OK) {
LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING,
("dns_send returned error: %s\n", lwip_strerr(err)));
}
break;
}
Can't reproduce using Clang 3.2 through 3.4 with assertions enabled.
It should be noted that those versions don't recognize -arm-dont-use-movt
and -lowregs-stack-align
. Given that you're using Apple Clang, this might be a downstream issue.
Extended Description
Clang just crashed on me, it asked me to file this bug, so I am.
This is the command line output:
Compiling (clang apple/llvm-armv7m/3.3) "lwip/src/core/dns.c" Unknown addressing mode for CP reference! UNREACHABLE executed at /home/elvin/GIT/embedded-tools/llvm-clang-3.3/llvm-source/lib/Target/ARM/ARMConstantIslandPass.cpp:734! 0 armv7m-none-eabi-clang 0x09dca2ef llvm::sys::PrintStackTrace(_IO_FILE) + 47 1 armv7m-none-eabi-clang 0x09dca54f 2 armv7m-none-eabi-clang 0x09dc9714 3 0x40022400 __kernel_sigreturn + 0 4 0x40022424 __kernel_vsyscall + 16 5 libc.so.6 0x401b51df gsignal + 79 6 libc.so.6 0x401b8825 abort + 373 7 armv7m-none-eabi-clang 0x09daf9fc 8 armv7m-none-eabi-clang 0x093b6480 9 armv7m-none-eabi-clang 0x0969519a llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 186 10 armv7m-none-eabi-clang 0x09cd124c llvm::FPPassManager::runOnFunction(llvm::Function&) + 636 11 armv7m-none-eabi-clang 0x09cd12b8 llvm::FPPassManager::runOnModule(llvm::Module&) + 56 12 armv7m-none-eabi-clang 0x09cd0d24 llvm::MPPassManager::runOnModule(llvm::Module&) + 692 13 armv7m-none-eabi-clang 0x09cd0f0c llvm::PassManagerImpl::run(llvm::Module&) + 236 14 armv7m-none-eabi-clang 0x09cd0fc6 llvm::PassManager::run(llvm::Module&) + 38 15 armv7m-none-eabi-clang 0x08507313 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::Module, clang::BackendAction, llvm::raw_ostream) + 3747 16 armv7m-none-eabi-clang 0x08504a99 17 armv7m-none-eabi-clang 0x086c833a clang::ParseAST(clang::Sema&, bool, bool) + 410 18 armv7m-none-eabi-clang 0x0835e3bf clang::ASTFrontendAction::ExecuteAction() + 111 19 armv7m-none-eabi-clang 0x08502c12 clang::CodeGenAction::ExecuteAction() + 50 20 armv7m-none-eabi-clang 0x0835edd8 clang::FrontendAction::Execute() + 248 21 armv7m-none-eabi-clang 0x0834041d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 301 22 armv7m-none-eabi-clang 0x08325898 clang::ExecuteCompilerInvocation(clang::CompilerInstance) + 1608 23 armv7m-none-eabi-clang 0x0831de30 cc1_main(char const, char const, char const, void) + 1008 24 armv7m-none-eabi-clang 0x08307eb9 main + 809 25 libc.so.6 0x401a04d3 __libc_start_main + 243 26 armv7m-none-eabi-clang 0x0831d8b1 Stack dump:
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: armv7m-none-eabi-clang: note: diagnostic msg: /tmp/dns-UoFhjM.c armv7m-none-eabi-clang: note: diagnostic msg: /tmp/dns-UoFhjM.sh armv7m-none-eabi-clang: note: diagnostic msg: