Skip to content

Commit 8c84fe6

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.4
1 parent 82a4277 commit 8c84fe6

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5253,3 +5253,9 @@ def CountedByRef : Builtin {
52535253
let Attributes = [NoThrow, CustomTypeChecking];
52545254
let Prototype = "int(...)";
52555255
}
5256+
5257+
def StaticAnalysisAssume : Builtin {
5258+
let Spellings = ["__builtin_static_analysis_assume"];
5259+
let Attributes = [NoThrow, Const, Pure, UnevaluatedArguments];
5260+
let Prototype = "void(bool)";
5261+
}

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3733,6 +3733,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
37333733

37343734
return RValue::get(Result);
37353735
}
3736+
case Builtin::BI__builtin_static_analysis_assume:
3737+
return RValue::get(nullptr);
37363738
case Builtin::BI__builtin_prefetch: {
37373739
Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0));
37383740
// FIXME: Technically these constants should of type 'int', yes?
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -ast-dump -triple x86_64-linux-gnu %s \
2+
// RUN: | FileCheck %s --strict-whitespace --check-prefixes=CHECK
3+
//
4+
// Tests with serialization:
5+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-pch -o %t %s
6+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -include-pch %t -ast-dump-all /dev/null \
7+
// RUN: | FileCheck %s --strict-whitespace
8+
9+
int fun() {
10+
int x = 0;
11+
__builtin_static_analysis_assume(++x >= 1);
12+
return x;
13+
}
14+
15+
// CHECK: |-CallExpr {{.*}} <line:11:5, col:46> 'void'
16+
// CHECK: | |-ImplicitCastExpr {{.*}} <col:5> 'void (*)(_Bool)' <BuiltinFnToFnPtr>
17+
// CHECK: | | `-DeclRefExpr {{.*}} <col:5> '<builtin fn type>' Function {{.*}} '__builtin_static_analysis_assume' 'void (_Bool)'
18+
// CHECK: | `-ImplicitCastExpr {{.*}} <col:38, col:45> '_Bool' <IntegralToBoolean>
19+
// CHECK: | `-BinaryOperator {{.*}} <col:38, col:45> 'int' '>='
20+
// CHECK: | |-UnaryOperator {{.*}} <col:38, col:40> 'int' prefix '++'
21+
// CHECK: | | `-DeclRefExpr {{.*}} <col:40> 'int' lvalue Var {{.*}} 'x' 'int'
22+
// CHECK: | `-IntegerLiteral {{.*}} <col:45> 'int' 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 6
2+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s \
3+
// RUN: | FileCheck --check-prefix CHECK %s
4+
5+
// CHECK-LABEL: define dso_local i32 @fun(
6+
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
7+
// CHECK-NEXT: [[ENTRY:.*:]]
8+
// CHECK-NEXT: [[X:%.*]] = alloca i32, align 4
9+
// CHECK-NEXT: store i32 0, ptr [[X]], align 4
10+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[X]], align 4
11+
// CHECK-NEXT: ret i32 [[TMP0]]
12+
//
13+
int fun() {
14+
int x = 0;
15+
__builtin_static_analysis_assume(++x >= 1);
16+
return x;
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
2+
3+
void voidfn();
4+
5+
class Foo{};
6+
7+
int fun() {
8+
int x = 0;
9+
__builtin_static_analysis_assume(true);
10+
__builtin_static_analysis_assume(x <= 0);
11+
__builtin_static_analysis_assume(voidfn()); // expected-error{{cannot initialize a parameter of type 'bool' with an rvalue of type 'void}}
12+
__builtin_static_analysis_assume(Foo()); // expected-error{{no viable conversion from 'Foo' to 'bool'}}
13+
return x;
14+
}

0 commit comments

Comments
 (0)