llvm-project/clang/test/SemaCXX/cxx23-assume-print.cpp
Sirraide 2b5f68a5f6
[Clang][C++23] Implement P1774R8: Portable assumptions (#81014)
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.
2024-03-09 12:07:16 +01:00

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)]];
}