Skip to content

Instantly share code, notes, and snippets.

@EricWF
Created July 12, 2018 22:38
Show Gist options
  • Save EricWF/08637233b27476495580e47587ef809a to your computer and use it in GitHub Desktop.
Save EricWF/08637233b27476495580e47587ef809a to your computer and use it in GitHub Desktop.
// RUN: %clang_cc1 -triple x86_64-apple-darwin10.0.0 -fresumable-functions -emit-llvm -o - %s -fexceptions -std=c++17 | FileCheck %s
resumable int foo() {
return 42;
}
void bar() {
resumable auto r = foo();
bool b = r.ready();
int x = r.result();
}
struct NonTrivial {
NonTrivial();
NonTrivial(NonTrivial const &);
~NonTrivial();
};
resumable NonTrivial test_dtor() {
return NonTrivial{};
}
void test() {
resumable auto r = test_dtor();
}
; ModuleID = '/home/eric/workspace/clang/test/CodeGenCXX/resumable-expressions.cpp'
source_filename = "/home/eric/workspace/clang/test/CodeGenCXX/resumable-expressions.cpp"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin10.0.0"
%class.anon = type { [1024 x i8], [32 x i8], i8, [31 x i8] }
%class.anon.0 = type { [1024 x i8], [8 x i8], i8, [7 x i8] }
%struct.NonTrivial = type { i8 }
; Function Attrs: noinline nounwind optnone
define void @_Z3barv() #0 {
entry:
%r = alloca %class.anon, align 32
%b = alloca i8, align 1
%x = alloca i32, align 4
%0 = bitcast %class.anon* %r to i8*
call void @llvm.memset.p0i8.i64(i8* align 32 %0, i8 0, i64 1088, i1 false)
%__data_ = getelementptr inbounds %class.anon, %class.anon* %r, i32 0, i32 0
%1 = bitcast [1024 x i8]* %__data_ to i32*
%call = call i32 @_Z3foov()
store i32 %call, i32* %1, align 32
%__ready_ = getelementptr inbounds %class.anon, %class.anon* %r, i32 0, i32 2
store i8 1, i8* %__ready_, align 32
%call1 = call zeroext i1 @"_ZZ3barvENK3$_05readyEv"(%class.anon* %r) #4
%frombool = zext i1 %call1 to i8
store i8 %frombool, i8* %b, align 1
%call2 = call i32 @"_ZZ3barvEN3$_06resultEv"(%class.anon* %r)
store i32 %call2, i32* %x, align 4
ret void
}
; Function Attrs: argmemonly nounwind
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1) #1
; Function Attrs: noinline nounwind optnone
define linkonce_odr i32 @_Z3foov() #0 {
entry:
ret i32 42
}
; Function Attrs: noinline nounwind optnone
define internal zeroext i1 @"_ZZ3barvENK3$_05readyEv"(%class.anon* %this) #0 align 2 {
entry:
%this.addr = alloca %class.anon*, align 8
store %class.anon* %this, %class.anon** %this.addr, align 8
%this1 = load %class.anon*, %class.anon** %this.addr, align 8
%__ready_ = getelementptr inbounds %class.anon, %class.anon* %this1, i32 0, i32 2
%0 = load i8, i8* %__ready_, align 32
%tobool = trunc i8 %0 to i1
ret i1 %tobool
}
; Function Attrs: noinline nounwind optnone
define internal i32 @"_ZZ3barvEN3$_06resultEv"(%class.anon* %this) #0 align 2 {
entry:
%retval = alloca i32, align 4
%this.addr = alloca %class.anon*, align 8
store %class.anon* %this, %class.anon** %this.addr, align 8
%this1 = load %class.anon*, %class.anon** %this.addr, align 8
%__result_ = getelementptr inbounds %class.anon, %class.anon* %this1, i32 0, i32 1
%0 = bitcast [32 x i8]* %__result_ to i32*
%1 = bitcast i32* %retval to i8*
%2 = bitcast i32* %0 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 32 %2, i64 4, i1 false)
%3 = load i32, i32* %retval, align 4
ret i32 %3
}
; Function Attrs: noinline nounwind optnone
define void @_Z4testv() #0 {
entry:
%r = alloca %class.anon.0, align 16
%0 = bitcast %class.anon.0* %r to i8*
call void @llvm.memset.p0i8.i64(i8* align 16 %0, i8 0, i64 1040, i1 false)
%__data_ = getelementptr inbounds %class.anon.0, %class.anon.0* %r, i32 0, i32 0
%1 = bitcast [1024 x i8]* %__data_ to %struct.NonTrivial*
call void @_Z9test_dtorv(%struct.NonTrivial* sret %1)
%__ready_ = getelementptr inbounds %class.anon.0, %class.anon.0* %r, i32 0, i32 2
store i8 1, i8* %__ready_, align 8
call void @"_ZZ4testvEN3$_1D1Ev"(%class.anon.0* %r) #4
ret void
}
; Function Attrs: noinline nounwind optnone
define linkonce_odr void @_Z9test_dtorv(%struct.NonTrivial* noalias sret %agg.result) #0 {
entry:
call void @_ZN10NonTrivialC1Ev(%struct.NonTrivial* %agg.result)
ret void
}
; Function Attrs: noinline nounwind optnone
define internal void @"_ZZ4testvEN3$_1D1Ev"(%class.anon.0* %this) unnamed_addr #0 align 2 {
entry:
%this.addr = alloca %class.anon.0*, align 8
store %class.anon.0* %this, %class.anon.0** %this.addr, align 8
%this1 = load %class.anon.0*, %class.anon.0** %this.addr, align 8
call void @"_ZZ4testvEN3$_1D2Ev"(%class.anon.0* %this1) #4
ret void
}
; Function Attrs: argmemonly nounwind
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #1
declare void @_ZN10NonTrivialC1Ev(%struct.NonTrivial*) unnamed_addr #2
; Function Attrs: noinline nounwind optnone
define internal void @"_ZZ4testvEN3$_1D2Ev"(%class.anon.0* %this) unnamed_addr #0 align 2 {
entry:
%this.addr = alloca %class.anon.0*, align 8
store %class.anon.0* %this, %class.anon.0** %this.addr, align 8
%this1 = load %class.anon.0*, %class.anon.0** %this.addr, align 8
%__ready_ = getelementptr inbounds %class.anon.0, %class.anon.0* %this1, i32 0, i32 2
%0 = load i8, i8* %__ready_, align 8
%tobool = trunc i8 %0 to i1
br i1 %tobool, label %if.then, label %if.end
if.then: ; preds = %entry
%__result_ = getelementptr inbounds %class.anon.0, %class.anon.0* %this1, i32 0, i32 1
%1 = bitcast [8 x i8]* %__result_ to %struct.NonTrivial*
call void @_ZN10NonTrivialD1Ev(%struct.NonTrivial* %1) #4
br label %if.end
if.end: ; preds = %if.then, %entry
ret void
}
; Function Attrs: nounwind
declare void @_ZN10NonTrivialD1Ev(%struct.NonTrivial*) unnamed_addr #3
attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { argmemonly nounwind }
attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #3 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #4 = { nounwind }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 7.0.0 (trunk 334348) (https://git.llvm.org/git/llvm.git da8f6959d96395755c49e3ab327a94ab07bdaa83)"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment