[llvm-dev] __restirct ignored when including headers like <cmath>
Johannes Doerfert via llvm-dev
llvm-dev at lists.llvm.org
Mon Jun 29 15:56:00 PDT 2020
From wikipedia (https://en.wikipedia.org/wiki/Restrict)
C++ <https://en.wikipedia.org/wiki/C%2B%2B> does not have standard
support for |restrict|, but many compilers have equivalents that usually
work in both C++ and C, such as the GCC
<https://en.wikipedia.org/wiki/GNU_Compiler_Collection>'s and Clang
<https://en.wikipedia.org/wiki/Clang>'s |__restrict__|, and Visual C++
<https://en.wikipedia.org/wiki/Visual_C%2B%2B>'s |__declspec(restrict)|.
In addition, |__restrict| is supported by those three compilers. The
exact interpretation of these alternative keywords vary by the compiler:
Hope this helps,
~ Johannes
On 6/29/20 11:51 AM, Bandhav Veluri via llvm-dev wrote:
> Hi,
>
> Later found out this is because some Newlib headers defined __restrict as
> empty. __restrict__ seems to work...
>
> What's the supposed difference between __restrict and __restrict__?
>
> Thanks,
> Bandhav
>
> On Sun, Jun 28, 2020 at 1:18 AM Bandhav Veluri <bandhav.veluri00 at gmail.com>
> wrote:
>
>> Hi,
>>
>> I am observing a strange behaviour in which Clang ignores __restirct when
>> I include some standard headers.
>>
>> For example, this code:
>> void vec_add(int* __restrict a,
>> int* __restrict b,
>> int n) {
>> #pragma unroll 4
>> for(int i=0; i<n; ++i) {
>> a[i] += b[i];
>> }
>> }
>>
>> results in:
>> ; Function Attrs: nofree norecurse nounwind
>> define dso_local void @_Z7vec_addPiS_i(i32* noalias nocapture %a, i32*
>> noalias nocapture readonly %b, i32 %n) local_unnam
>> ed_addr #0 {
>> entry:
>> .
>> .
>> ...
>> (note the noaliass before function arguments).
>>
>> But this code:
>> #include <cmath>
>>
>> void vec_add(int* __restrict a,
>> int* __restrict b,
>> int n) {
>> #pragma unroll 4
>> for(int i=0; i<n; ++i) {
>> a[i] += b[i];
>> }
>> }
>>
>> results in:
>> ; Function Attrs: nofree norecurse nounwind
>> define dso_local void @_Z7vec_addPiS_i(i32* nocapture %a, i32* nocapture
>> readonly %b, i32 %n) local_unnamed_addr #0 {
>> entry:
>> %cmp6 = icmp sgt i32 %n, 0
>> br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup
>> .
>> .
>> ...
>>
>> I'm running this with LLVM RISC-V backend using RISC-V GCC compiled Newlib
>> as the C/C++ library.
>>
>> Is it not okay to use GCC libraries with LLVM? Or could this be a specific
>> issue with Newlib's header files misinterpreted by Clang?
>>
>> Thank you,
>> Bandhav
>>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200629/ee04cfe6/attachment.html>
More information about the llvm-dev
mailing list