Lambda testcase fails when optimization enabled in gcc and llvm

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Lambda testcase fails when optimization enabled in gcc and llvm

Boost - Dev mailing list
Hi Devs,
consider below reduced testcase from boost lamda.

$cat result_of_tests.cpp

#include <boost/lambda/lambda.hpp>
#include <stdio.h>
template<class A, class F> typename boost::result_of<F(A)>::type apply1(F
f, A b) {
    return f(b);
}
using namespace boost::lambda;
int main(int, char *[]) {
    int one = 1;
    int d= (apply1<int>(_1 ,one) == 1);
    printf("\n%d\n",d);
    return 0;
}
when compiled with optimization O2
$g++ result_of_tests.cpp  -I ./boost_1_70_0 -O2
$./a.out
0

And,when we compile same testcase with O0
$g++ result_of_tests.cpp  -I ./boost_1_70_0 -O0
$./a.out
1

The above testcases is demonstrated with g++ compiler but behavior is same
on clang as well.
so we thought that this may be boost testcase issue.
When we replace ,
  int d= (apply1<int>(_1 ,one) == 1);
 with
  int d= (apply1<int&>(_1 ,one) == 1);

testcase gives correct result with or without optimization.

Wanted to confirm here,is it valid testcase or we have to modify testcase
as per above?

Thanks,
Navya

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Lambda testcase fails when optimization enabled in gcc and llvm

Boost - Dev mailing list

________________________________________
From: Boost [[hidden email]] on behalf of navya deepika garakapati via Boost [[hidden email]]
>Sent: 19 July 2019 10:49
>To: [hidden email]
>Cc: navya deepika garakapati
>Subject: [boost] Lambda testcase fails when optimization enabled in gcc and llvm

>Hi Devs,
>consider below reduced testcase from boost lamda.



>The above testcases is demonstrated with g++ compiler but behavior is same
>on clang as well.
>so we thought that this may be boost testcase issue.
>When we replace ,
> int d= (apply1<int>(_1 ,one) == 1);
> with
>  int d= (apply1<int&>(_1 ,one) == 1);

>testcase gives correct result with or without optimization.

>Wanted to confirm here,is it valid testcase or we have to modify testcase
>as per above?

>Thanks,
>Navya

Navya

It would be helpful to know what versions of g++ and clang you are using, and also what version of C++.

Boost lambda is old code which was written for C++03 so the example may run fine on older C++ compilers.

I hope this helps.

John


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Lambda testcase fails when optimization enabled in gcc and llvm

Boost - Dev mailing list
Hi John,
we tried with below compilers and version where it is failing
 g++ 8.1 and above. in clang++ 3.8.1 and 8.

while it is passing on g++ 5.4.

Thanks

On Fri, Jul 19, 2019 at 3:51 PM Fletcher, John P via Boost <
[hidden email]> wrote:

>
> ________________________________________
> From: Boost [[hidden email]] on behalf of navya deepika
> garakapati via Boost [[hidden email]]
> >Sent: 19 July 2019 10:49
> >To: [hidden email]
> >Cc: navya deepika garakapati
> >Subject: [boost] Lambda testcase fails when optimization enabled in gcc
> and llvm
>
> >Hi Devs,
> >consider below reduced testcase from boost lamda.
>
>
>
> >The above testcases is demonstrated with g++ compiler but behavior is same
> >on clang as well.
> >so we thought that this may be boost testcase issue.
> >When we replace ,
> > int d= (apply1<int>(_1 ,one) == 1);
> > with
> >  int d= (apply1<int&>(_1 ,one) == 1);
>
> >testcase gives correct result with or without optimization.
>
> >Wanted to confirm here,is it valid testcase or we have to modify testcase
> >as per above?
>
> >Thanks,
> >Navya
>
> Navya
>
> It would be helpful to know what versions of g++ and clang you are using,
> and also what version of C++.
>
> Boost lambda is old code which was written for C++03 so the example may
> run fine on older C++ compilers.
>
> I hope this helps.
>
> John
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Lambda testcase fails when optimization enabled in gcc and llvm

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list
navya deepika garakapati wrote:

> Hi Devs,
> consider below reduced testcase from boost lamda.
>
> $cat result_of_tests.cpp
>
> #include <boost/lambda/lambda.hpp>
> #include <stdio.h>
> template<class A, class F> typename boost::result_of<F(A)>::type apply1(F
> f, A b) {
>     return f(b);
> }
> using namespace boost::lambda;
> int main(int, char *[]) {
>     int one = 1;
>     int d= (apply1<int>(_1 ,one) == 1);
>     printf("\n%d\n",d);
>     return 0;
> }

f(b) returns a reference to b, which goes out of scope at the closing brace;
the example has undefined behavior. You should report this as an issue at
https://github.com/boostorg/lambda/issues.


_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Lambda testcase fails when optimization enabled in gcc and llvm

Boost - Dev mailing list
In reply to this post by Boost - Dev mailing list

________________________________
From: navya deepika garakapati [[hidden email]]
Sent: 19 July 2019 11:28
To: [hidden email]
Cc: Fletcher, John P
Subject: Re: [boost] Lambda testcase fails when optimization enabled in gcc and llvm

>Hi John,
>we tried with below compilers and version where it is failing
 >g++ 8.1 and above. in clang++ 3.8.1 and 8.

>while it is passing on g++ 5.4.

>Thanks


An observation

int d= (apply1<int>(_1 ,one) == 1);




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: Lambda testcase fails when optimization enabled in gcc and llvm

Boost - Dev mailing list
Sorry the last post was sent incomplete by mistake.

John
________________________________________
From: Boost [[hidden email]] on behalf of Fletcher, John P via Boost [[hidden email]]
Sent: 19 July 2019 23:49
To: navya deepika garakapati; [hidden email]
Cc: Fletcher, John P
Subject: Re: [boost] Lambda testcase fails when optimization enabled in gcc and llvm

________________________________
From: navya deepika garakapati [[hidden email]]
Sent: 19 July 2019 11:28
To: [hidden email]
Cc: Fletcher, John P
Subject: Re: [boost] Lambda testcase fails when optimization enabled in gcc and llvm

>Hi John,
>we tried with below compilers and version where it is failing
 >g++ 8.1 and above. in clang++ 3.8.1 and 8.

>while it is passing on g++ 5.4.

>Thanks


An observation:

When I replace

int d= (apply1<int>(_1 ,one) == 1);

with this

int d= (apply1<int>(_1 + 0 ,one) == 1);

it works even when optimized.

I have tried this with clang 4.0

John


_______________________________________________
Unsubscribe & other changes: https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.boost.org%2Fmailman%2Flistinfo.cgi%2Fboost&amp;data=02%7C01%7CJ.P.Fletcher%40aston.ac.uk%7C4065109385d74d061a8908d70c9b5e03%7Ca085950c4c2544d5945ab852fa44a221%7C0%7C0%7C636991733803734718&amp;sdata=nvOui0rHUFYq%2FDI5ie3PkS4ffSGR0UkuGB6AxqaZCYU%3D&amp;reserved=0

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost