diff options
author | Volodymyr Sapsai <vsapsai@apple.com> | 2019-03-01 02:15:39 +0000 |
---|---|---|
committer | Volodymyr Sapsai <vsapsai@apple.com> | 2019-03-01 02:15:39 +0000 |
commit | 23c3c07e7662da02b916241b1656d667bea63891 (patch) | |
tree | 190660de4653d215e5d571fc74957f4c3c86b92d /test/CodeGen | |
parent | 358a36e5760dd3c6d235099a29b7be6203c7fe99 (diff) | |
download | clang-23c3c07e7662da02b916241b1656d667bea63891.tar.gz |
[CodeGen] Fix calling llvm.var.annotation outside of a basic block.
When we have an annotated local variable after a function returns, we
generate IR that fails verification with the error
> Instruction referencing instruction not embedded in a basic block!
And it means that bitcast referencing alloca doesn't have a parent basic
block.
Fix by checking if we are at an unreachable point and skip emitting
annotations. This approach is similar to the way we emit variable
initializer and debug info.
rdar://problem/46200420
Reviewers: rjmccall
Reviewed By: rjmccall
Subscribers: aprantl, jkorous, dexonsmith, cfe-commits
Differential Revision: https://reviews.llvm.org/D58147
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355166 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen')
-rw-r--r-- | test/CodeGen/annotations-builtin.c | 3 | ||||
-rw-r--r-- | test/CodeGen/annotations-var.c | 11 |
2 files changed, 13 insertions, 1 deletions
diff --git a/test/CodeGen/annotations-builtin.c b/test/CodeGen/annotations-builtin.c index 8a3b3ffcec..e6dd3587af 100644 --- a/test/CodeGen/annotations-builtin.c +++ b/test/CodeGen/annotations-builtin.c @@ -43,4 +43,7 @@ int main(int argc, char **argv) { // CHECK: call i32 @llvm.annotation.i32 // CHECK: inttoptr {{.*}} to i8** return 0; + + int after_return = __builtin_annotation(argc, "annotation_a"); +// CHECK-NOT: call i32 @llvm.annotation.i32 } diff --git a/test/CodeGen/annotations-var.c b/test/CodeGen/annotations-var.c index 6e8ad34c65..3dc6dca3e7 100644 --- a/test/CodeGen/annotations-var.c +++ b/test/CodeGen/annotations-var.c @@ -39,10 +39,19 @@ void local(void) { // LOCAL-NEXT: call void @llvm.var.annotation(i8* [[T0]], i8* getelementptr inbounds ([15 x i8], [15 x i8]* @{{.*}}), i8* getelementptr inbounds ({{.*}}), i32 33) } +void local_after_return(void) { + return; + int localvar __attribute__((annotate("localvar_after_return"))) = 3; +// Test we are not emitting instructions like bitcast or call outside of a basic block. +// LOCAL-LABEL: define void @local_after_return() +// LOCAL: [[LOCALVAR:%.*]] = alloca i32, +// LOCAL-NEXT: ret void +} + void undef(void) { int undefvar __attribute__((annotate("undefvar_ann_0"))); // UNDEF-LABEL: define void @undef() // UNDEF: [[UNDEFVAR:%.*]] = alloca i32, // UNDEF-NEXT: [[T0:%.*]] = bitcast i32* [[UNDEFVAR]] to i8* -// UNDEF-NEXT: call void @llvm.var.annotation(i8* [[T0]], i8* getelementptr inbounds ([15 x i8], [15 x i8]* @{{.*}}), i8* getelementptr inbounds ({{.*}}), i32 43) +// UNDEF-NEXT: call void @llvm.var.annotation(i8* [[T0]], i8* getelementptr inbounds ([15 x i8], [15 x i8]* @{{.*}}), i8* getelementptr inbounds ({{.*}}), i32 52) } |