mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 08:26:06 +00:00

We have a new policy in place making links to private resources something we try to avoid in source and test files. Normally, we'd organically switch to the new policy rather than make a sweeping change across a project. However, Clang is in a somewhat special circumstance currently: recently, I've had several new contributors run into rdar links around test code which their patch was changing the behavior of. This turns out to be a surprisingly bad experience, especially for newer folks, for a handful of reasons: not understanding what the link is and feeling intimidated by it, wondering whether their changes are actually breaking something important to a downstream in some way, having to hunt down strangers not involved with the patch to impose on them for help, accidental pressure from asking for potentially private IP to be made public, etc. Because folks run into these links entirely by chance (through fixing bugs or working on new features), there's not really a set of problematic links to focus on -- all of the links have basically the same potential for causing these problems. As a result, this is an omnibus patch to remove all such links. This was not a mechanical change; it was done by manually searching for rdar, radar, radr, and other variants to find all the various problematic links. From there, I tried to retain or reword the surrounding comments so that we would lose as little context as possible. However, because most links were just a plain link with no supporting context, the majority of the changes are simple removals. Differential Review: https://reviews.llvm.org/D158071
97 lines
2.3 KiB
C
97 lines
2.3 KiB
C
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O1 -disable-llvm-passes | FileCheck %s --check-prefix=ALL --check-prefix=O1
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O0 | FileCheck %s --check-prefix=ALL --check-prefix=O0
|
|
|
|
// In all tests, make sure that no expect is generated if optimizations are off.
|
|
// If optimizations are on, generate the correct expect and preserve other necessary operations.
|
|
|
|
int expect_taken(int x) {
|
|
// ALL-LABEL: define{{.*}} i32 @expect_taken
|
|
// O1: call i64 @llvm.expect.i64(i64 {{%.*}}, i64 1)
|
|
// O0-NOT: @llvm.expect
|
|
|
|
if (__builtin_expect (x, 1))
|
|
return 0;
|
|
return x;
|
|
}
|
|
|
|
|
|
int expect_not_taken(int x) {
|
|
// ALL-LABEL: define{{.*}} i32 @expect_not_taken
|
|
// O1: call i64 @llvm.expect.i64(i64 {{%.*}}, i64 0)
|
|
// O0-NOT: @llvm.expect
|
|
|
|
if (__builtin_expect (x, 0))
|
|
return 0;
|
|
return x;
|
|
}
|
|
|
|
|
|
int x;
|
|
int y(void);
|
|
void foo(void);
|
|
|
|
void expect_value_side_effects(void) {
|
|
// ALL-LABEL: define{{.*}} void @expect_value_side_effects()
|
|
// ALL: [[CALL:%.*]] = call i32 @y
|
|
// O1: [[SEXT:%.*]] = sext i32 [[CALL]] to i64
|
|
// O1: call i64 @llvm.expect.i64(i64 {{%.*}}, i64 [[SEXT]])
|
|
// O0-NOT: @llvm.expect
|
|
|
|
if (__builtin_expect (x, y()))
|
|
foo ();
|
|
}
|
|
|
|
|
|
// Make sure that issigprocmask() is called before bar()?
|
|
// There's no compare, so there's nothing to expect?
|
|
void isigprocmask(void);
|
|
long bar(void);
|
|
|
|
int main(void) {
|
|
// ALL-LABEL: define{{.*}} i32 @main()
|
|
// ALL: call void @isigprocmask()
|
|
// ALL: [[CALL:%.*]] = call i64 @bar()
|
|
// O1: call i64 @llvm.expect.i64(i64 0, i64 [[CALL]])
|
|
// O0-NOT: @llvm.expect
|
|
|
|
(void) __builtin_expect((isigprocmask(), 0), bar());
|
|
}
|
|
|
|
|
|
int switch_cond(int x) {
|
|
// ALL-LABEL: define{{.*}} i32 @switch_cond
|
|
// O1: call i64 @llvm.expect.i64(i64 {{%.*}}, i64 5)
|
|
// O0-NOT: @llvm.expect
|
|
|
|
switch(__builtin_expect(x, 5)) {
|
|
default:
|
|
return 0;
|
|
case 0:
|
|
case 1:
|
|
case 2:
|
|
return 1;
|
|
case 5:
|
|
return 5;
|
|
};
|
|
|
|
return 0;
|
|
}
|
|
|
|
int variable_expected(int stuff) {
|
|
// ALL-LABEL: define{{.*}} i32 @variable_expected(
|
|
// O1: call i64 @llvm.expect.i64(i64 {{%.*}}, i64 {{%.*}})
|
|
// O0-NOT: @llvm.expect
|
|
|
|
int res = 0;
|
|
|
|
switch (__builtin_expect(stuff, stuff)) {
|
|
case 0:
|
|
res = 1;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return res;
|
|
}
|