From 53e43f4d9e8e4f3fd1bd2ed1a81af1b8870b92a7 Mon Sep 17 00:00:00 2001 From: Erik Pilkington Date: Thu, 28 Feb 2019 00:47:55 +0000 Subject: [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 llvm-svn: 355054 --- clang/test/CodeGen/sanitize-atomic-int-overflow.c | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 clang/test/CodeGen/sanitize-atomic-int-overflow.c (limited to 'clang/test/CodeGen/sanitize-atomic-int-overflow.c') diff --git a/clang/test/CodeGen/sanitize-atomic-int-overflow.c b/clang/test/CodeGen/sanitize-atomic-int-overflow.c new file mode 100644 index 00000000000..a1064f47c34 --- /dev/null +++ b/clang/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++; +} -- cgit v1.2.3