summaryrefslogtreecommitdiff
path: root/test/CodeGen/sanitize-atomic-int-overflow.c
diff options
context:
space:
mode:
authorErik Pilkington <erik.pilkington@gmail.com>2019-02-28 00:47:55 +0000
committerErik Pilkington <erik.pilkington@gmail.com>2019-02-28 00:47:55 +0000
commitebcdeef2f3efd820a57f0f0f9857a7cb2362b496 (patch)
tree5a197835e397c897e0b05c0c2d6379b0f7e3856c /test/CodeGen/sanitize-atomic-int-overflow.c
parent54cb5304bd89e37e4af46031f81950bd2ddd6ba7 (diff)
downloadclang-ebcdeef2f3efd820a57f0f0f9857a7cb2362b496.tar.gz
[CodeGen] Fix some broken IR generated by -fsanitize=unsigned-integer-overflow
I think the author of the function assumed that `GetInsertBlock()` wouldn't change from where `atomicPHI` was created, but this isn't true when `-fsanitize=unsigned-integer-overflow` is enabled (we generate an overflow/continuation label). Fix by keeping track of the block we want to return to to complete the cmpxchg loop. rdar://48406558 Differential revision: https://reviews.llvm.org/D58744 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355054 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen/sanitize-atomic-int-overflow.c')
-rw-r--r--test/CodeGen/sanitize-atomic-int-overflow.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/CodeGen/sanitize-atomic-int-overflow.c b/test/CodeGen/sanitize-atomic-int-overflow.c
new file mode 100644
index 0000000000..a1064f47c3
--- /dev/null
+++ b/test/CodeGen/sanitize-atomic-int-overflow.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14.0 -fsanitize=unsigned-integer-overflow %s -emit-llvm -o - | FileCheck %s
+
+_Atomic(unsigned) atomic;
+
+// CHECK-LABEL: define void @cmpd_assign
+void cmpd_assign() {
+ // CHECK: br label %[[LOOP_START:.*]]
+
+ // CHECK: [[LOOP_START]]:
+ // CHECK-NEXT: phi i32 {{.*}}, [ {{.*}}, %[[INCOMING_BLOCK:.*]] ]
+
+ // CHECK: [[INCOMING_BLOCK]]:
+ // CHECK-NEXT: cmpxchg
+ // CHECK-NEXT: extractvalue
+ // CHECK-NEXT: extractvalue
+ // CHECK-NEXT: br i1 %8, label %{{.*}}, label %[[LOOP_START]]
+ atomic += 1;
+}
+
+// CHECK-LABEL: define void @inc
+void inc() {
+ // CHECK: br label %[[LOOP_START:.*]]
+
+ // CHECK: [[LOOP_START]]:
+ // CHECK-NEXT: phi i32 {{.*}}, [ {{.*}}, %[[INCOMING_BLOCK:.*]] ]
+
+ // CHECK: [[INCOMING_BLOCK]]:
+ // CHECK-NEXT: cmpxchg
+ // CHECK-NEXT: extractvalue
+ // CHECK-NEXT: extractvalue
+ // CHECK-NEXT: br i1 %8, label %{{.*}}, label %[[LOOP_START]]
+ atomic++;
+}