[llvm-dev] returns_twice / noreturn

Alexandre Isoard via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 3 17:20:53 PDT 2017


Hello,

I am not sure about the semantic (if any) of returns_twice and noreturn
attributes.

int fork() __attribute__((returns_twice));
void join(int) __attribute__((noreturn));

int f(int n) {
  int t = fork();
  n++;
  if (t != 0)
    join(t);
  return n;
}

Produces the following LLVM IR:

; Function Attrs: nounwind uwtable
define i32 @f(i32 %n) local_unnamed_addr #0 {
entry:
  %call = call i32 (...) @fork() #3
  %cmp = icmp eq i32 %call, 0
  br i1 %cmp, label %if.end, label %if.then

if.then:                                          ; preds = %entry
  call void @join(i32 %call) #4
  unreachable

if.end:                                           ; preds = %entry
  %inc = add nsw i32 %n, 1
  ret i32 %inc
}

; Function Attrs: returns_twice
declare i32 @fork(...) local_unnamed_addr #1

; Function Attrs: noreturn
declare void @join(i32) local_unnamed_addr #2

Where the n++ has been moved after the if, is that legal?

Also, technically, f could also returns_twice or noreturn (depending on the
return values of fork).

So my question is: do they have semantic or they are only "clues" for
heuristic purposes?

-- 
*Alexandre Isoard*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171103/e51d029f/attachment.html>


More information about the llvm-dev mailing list