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

Bandhav Veluri via llvm-dev llvm-dev at lists.llvm.org
Sun Jun 28 01:18:00 PDT 2020


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/20200628/1471034e/attachment-0001.html>


More information about the llvm-dev mailing list