LLVM IO Error - Error writing to a bc file - c++

Error occurs when I try to delete raw_ostream
void LLVMGenerator::SaveModule(string path) {
std::string ErrInfo = "";
llvm::raw_ostream *out =
new llvm::raw_fd_ostream(path.c_str(), ErrInfo, llvm::sys::fs::F_None);
llvm::WriteBitcodeToFile(_mod, *out);
out->flush();
delete out; // LLVM ERROR: IO failure on output stream.
return;
}
OS Ubuntu 13.10 x64, LLVM 3.4

Some IO error occurred on the raw_fd_ostream object - perhaps the underlying writev call encountered a non-recoverable error. raw_fd_ostream's behavior in this case is to turn on a flag indicating an error has occurred, and if that flag is still on during destruction, it reports a fatal error (=crashes).
If you want to avoid this crash, you can call clear_error() on the object before you destruct it; though it's of course recommended that you first check whether an error occurred yourself, via has_error(), and try to handle it.

Related

How to detect USRP usb type?

When i include uhd/usb_control.hpp in my main.cpp :
#include <uhd/transport/usb_control.hpp>
/* Some other includes */
int main (void)
{
uhd::transport::usb_control::sptr usbSpeed;
usbSpeed = uhd::transport::usb_control::make(handle, 0);
/* `handle` is a `usb_device_handle::vid_pid_pair_t` */
}
I got error from here:
static sptr make(usb_device_handle::sptr handle, const int interface);
Error:
unexpected token struct. Did you forget a ';'
struct: missing tag name
And another strange error in:
usbSpeed = uhd::transport::usb_control::make(handle, 0);
Error:
Cannot convert argument 2 from int to const int
The only implementation that i find for uhd::transport::usb_control::make is uhd/transport/usb_dummy_impl.cpp which only throw an exception.
Environment information:
Compiler: MS Visual Studio 2017
OS: MS Windows 10
C++ Standard: 17
How to fix those errors ? I only what to detect the USRP usb type. For this i read the uhd source code and i find the uhd/transport/usb_control.hpp, But I have encountered those errors.
maybe the cause of this unexpected behavior is related to your included files and a conflict between some of them, as you mentioned in addition of #include <uhd/transport/usb_control.hpp> you have some other includes. i suggest move this include line upper and lower of other includes and test your code again.
wish my suggest be useful.

Possible Visual Studio 2015 C++ Compiler and IntelliSense Bugs

I encountered a compiler crash and intellisense false positives with Visual Studio 2015 using C++.
This crashes the compiler when written within a function block:
if();
This is the dialog that is shown when compiling (I am on a German version of Windows):
Even though the compiler crashes, I get error list output:
Error C2059 syntax error: ')'
Warning C4390 ';': empty controlled
statement found; is this the intent?
Error C1903 unable to recover from previous error(s); stopping compilation
This produces squiggles and error annotations in the vertical scrollbar in map mode, but no actual intellisense errors:
#include <vector>
struct S { std::vector<S> Children; };
int main(int argc, char* argv[]) {
S item;
item.Children.push_back(S());
// ^
// Error: no instance of overloaded function
// "std::vector<_Ty, _Alloc>::push_back [with _Ty=S, _Alloc=std::allocator<S>]"
// matches the argument list
// argument types are: (S)
// object type is: std::vector<S, std::allocator<S>>
S& back = item.Children.back();
// ^^^^
// Error: a reference of type "S &" (not const-qualified) cannot be
// initialized with a value of type "S"
return 0;
}
Are those bugs? Are they known? Can you reproduce them?
For the first case: the compiler shouldn't crash but just issue the diagnostic you show. So yes, that's a bug. Which doesn't occur in VS2013 btw. Submit a report for it here
For the second case: it is the same in VS2013 and is due to nesting a vector of S inside S. This and other cases make the error squiggles appear incorrectly, it is actually not that uncommon. But ideally it should not happen so you can submit a bug report for it as well, though it might be something which is going to be labelled 'wontfix' as the compiler team usually focusses on more urgent cases.

copying function pointer throws error in one function pointer

I have cjson code (https://github.com/kbranigan/cJSON/blob/master/ ) , it compiles well when I compile on the linux pc .
but when I compile for some embedded platform it throws error at
if (!hooks) { /* Reset hooks */
cJSON_malloc = mem_alloc; // its equal to gcc malloc for the embedded compiler
cJSON_free = mem_free; // its equal to gcc free
}
The error is Undefined reference to mem_alloc , and mem_free
but if I call the function like below
char* data = (char*) mem_alloc(32);
it compiles well ..
compiler is xtensa compiler(xt-xcc)
isn't it right way to assign ?

MinGW-w64 pthread_cleanup_pop() error

when compiling a C++ program which contains a "call" to the pthread_cleanup_pop(E) macro, the following error is thrown by g++:
error: second operand to the conditional operator is of type 'void', but the third operand is neither a throw-expression nor of type 'void'
Now, the apparent problem here is that the macro above expands to
(*pthread_getclean() = _pthread_cup.next, (E?_pthread_cup.func((pthread_once_t *)_pthread_cup.arg):0));} where the second expression is a call to a function returning void, but the third expression is simply 0.
Althoug I get the basic issue here, I really don't see why the warning occurs in this particular use, as the "result" of the condition is not assigned to anything.
For the record: I compiled the C++ program using MinGW-w64 3.3.0 (GCC 4.9.2) both with and without -std=c++98. In both cases, the error occurs. If I compile the same code as a C program (both with or without -std=c99), there is no error.
Does anyone know how I could get rid of that error in C++, other than by editing pthread.h?
Many thanks in advance!
EDIT: Here is some example code for reference:
#include <pthread.h>
static int cancelled = 0;
static void test_thread_cleanup(void *_arg){
cancelled = 1;
}
static void* test_thread(void *_arg){
pthread_cleanup_push(&test_thread_cleanup, NULL); // push cleanup handler on stack
while (1){ // never left unless cancelled via pthread_cancel() from main()
pthread_testcancel(); // just test for pthread_cancel() having been called
}
pthread_cleanup_pop(1); // pop cleanup handler from stack
return NULL; // actually never reached
}
int main(void){
pthread_t th;
pthread_create(&th, NULL, &test_thread, NULL);
pthread_cancel(th);
pthread_join(th, NULL);
return cancelled;
}

What does it mean "internal compiler error: storage failure" on UNIX?

I have to build an application on UNIX, Unixware 2.1.3, with a CCS compiler 3.0 and I keep having this error :
UX:acomp: ERROR: "//home/dino/treeit.h", line 32: internal compiler error: storage failure
*** Error code 1 (bu21)
UX:make: ERROR: fatal error.
I've look at the space available on my system and it's fine.
Here's the code section, in c++, from line 23 to 36 :
public:
bool operator != (iterator_impl const &p_iterator) const
{
return m_pNode != p_iterator.m_pNode;
}
__BTL_ITERATOR_IMPL_NAME()
:m_pNode(0)
{} //Line 32 is here!!!!!!!
__BTL_ITERATOR_IMPL_NAME(iterator_impl const &p_iterator)
:m_pNode(p_iterator.m_pNode)
{}
I'm not that good on UNIX and don't know if it's a operating system related problem. Can someone help me ? :)
Thanks!
Appears to mean you're out of disk space during the compilation:
http://www.linuxmisc.com/4-linux/7e5b068dd5eedb04.htm