casting using llvm::dyn_cast cause in failed assertion - llvm

ERROR MESSAGE :
llvm/include/llvm/Support/Casting.h:240: typename llvm::cast_retty::ret_type llvm::cast(Y*) [with X = llvm::PointerType, Y = llvm::Type, typename llvm::cast_retty::ret_type = llvm::PointerType*]: Assertion `isa(Val) && "cast() argument of incompatible type!"' failed.
CODE :
Value *op1 = x->getOperand(0);
bool flag1;
if(ConstantInt *CI = dyn_cast<ConstantInt>(op)){
flag1=CI->isOne();
}
I searched on google and found that this was a bug but fixed. I recently downloaded the source and compiled it. Is there anyway I can fix this?

This problem is solved after using llvm 3.4 stable release. I was using latest code earlier.

Related

Compile error in boost header file. Fails on Centos 7, compiles on Ubuntu 16.04

I am running into a strange compilation issue. Any help in resolving it would be greatly appreciated. I am linking my application against the boost libraries. I need to compile my app on both Centos and Ubuntu. Everything works fine on Ubuntu and the same code fails to compile on Centos 7. The location of the error is in boost. Not sure if the issue is actually in boost or if something else is causing the error to be show up in boost. I've come across this link when I searched the error. However, that issue was for an older version of boost. I've listed error output below:
/usr/local/include/boost/chrono/duration.hpp: In function 'constexpr typename boost::enable_if<boost::mpl::and_<boost::is_convertible<Rep1, typename boost::common_type<Rep1, Rep2>::type>, boost::is_convertible<Rep2, typename boost::common_type<Rep1, Rep2>::type> >, boost::chrono::duration<typename boost::common_type<Rep1, Rep2>::type, Period> >::type boost::chrono::operator*(const boost::chrono::duration<Rep, Period>&, const Rep2&)':
In file included from /usr/local/include/boost/chrono/time_point.hpp:33:0,
from /usr/local/include/boost/thread/lock_types.hpp:22,
from /usr/local/include/boost/thread/lock_algorithms.hpp:11,
from /usr/local/include/boost/thread/locks.hpp:10,
...
/usr/local/include/boost/chrono/duration.hpp:575:34: error: type/value mismatch at argument 1 in template parameter list for 'template<class Rep, class Period> class boost::chrono::duration'
typedef duration<CR, Period> CD;
^
/usr/local/include/boost/chrono/duration.hpp:575:34: error: expected a type, got '13u'
/usr/local/include/boost/chrono/duration.hpp:575:38: error: invalid type in declaration before ';' token
typedef duration<CR, Period> CD;
Corresponding code from /usr/local/include/boost/chrono/duration.hpp:
// Duration *
template <class Rep1, class Period, class Rep2>
inline BOOST_CONSTEXPR
typename boost::enable_if <
mpl::and_ <
boost::is_convertible<Rep1, typename common_type<Rep1, Rep2>::type>,
boost::is_convertible<Rep2, typename common_type<Rep1, Rep2>::type>
>,
duration<typename common_type<Rep1, Rep2>::type, Period>
>::type
operator*(const duration<Rep1, Period>& d, const Rep2& s)
{
typedef typename common_type<Rep1, Rep2>::type CR;
typedef duration<CR, Period> CD;
return CD(CD(d).count()*static_cast<CR>(s));
}
I get this error on Centos7. Does not happen on Ubuntu.
Centos Version:
Boost: 1.58.0, OS: Centos 7, C++: g++ 4.8.5
Ubuntu Versions:
Boost: 1.58.0, OS: Ubuntu 16.04, C++: g++ 5.4.0
Not sure if the C++ compiler difference is the issue. The default version of c++ compiler on Centos7 is 4.8.5. BTW, the default boost version on CentOS7 is 1.53.2. I compiled and installed boost 1.58.0 version to minimize the variables. Any help is greatly appreciated. Thanks.
My guess (and that's all it is, a guess) based on the error message is that somewhere you've got:
#define CR 13u
and that's causing the compilation error.

compile error for boost::date_time::days_until_weekday

I'm currently toying around with boost::date_time. While doing so, I came upon the days_until_weekday (documentation link) function which appears highly useful to me. Unfortunately, I get a compile time error from the following snippet
date f(date d){
return next_weekday(d, boost::date_time::weekdays::Friday);
}
reading
> In file included from
> /usr/include/boost/date_time/gregorian/gregorian_types.hpp:25:0,
> from /usr/include/boost/date_time/posix_time/posix_time_config.hpp:18,
> from /usr/include/boost/date_time/posix_time/posix_time_system.hpp:13,
> from /usr/include/boost/date_time/posix_time/ptime.hpp:12,
> from /usr/include/boost/date_time/posix_time/posix_time.hpp:15,
> from prog.cpp:3: /usr/include/boost/date_time/date_generators.hpp: In instantiation of
> 'typename date_type::duration_type
> boost::date_time::days_until_weekday(const date_type&, const
> weekday_type&) [with date_type = boost::gregorian::date; weekday_type
> = boost::date_time::weekdays; typename date_type::duration_type = boost::gregorian::date_duration]':
> /usr/include/boost/date_time/date_generators.hpp:488:34: required
> from 'date_type boost::date_time::next_weekday(const date_type&, const
> weekday_type&) [with date_type = boost::gregorian::date; weekday_type
> = boost::date_time::weekdays]' prog.cpp:11:67: required from here /usr/include/boost/date_time/date_generators.hpp:452:37: error:
> request for member 'as_number' in 'wd', which is of non-class type
> 'const boost::date_time::weekdays'
> duration_type dd(wd.as_number() - d.day_of_week().as_number());
Go here for a paste of my code.
As the snippet causing the error is so short, I'm really out of ideas to fix this.
By the way, I'm on boost 1.60.0 using clang 3.7.0.
You need to convert the date_time enum to an object that matches the interface expected by the weekday_type passed to the function. Use the greg_weekday function to do this for you, eg:
return next_weekday(d, boost::gregorian::greg_weekday(boost::date_time::Friday));
That compiles for me under VS2015 and boost 1.53.
A link to the documentation for this function:
greg_weekday

Is set_value_at_thread_exit() supported on gcc?

This is my first post here so please be lenient :)
I am having a problem with set_value_at_thread_exit() method from promise class (part of c++11). Everything was ok in VS2013 but GCC gives me following error message:
error: ‘class std::promise<int>’ has no member named ‘set_value_at_thread_exit’
args->result.set_value_at_thread_exit(result);
I've tried GCC 4.8 and 4.9 on Ubuntu 14.04
The code is:
[...]
int result = 0;
Socket socket;
result = CreateUDPSocket(&socket, false, ANY_IP, args->port);
if (result != ERROR_SUCCESS)
{
args->result.set_value_at_thread_exit(result);
return;
}
args->result.set_value(ERROR_SUCCESS);
[...]
Unfortunately, it isn't supported yet. If you look at the status page
30.6.5 | Class template promise | Partial | Missing set_*_at_thread_exit

OpenCV 2.4.2 Compile Issues in "operations.hpp"

I am trying to install openCV 2.4.2 on Windows x64 and Netbeans. I have followed the following guide: http://projectsfromhellandmore.blogspot.co.nz/2012/06/opencv-241-netbeans-windows-7-plus.html
When I try to compile the sample code included in the guide I get the following errors for the following blocks of code in the file "include/opencv2/core/operations.hpp" and I have not found any fixes or figured out how to fix it myself:
template<typename _Tp, typename _Base> inline void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
Ptr<_Tp>& value, bool readOnly, Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&),
const string& help)
{
//TODO: static assert: _Tp inherits from _Base
addParam_(algo, parameter, ParamType<_Base>::type, &value, readOnly,
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
}
error: got 2 template parameters but 1 required
And the second block of code with an error is:
template<typename _Tp> inline void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter,
Ptr<_Tp>& value, bool readOnly, Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&),
const string& help)
{
//TODO: static assert: _Tp inherits from Algorithm
addParam_(algo, parameter, ParamType<Algorithm>::type, &value, readOnly,
(Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
}
error: redefinition of ...(the function in the first block of code)
Any help would be greatly appreciated thanks
I faced the same problem with MinGW with opencv2.4.x and later on found out that there was nothing wrong with the operations.hpp file. Instead, the MinGW compiler that i had installed was at fault. I reinstalled the compiler from sourcefourge and it worked. Check your netbeans compiler.
I faced the same problem. the solution to this problem is just comment out the entire template inline function. this function is declared twice just below one another thats why the issue. just comment out one of them.

OpenCV - Error C2244

I'm currently on vacation far away from my desktop, however I wanted to practice my c++ in particular with openCV, so I brought my laptop along. Given time and family constraints I didn't get everything set up in time with the libraries before flying.
I've set everything up with regards to VS 2010 as I recall doing on my desktop a while ago, but on compiling the test example on the openCV website (http://opencv.willowgarage.com/wiki/VisualC%2B%2B) I receive the following errors:
Error 3 error C2244: 'cv::Matx<_Tp,,>::diag' : unable to match function definition to an existing declaration C:\Program Files\OpenCV2.2\include\opencv2\core\operations.hpp 372
Error 4 error C2244: 'cv::Matx<_Tp,,>::diag' : unable to match function definition to an existing declaration C:\Program Files\OpenCV2.2\include\opencv2\core\operations.hpp 448
which in turn shows me:
template<typename _Tp, int m, int n> inline
Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const Matx<_Tp,MIN(m,n),1>& d)
{
Matx<_Tp,m,n> M;
for(int i = 0; i < MIN(m,n); i++)
M(i,i) = d[i];
return M;
}
template<typename _Tp, int m, int n> inline
Matx<_Tp, MIN(m,n), 1> Matx<_Tp, m, n>::diag() const
{
diag_type d;
for( int i = 0; i < MIN(m, n); i++ )
d.val[i] = val[i*n + i];
return d;
}
I've looked into this error on the msdn and have looked on the openCV forums, but I couldn't find record of this specific error and I'm not sure how to resolve it.
Is it also problematic that I'm running the 64 bit version of Windows 7? I read that openCV2.2 is compatible however previously while the programs would compile, it kept on saying the .dll files were missing even though the PATH variable and directories were correct.
Thanks,
Jean-Pierre
I had the same issue running Opencv2.2 on 32bit Win7 VS2010 and QT 4.7.2.
I doesn't seem to be an error that affects the actual function of code. When I turned code analysis off as Himanshu jain described above it fixed the problem.
It seems indeed that the option advanced compiler option "/analyze" causes this problem (I'm using OpenCV 2.2 with VS 2008 on Win XP 32bit). I could fix the first error:
In line 365, you got to replace Matx<_Tp,MIN(m,n),1> with diag_type, i.e. this
template<typename _Tp, int m, int n> inline
Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const Matx<_Tp,MIN(m,n),1>& d)
becomes
template<typename _Tp, int m, int n> inline
Matx<_Tp,m,n> Matx<_Tp,m,n>::diag(const diag_type& d)
Unfortunately, the 2nd error still occurs -- I found no way to get rid of it but to deactivate \analyze :-(
1>D:\OpenCV2.2\include\opencv2/core/operations.hpp(447) : error C2244: 'cv::Matx<_Tp,,>::diag':
unable to match function definition to an existing declaration
If you find a way to fix this, please let me know -- I think I'll go ahead and post a bug-report-ticket on OpenCV Trac now...