[llvm-dev] __restirct ignored when including headers like <cmath>

Bandhav Veluri via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 29 09:51:49 PDT 2020


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200629/9809c9a6/attachment-0001.html>


More information about the llvm-dev mailing list