mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 04:26:37 +00:00

This implements the C++23 `[[assume]]` attribute. Assumption information is lowered to a call to `@llvm.assume`, unless the expression has side-effects, in which case it is discarded and a warning is issued to tell the user that the assumption doesn’t do anything. A failed assumption at compile time is an error (unless we are in `MSVCCompat` mode, in which case we don’t check assumptions at compile time). Due to performance regressions in LLVM, assumptions can be disabled with the `-fno-assumptions` flag. With it, assumptions will still be parsed and checked, but no calls to `@llvm.assume` will be emitted and assumptions will not be checked at compile time.
14 lines
303 B
C++
14 lines
303 B
C++
// RUN: %clang_cc1 -std=c++23 -ast-print %s | FileCheck %s
|
|
|
|
// CHECK: void f(int x, int y) {
|
|
void f(int x, int y) {
|
|
// CHECK-NEXT: {{\[}}[assume(true)]]
|
|
[[assume(true)]];
|
|
|
|
// CHECK-NEXT: {{\[}}[assume(2 + 4)]]
|
|
[[assume(2 + 4)]];
|
|
|
|
// CHECK-NEXT: {{\[}}[assume(x == y)]]
|
|
[[assume(x == y)]];
|
|
}
|