Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
192 commits
Select commit Hold shift + click to select a range
dd5ce67
Add contracts representation and parsing. Much thanks to Peter for th…
EricWF Jun 19, 2024
de83929
fix todo
EricWF Jun 19, 2024
3a3d504
get it working end-to-end
EricWF Jun 22, 2024
1f0e34b
a bunch of work, most of it broken
EricWF Jul 2, 2024
d63f11e
Get templates working.
EricWF Jul 3, 2024
bb979cd
Improve codegen, Start on constification.
EricWF Jul 4, 2024
2c6d5fd
A lot of forward progress.
EricWF Jul 6, 2024
249f571
whitespace changes
EricWF Jul 6, 2024
4eee4d5
change flags, but break clang
EricWF Jul 6, 2024
b039625
Add contracts representation and parsing. Much thanks to Peter for th…
EricWF Jun 19, 2024
6b6d951
fix todo
EricWF Jun 19, 2024
9674f45
get it working end-to-end
EricWF Jun 22, 2024
93a6ba5
a bunch of work, most of it broken
EricWF Jul 2, 2024
4b91b34
Get templates working.
EricWF Jul 3, 2024
670df13
Improve codegen, Start on constification.
EricWF Jul 4, 2024
33eaf39
A lot of forward progress.
EricWF Jul 6, 2024
c8290ce
whitespace changes
EricWF Jul 6, 2024
d19459f
change flags, but break clang
EricWF Jul 6, 2024
acd41cd
finish merge
EricWF Jul 6, 2024
c6eac65
get constification working for "this"
EricWF Jul 6, 2024
6071299
Fix constexpr eval and bug in contract group
EricWF Jul 6, 2024
391ac51
Fix codegen for trap
EricWF Jul 6, 2024
d399ebf
Emit the contract assertion info as a single struct
EricWF Jul 7, 2024
33d86bf
Get codegen working with exceptions
EricWF Jul 8, 2024
dd4fb76
Fix cleanups by finishing statement.
EricWF Jul 8, 2024
10d6946
Fix some modules bugs & fix exception violation handling
EricWF Jul 8, 2024
3653205
Temp work save
EricWF Jul 10, 2024
138ce13
Merge branch 'main' of github.com:llvm/llvm-project into eric-contrac…
EricWF Jul 10, 2024
3fa7f33
remove temp asserts
EricWF Jul 10, 2024
5053299
rename ContractOpts to prevent GCC from getting mad
EricWF Jul 11, 2024
1b41645
Fix build with GCC but introduce issues in constant evaluation
EricWF Jul 11, 2024
a21af21
replace assertion with TODO diagnostic
EricWF Jul 11, 2024
4375eca
fixup more tests
EricWF Jul 11, 2024
e11ee1f
not working, but progress
EricWF Jul 11, 2024
5baf4fb
Constexpr evaluation hacked together, don't really understand it all yet
EricWF Jul 12, 2024
ea09d6a
Got constant expressions working.
EricWF Jul 14, 2024
8f168e8
Merge branch 'contracts-main' of github.com:efcs/llvm-project into er…
EricWF Jul 14, 2024
8ad85a3
start expr constant cleanup
EricWF Jul 14, 2024
f87514d
Finish constexpr cleanup - candidate for nightly
EricWF Jul 14, 2024
e68de9f
remove duplicate test
EricWF Jul 14, 2024
0d848f3
It's a bunch of progress, but a big mess.
EricWF Jul 16, 2024
c5c572b
Fixes for nightly build
EricWF Jul 16, 2024
ff28a02
Merge branch 'main' into eric-contracts
EricWF Jul 16, 2024
8e108c3
Merge branch 'main' of github.com:llvm/llvm-project into eric-contracts
EricWF Jul 16, 2024
c973386
Get post codegen working.
EricWF Jul 16, 2024
deee849
Add more tests, fix bug in constant evaluation
EricWF Jul 16, 2024
c90146c
Get contract codegen working with phi dispatching.
EricWF Jul 16, 2024
2496eb1
remove bad comment, start libc++ tests
EricWF Jul 17, 2024
eb20a06
Merge branch 'main' of github.com:llvm/llvm-project into eric-contracts
EricWF Jul 17, 2024
859c7cc
resolve parsing regression
EricWF Jul 17, 2024
eba4e9b
Add some new kinds of tests, also some junk temp cmake, get post work…
EricWF Jul 17, 2024
1c7ca5f
cleanup more code
EricWF Jul 17, 2024
bb6bc4d
Save progress.
EricWF Jul 26, 2024
008b9f8
Merge branch 'main' into eric-contracts
EricWF Jul 26, 2024
a0696f1
Save libc++ improvements
EricWF Jul 26, 2024
5bd7502
Merge branch 'main' into eric-contracts
EricWF Jul 28, 2024
eeaf4c8
Cleanup, Fixes, and restart of codegen.
EricWF Jul 29, 2024
7593ea5
Messy Save.
EricWF Jul 31, 2024
e42e0da
Remove debug code.
EricWF Jul 31, 2024
1853eda
merge
EricWF Jul 31, 2024
8f3798b
Merge remote-tracking branch 'upstream/main' into eric-contracts
EricWF Jul 31, 2024
5d3fe34
Add some tests for contracts.
EricWF Jul 31, 2024
7d538a6
rework codegen, not working, but need to merge
EricWF Jul 31, 2024
20d89bc
merge
EricWF Jul 31, 2024
1cd86ae
Rework codegen so that exceptions are hopefully supported...
EricWF Jul 31, 2024
1983bc6
Fix codegen for throwing contracts
EricWF Aug 1, 2024
aa460bb
Some test cleanup
EricWF Aug 1, 2024
dd42a17
get more working
EricWF Aug 1, 2024
7b5d440
Get constant initialization working.
EricWF Aug 1, 2024
636379d
Fix bug in constant evaluation reusing previously computed value
EricWF Aug 1, 2024
d8aa52a
Add diagnostics for redeclarations, but redeclarations dont quite work
EricWF Aug 2, 2024
bff0015
Improvements, and some broken expr constant stuff
EricWF Aug 5, 2024
b3a7912
mostly working
EricWF Aug 5, 2024
7a13879
Fix GCC build hopefully
EricWF Aug 5, 2024
00a37e6
working save. needs cleanup
EricWF Aug 5, 2024
43f9a99
remove a bunch of debug print lines
EricWF Aug 5, 2024
ce40d46
suppress warning
EricWF Aug 5, 2024
94962a0
remove and replace bad assertions
EricWF Aug 5, 2024
fa665c9
cleanup for deduced auto
EricWF Aug 5, 2024
42aede0
Lazy parsing and support for trailing auto
EricWF Aug 5, 2024
7b2d493
try adding builders
EricWF Aug 5, 2024
8410ea6
adjust glob
EricWF Aug 5, 2024
7f73aed
get working
EricWF Aug 5, 2024
d435b4b
checkout sources first
EricWF Aug 5, 2024
acd8756
fix build
EricWF Aug 5, 2024
c21ac2e
a bunch of dummy code and cleanup
EricWF Aug 7, 2024
ca97bd8
almost clean test suite
EricWF Aug 7, 2024
f876563
get tests passing
EricWF Aug 7, 2024
f29f4d8
fixup
EricWF Aug 7, 2024
790e248
changes
EricWF Aug 7, 2024
e2823ad
all changes
EricWF Aug 7, 2024
e406e30
all changes
EricWF Aug 7, 2024
736cd30
try to add verification job
EricWF Aug 8, 2024
39b13ff
try to add verification job
EricWF Aug 8, 2024
be3618e
force ci
EricWF Aug 8, 2024
ead688e
remove garbage file
EricWF Aug 8, 2024
d8ce14a
Cleanup headers
EricWF Aug 9, 2024
b86bb4f
make almost everything worse
EricWF Aug 9, 2024
2a95f50
remove garbage
EricWF Aug 10, 2024
0536778
merge with upstream
EricWF Aug 10, 2024
19200f3
Cleanup and format
EricWF Aug 12, 2024
7b35443
Start work on virtual functions by adding caller side emmission.
EricWF Aug 12, 2024
97ee8da
Merge branch 'main' into eric-contracts
EricWF Aug 12, 2024
9c7e575
start representation overhall
EricWF Aug 13, 2024
f0c696e
Before merge
EricWF Aug 14, 2024
e1eae95
attempt bad merge
EricWF Aug 14, 2024
0e11e7e
Start a very large refactor of template machinary and sema structure.
EricWF Aug 17, 2024
1a8691e
A working mess.
EricWF Aug 17, 2024
d8fa6bf
remove dead code
EricWF Aug 17, 2024
55c0115
fix up tests, get templates working better
EricWF Aug 19, 2024
a4bbee1
Add more tests
EricWF Aug 19, 2024
b6111fa
Merge branch 'main' of github.com:llvm/llvm-project into eric-contracts
EricWF Aug 19, 2024
5cdd5ff
more cleanup
EricWF Aug 20, 2024
d00bcda
diagnostic improvements
EricWF Aug 21, 2024
a8fec54
Fix a number of crashes
EricWF Aug 21, 2024
a825f44
merge
EricWF Aug 23, 2024
41eb0e6
Merge branch 'main' of github.com:llvm/llvm-project into eric-contracts
EricWF Aug 23, 2024
bde79ad
everything except libcxx working
EricWF Aug 23, 2024
ff224b5
Merge branch 'main' of github.com:llvm/llvm-project into eric-contracts
EricWF Aug 23, 2024
03703a6
I think I got lambdas working-ish
EricWF Aug 24, 2024
1b34713
remove print code
EricWF Aug 24, 2024
33117f7
remove xfails, is this working?
EricWF Aug 24, 2024
8ae4b0f
start work on instantiation stuff
EricWF Aug 25, 2024
ad37382
adjust libcxx tests
EricWF Aug 25, 2024
624e117
get contract diagnosing almost working
EricWF Aug 26, 2024
c085a7b
save progress
EricWF Aug 27, 2024
f5bd830
save before removing old code
EricWF Aug 29, 2024
98b8658
remove a bunch of bad code
EricWF Aug 29, 2024
28bc937
get working
EricWF Aug 29, 2024
aae32af
More cleanup, add crashing lambda tests
EricWF Aug 30, 2024
fdbd394
various saves
EricWF Sep 1, 2024
4f16753
merge with upstream
EricWF Sep 1, 2024
9b48c77
save state
EricWF Sep 5, 2024
306f147
with working tests
EricWF Sep 5, 2024
2f53e1c
broken
EricWF Sep 6, 2024
bfd1dd9
idk
EricWF Oct 2, 2024
99b70b6
delete
EricWF Oct 11, 2024
01c0a7b
merge
EricWF Oct 13, 2024
654a052
address equality bug
EricWF Oct 14, 2024
5cfd1fa
add test
EricWF Oct 22, 2024
8b799fa
llvm fixes v2
EricWF Oct 11, 2024
7b8a2c0
merge
EricWF Nov 12, 2024
1e0fa51
finish merge
EricWF Dec 19, 2024
0ea44a7
merge
EricWF Jan 6, 2025
cf071e8
Merge branch 'main' of github.com:llvm/llvm-project into save-contrac…
EricWF Jan 7, 2025
1bfef1b
fix merge issue
EricWF Jan 7, 2025
c948813
cleanup and merge fixes
EricWF Jan 7, 2025
1ce21f0
add more printouts
EricWF Jan 11, 2025
d4cc62e
merge with main
EricWF Jan 21, 2025
45a17da
complete merge
EricWF Jan 26, 2025
88ae701
save
EricWF Feb 2, 2025
5754fed
merge
EricWF Feb 3, 2025
4a726dc
fix merge
EricWF Feb 3, 2025
e08f16b
adjust some failing libc++ tests
EricWF Feb 3, 2025
e845f32
merge
EricWF Feb 28, 2025
0fdd326
fix build error only present on GCC?
EricWF Feb 28, 2025
7477b44
finish merge
EricWF Apr 22, 2025
d45524d
Merge branch 'contracts-base' into contracts-nightly
EricWF Apr 22, 2025
f58bb13
Fix build error under GCC
EricWF Apr 22, 2025
3f77a05
Merge w/ Parser changes
EricWF May 21, 2025
741163d
Add non-cassert parts of D3290R3.
EricWF Jun 27, 2025
7a59c2f
Merge with contracts-base
EricWF Jun 27, 2025
32ffa4f
Merge branch 'contracts-base' into contracts-nightly
EricWF Jun 27, 2025
0852a7b
fix broken build due to new warning
EricWF Jun 27, 2025
189f6ff
Merge branch 'contracts-base' into contracts-nightly
EricWF Jun 27, 2025
07a81cc
add new interfaces
EricWF Jun 27, 2025
6667568
Merge branch 'contracts-base' into contracts-nightly
EricWF Jun 29, 2025
7c23886
Merge branch 'contracts-base' into contracts-nightly
EricWF Jun 30, 2025
d456da7
Merge branch 'contracts-base' into contracts-nightly
EricWF Jun 30, 2025
7793c0e
fix build failures
EricWF Jun 30, 2025
aeba9b9
merge done
EricWF Jul 7, 2025
ee4919f
scope flag rewrites
EricWF Jul 7, 2025
9de4341
start mangling changes
EricWF Jul 7, 2025
aed147b
merge with main
EricWF Jul 11, 2025
441e5bd
fix bad merge
EricWF Jul 11, 2025
962b8e9
fix warnings turned into errors
EricWF Jul 11, 2025
7c8a3cb
add new source location builtin
EricWF Jul 22, 2025
fb45504
Merge branch 'contracts-base' into contracts-nightly
EricWF Jul 22, 2025
784686d
Merge branch 'contracts-base' into contracts-nightly
EricWF Jul 23, 2025
8ee401f
work around C build failures
EricWF Jul 23, 2025
f3615bf
Merge branch 'contracts-base' into contracts-nightly
EricWF Jul 25, 2025
7f7246e
Merge branch 'contracts-base' into contracts-nightly
EricWF Jul 28, 2025
6b78e30
finish merge but broken libcxx tests
EricWF Jul 29, 2025
c49705f
Fix up post-merge breakages
EricWF Jul 30, 2025
d2a5be8
Merge branch 'contracts-base' into contracts-nightly
EricWF Jul 30, 2025
7d383f0
Delete change_default_route_ip.py
EricWF Aug 2, 2025
f1e4683
Delete change_network_config.yml
EricWF Aug 2, 2025
1c27de9
merge with main
EricWF Aug 7, 2025
e8dfec8
merge with main
EricWF Sep 26, 2025
1f8ffc0
merge changes
EricWF Sep 26, 2025
01c3f80
remove temp changes
EricWF Sep 26, 2025
ceadf96
Merge branch 'contracts-nightly' of github.com:efcs/llvm-project into…
EricWF Oct 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/ericwf-contracts-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: EricWF Contracts Nightly Release flow

permissions:
contents: write
actions: read

on:
workflow_dispatch:
push:
branches:
- 'eric-contracts'
- "eric-test-contracts"


concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
check_clang:
name: "Do it"
if: github.repository_owner == 'EricWF'
runs-on: aah
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 0
- name: "Setup"
run: |
mkdir build
mkdir install

- name: "Configure"
run: >
cmake -B build -S ./llvm/
-G Ninja
-DCMAKE_BUILD_TYPE=RELWITHDEBINFO
-DLLVM_ENABLE_PROJECTS="clang"
"-DLLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind"
-DLLVM_ENABLE_ASSERTIONS=ON
-DLLVM_USE_LINKER=mold
-DCMAKE_INSTALL_PREFIX=./install
-DCMAKE_C_COMPILER=clang
-DCMAKE_CXX_COMPILER=clang++
'-DLLVM_USE_SANITIZER=Address;Undefined'
- name: Build Clang & Libc++
run: |
cd build
ninja clang
ninja cxx
- name: Test Clang
run: |
cd build
ninja check-clang
- name: Check Libc++
run: |
cd build
ninja check-cxx
- name: Install
run: |
cd build
ninja install
15 changes: 15 additions & 0 deletions CONTRACTS_TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* Parse result name in post contracts
* auto declared functions.
* templates.
* Late parsing in general
* Diagnose
* Test parsing failures
* What happens when pre/post throws from a noexcept function? Can we even callee-emit contracts?
* Start constification
* Check 'this' access in pre/post
* Codegen:
* Make it work

* Required headers?
<contracts>
<source_location>
Empty file added Notes.md
Empty file.
Empty file added RFC.txt
Empty file.
15 changes: 15 additions & 0 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
// The decl is built when constructing 'BuiltinVaListDecl'.
mutable Decl *VaListTagDecl = nullptr;

// Decl used to define the datastructure for the contract violation object
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Decl used to define the datastructure for the contract violation object
// Decl used to define the data structure for the contract violation object

// used for C++ contracts
mutable Decl *BuiltinContractViolationRecordDecl = nullptr;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to make that a RecordDecl directly?


// Implicitly-declared type 'struct _GUID'.
mutable TagDecl *MSGuidTagDecl = nullptr;

Expand Down Expand Up @@ -2446,6 +2450,17 @@ class ASTContext : public RefCountedBase<ASTContext> {
return getCanonicalTagType(MSGuidTagDecl);
}

CanQualType getBuiltinContractViolationRecordType() const {
return getCanonicalTagType(
cast<RecordDecl>(getBuiltinContractViolationRecordDecl()));
}

Decl *getBuiltinContractViolationRecordDecl() const;
UnnamedGlobalConstantDecl *
BuildViolationObject(const ContractStmt *CS,
const FunctionDecl *CurDecl = nullptr);


/// Retrieve the implicitly-predeclared 'struct type_info' declaration.
TagDecl *getMSTypeInfoTagDecl() const {
// Lazily create this type on demand - it's only needed for MS builds.
Expand Down
16 changes: 15 additions & 1 deletion clang/include/clang/AST/ASTNodeTraverser.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ASTNodeTraverser

// Some statements have custom mechanisms for dumping their children.
if (isa<DeclStmt, GenericSelectionExpr, RequiresExpr,
OpenACCWaitConstruct, SYCLKernelCallStmt>(S))
OpenACCWaitConstruct, SYCLKernelCallStmt, ContractStmt>(S))
Comment on lines 161 to +162
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just make expressions children. It's not yet clear to me why they should not be, as I do a linear read through

return;

if (Traversal == TK_IgnoreUnlessSpelledInSource &&
Expand Down Expand Up @@ -556,6 +556,9 @@ class ASTNodeTraverser
if (const AssociatedConstraint &TRC = D->getTrailingRequiresClause())
Visit(TRC.ConstraintExpr);

if (const ContractSpecifierDecl *CSD = D->getContracts())
Visit(CSD);

if (Traversal == TK_IgnoreUnlessSpelledInSource && D->isDefaulted())
return;

Expand Down Expand Up @@ -747,6 +750,17 @@ class ASTNodeTraverser
Visit(D->getConstraintExpr());
}

void VisitContractSpecifierDecl(const ContractSpecifierDecl *CSD) {
for (auto *CS : CSD->contracts())
Visit(CS);
}

void VisitContractStmt(const ContractStmt *S) {
if (S->hasResultName())
Visit(S->getResultName());
Visit(S->getCond());
}

void VisitImplicitConceptSpecializationDecl(
const ImplicitConceptSpecializationDecl *CSD) {
for (const TemplateArgument &Arg : CSD->getTemplateArguments())
Expand Down
77 changes: 66 additions & 11 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace clang {
class ASTContext;
struct ASTTemplateArgumentListInfo;
class CompoundStmt;
class ContractStmt;
class ContractSpecifierDecl;
class DependentFunctionTemplateSpecializationInfo;
class EnumDecl;
class Expr;
Expand All @@ -70,6 +72,7 @@ class Module;
class NamespaceDecl;
class ParmVarDecl;
class RecordDecl;
class ResultNameDecl;
class Stmt;
class StringLiteral;
class TagDecl;
Expand All @@ -80,6 +83,7 @@ class TypeAliasTemplateDecl;
class UnresolvedSetImpl;
class VarTemplateDecl;
enum class ImplicitParamKind;
enum class ContractKind;

// Holds a constraint expression along with a pack expansion index, if
// expanded.
Expand Down Expand Up @@ -778,8 +782,8 @@ struct QualifierInfo {
/// Contains type source information through TypeSourceInfo.
class DeclaratorDecl : public ValueDecl {
// A struct representing a TInfo, a trailing requires-clause and a syntactic
// qualifier, to be used for the (uncommon) case of out-of-line declarations
// and constrained function decls.
// qualifier, to be used for the (uncommon) case of out-of-line declarations,
// constrained function decls or functions with contracts.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// constrained function decls or functions with contracts.
// constrained function decls or functions with pre/post conditions.

struct ExtInfo : public QualifierInfo {
TypeSourceInfo *TInfo = nullptr;
AssociatedConstraint TrailingRequiresClause;
Expand Down Expand Up @@ -908,17 +912,24 @@ struct EvaluatedStmt {
bool HasICEInit : 1;
bool CheckedForICEInit : 1;

// The APvalue stored here may need re-evaluation under contracts, in which
// case we need to track if we've already regisetered this value for
// destruction.
bool RegisteredForDestruction : 1;

bool HasSideEffects : 1;
bool CheckedForSideEffects : 1;


LazyDeclStmtPtr Value;
APValue Evaluated;

EvaluatedStmt()
: WasEvaluated(false), IsEvaluating(false),
HasConstantInitialization(false), HasConstantDestruction(false),
HasICEInit(false), CheckedForICEInit(false), HasSideEffects(false),
CheckedForSideEffects(false) {}
HasICEInit(false), CheckedForICEInit(false),
RegisteredForDestruction(false), HasSideEffects(false), CheckedForSideEffects(false) {}

};

/// Represents a variable declaration or definition.
Expand Down Expand Up @@ -1413,7 +1424,8 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {

private:
APValue *evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> &Notes,
bool IsConstantInitialization) const;
bool IsConstantInitialization,
bool EnableContracts) const;

public:
/// Return the already-evaluated value of this variable's
Expand Down Expand Up @@ -1445,8 +1457,13 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
/// Evaluate the initializer of this variable to determine whether it's a
/// constant initializer. Should only be called once, after completing the
/// definition of the variable.
bool checkForConstantInitialization(
SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
bool
checkForConstantInitialization(SmallVectorImpl<PartialDiagnosticAt> &Notes,
bool EnableContracts = true) const;

bool
recheckForConstantInitialization(SmallVectorImpl<PartialDiagnosticAt> &Notes,
bool EnableContracts = true) const;

void setInitStyle(InitializationStyle Style) {
VarDeclBits.InitStyle = Style;
Expand Down Expand Up @@ -2058,13 +2075,18 @@ class FunctionDecl : public DeclaratorDecl,
/// no formals.
ParmVarDecl **ParamInfo = nullptr;

/// The contract sequence specified on this function declaration if there is
/// any, otherwise nullptr
ContractSpecifierDecl *Contracts = nullptr;

/// The active member of this union is determined by
/// FunctionDeclBits.HasDefaultedOrDeletedInfo.
union {
/// The body of the function.
LazyDeclStmtPtr Body;
/// Information about a future defaulted function definition.
DefaultedOrDeletedFunctionInfo *DefaultedOrDeletedInfo;
///
};

unsigned ODRHash;
Expand Down Expand Up @@ -2154,7 +2176,8 @@ class FunctionDecl : public DeclaratorDecl,
const DeclarationNameInfo &NameInfo, QualType T,
TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin,
bool isInlineSpecified, ConstexprSpecKind ConstexprKind,
const AssociatedConstraint &TrailingRequiresClause);
const AssociatedConstraint &TrailingRequiresClause,
ContractSpecifierDecl *Contracts = nullptr);

using redeclarable_base = Redeclarable<FunctionDecl>;

Expand Down Expand Up @@ -2190,20 +2213,23 @@ class FunctionDecl : public DeclaratorDecl,
TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin = false,
bool isInlineSpecified = false, bool hasWrittenPrototype = true,
ConstexprSpecKind ConstexprKind = ConstexprSpecKind::Unspecified,
const AssociatedConstraint &TrailingRequiresClause = {}) {
const AssociatedConstraint &TrailingRequiresClause = {},
ContractSpecifierDecl *Contracts = nullptr) {

DeclarationNameInfo NameInfo(N, NLoc);
return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
UsesFPIntrin, isInlineSpecified,
hasWrittenPrototype, ConstexprKind,
TrailingRequiresClause);
TrailingRequiresClause, Contracts);
}

static FunctionDecl *
Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
StorageClass SC, bool UsesFPIntrin, bool isInlineSpecified,
bool hasWrittenPrototype, ConstexprSpecKind ConstexprKind,
const AssociatedConstraint &TrailingRequiresClause);
const AssociatedConstraint &TrailingRequiresClause, ContractSpecifierDecl *Contracts);


static FunctionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);

Expand Down Expand Up @@ -2765,6 +2791,10 @@ class FunctionDecl : public DeclaratorDecl,
return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
}


FunctionDecl *getDeclForContracts();
const FunctionDecl *getDeclForContracts() const;

Comment on lines +2794 to +2797
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not used (and if we were to keep them we could come up with a better name)

unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const;

// ArrayRef interface to parameters.
Expand Down Expand Up @@ -3138,6 +3168,22 @@ class FunctionDecl : public DeclaratorDecl,
return {};
}

/// Set the function level contracts for this function. Update the specifier
/// decl and it's children to have this declaration as a declaration context.
void setContracts(ContractSpecifierDecl *CSD);

bool hasContracts() const { return Contracts != nullptr; }

ContractSpecifierDecl *getContracts() const { return Contracts; }

using ContractRange = llvm::iterator_range<llvm::filter_iterator<
ArrayRef<ContractStmt *>::iterator, bool (*)(const ContractStmt *)>>;

// Convenience functions to get the preconditions and postconditions.
ArrayRef<ContractStmt *> contracts() const;
ContractRange preconditions() const;
ContractRange postconditions() const;

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) {
Expand Down Expand Up @@ -3184,6 +3230,9 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
unsigned Mutable : 1;
LLVM_PREFERRED_TYPE(InitStorageKind)
unsigned StorageKind : 2;
LLVM_PREFERRED_TYPE(bool)
unsigned IsConstifiedCapture : 1;

mutable unsigned CachedFieldIndex : 28;

/// If this is a bitfield with a default member initializer, this
Expand Down Expand Up @@ -3223,6 +3272,7 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
CachedFieldIndex(0), Init() {
if (BW)
setBitWidth(BW);
IsConstifiedCapture = false;
}

public:
Expand Down Expand Up @@ -3385,6 +3435,11 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
/// Set the captured variable length array type for this field.
void setCapturedVLAType(const VariableArrayType *VLAType);

bool isConstifiedCapture() const { return IsConstifiedCapture; }
void setIsConstifiedCapture(bool Value = true) {
IsConstifiedCapture = Value;
}

/// Returns the parent of this field declaration, which
/// is the struct in which this field is defined.
///
Expand Down
Loading
Loading