[llvm-dev] returns_twice (original) (raw)

[llvm-dev] returns_twice / noreturn

Hal Finkel via llvm-dev llvm-dev at lists.llvm.org
Fri Nov 3 17:39:06 PDT 2017


On 11/03/2017 07:20 PM, Alexandre Isoard via llvm-dev wrote:

Hello,

I am not sure about the semantic (if any) of returnstwice and noreturn attributes. int fork() attribute((returnstwice)); 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) localunnamedaddr #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: returnstwice declare i32 @fork(...) localunnamedaddr #1 ; Function Attrs: noreturn declare void @join(i32) localunnamedaddr #2 Where the n++ has been moved after the if, is that legal?

Why wouldn't it be?

Also, technically, f could also returnstwice 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?

They have semantics. returns_twice, however, really means, "it may return more than once". noreturn is interpreted as the name implies. Thus the unreachable after the call.

-Hal

-- Alexandre Isoard


LLVM Developers mailing list llvm-dev at lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

-- Hal Finkel Lead, Compiler Technology and Programming Languages Leadership Computing Facility Argonne National Laboratory

-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171103/8627aaa1/attachment-0001.html>



More information about the llvm-dev mailing list