Skip to content

nonblocking/nonallocating attributes (was: nolock/noalloc) #84983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 84 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
0619e30
Initial squash/cleanup
Mar 12, 2024
2a1b0d2
Cleanup, mostly code style
Mar 12, 2024
8aaeeb2
squash me
Mar 12, 2024
eb204df
apply the in-tree clang-format (which seems subtly different from my …
Mar 12, 2024
3b0277b
Address most of the low-hanging fruit in the initial review feedback.
Mar 13, 2024
4c6486f
Update clang/include/clang/AST/Type.h
dougsonos Mar 14, 2024
e6b1e35
- Sema::CheckAddCallableWithEffects: really do skip functions in depe…
Mar 13, 2024
fc67743
ASTContext::mergeFunctionTypes doesn't seem to need to do anything (?)
Mar 15, 2024
a638125
Fix function pointer type conversion in C by making IsFunctionConvers…
Mar 15, 2024
c2ba529
De-virtualize FunctionEffect; it's now a value type. Prepare for the …
Mar 16, 2024
2a5c14f
Remove unused parameters from FunctionEffect interface.
Mar 16, 2024
ad39599
Don't merge effects back to Old on redeclaration
Mar 16, 2024
513c88c
Fix: canInferOnFunction can't always get a TypeSourceInfo.
Mar 17, 2024
1325429
Cleanup of redeclarations (Sema::MergeFunctionDecl) so that the type …
Mar 19, 2024
5ac7429
FunctionEffectSet::create() is now a method of ASTContext; the global…
Mar 19, 2024
81b86df
- Serialize FunctionEffectSet as part of a FunctionProtoType.
Mar 19, 2024
8414186
Don't repeat function names in diagnostics.
Mar 20, 2024
62b125e
Functionality:
Mar 20, 2024
b15b53a
Merge remote-tracking branch 'llvm-origin/main' into nolock
Apr 3, 2024
525962e
Mass renaming: nolock/noalloc -> nonblocking/nonallocating
Apr 3, 2024
c026355
Remove vestigial FunctionEffect flags
Apr 3, 2024
02a3b7a
ArrayRef<const FunctionEffect> -> ArrayRef<FunctionEffect> (it's alre…
Apr 4, 2024
8121422
Adding the `blocking` and `allocating` attributes, as synonyms for `n…
Apr 5, 2024
9471aa1
Look for blocking and allocating attributes across all redeclarations.
Apr 5, 2024
12e213a
Reinstate the warning that nonblocking/nonallocating should be accomp…
Apr 5, 2024
2a58dda
Groundwork for `nonblocking(expr)`
Apr 9, 2024
e942a90
Low-hanging fruit in review feedback.
Apr 10, 2024
45389bd
- During parsing, don't remove nonallocating when nonblocking is adde…
Apr 11, 2024
80d5e7a
- Get rid of ugly const_cast in Sema::CheckOverridingFunctionAttributes.
Apr 11, 2024
9e223a3
Split out the Objective-C tests into a separate source file.
Apr 11, 2024
9bac8d2
Make FunctionEffectSet::operator==() more elegant.
Apr 11, 2024
b955435
Create a flat effect representation in FunctionProtoType. Renaming of…
Apr 13, 2024
6045573
Separate effects and conditions.
Apr 15, 2024
57d09ce
FunctionEffectCondExpr => FunctionEffectCondition
Apr 16, 2024
a9edec6
FunctionTypeEffectSet => FunctionEffectSet
Apr 16, 2024
80495b7
nonblocking(cond) now parsed into new form.
Apr 16, 2024
1853b39
wip with computed effects
Apr 18, 2024
0aa20af
- Inline the methods on Decl.
Apr 23, 2024
67c3e47
Merge llvm-origin/main into nolock
Apr 23, 2024
ca9b8fa
- Adapt to merge from main.
Apr 24, 2024
5143877
tiny cleanup
Apr 24, 2024
8c691dc
Merge main into nolock
Apr 25, 2024
65e5b61
Tests involving nonblocking(expression)
Apr 25, 2024
1748edb
ASTReader: adapt to GlobalDeclID change
Apr 26, 2024
485c941
warn_perf_constraint_implies_noexcept should only be issued in C++ wi…
Apr 26, 2024
92e4b9a
Obtain extern-C-ness from the function's canonical Decl.
Apr 28, 2024
c534d63
Fix build problem involving std::any_of and a FunctionEffectsRef.
Apr 29, 2024
5cd7bfd
Remove AnalysisBasedWarnings debug code that was pulling in ASTMatchers.
May 2, 2024
c18b774
Remove the 2nd pass caller/callee analysis/verification for now (to b…
May 2, 2024
13e71c0
Merge branch 'main' into nolock
May 2, 2024
b6cfea8
In Sema::ImpCastExprToType, the check for a nullptr source was
May 2, 2024
711bc56
Better attribute documentation
May 2, 2024
990f5bb
- Remove disabling of future warning
May 3, 2024
db576ef
Cleanup dead code.
May 3, 2024
b95964c
- AttrDocs: add note about -W option to control diagnostics.
May 3, 2024
46830f6
Review feedback, notably: FunctionEffectsRef invariants, mergeFunctio…
May 4, 2024
d918424
Review feedback:
May 4, 2024
86795b4
Detect and diagnose conflicts when merging effects between declarations.
May 5, 2024
8fdea5b
In CheckOverridingFunctionAttributes, gather and report effect confli…
May 6, 2024
f4e299f
nonblocking(expr): Simplify ActOnEffectExpression, add tests.
May 6, 2024
cad5d0d
- Require function prototypes in conjunction with the new attributes.
May 6, 2024
f4112ff
tighten up ActOnEffectExpression
May 6, 2024
c2848f8
More syntax tests.
May 7, 2024
1fef4b1
Apply suggestions from code review
dougsonos May 16, 2024
ba7f53f
- review feedback: getCondition(), default-constructable iterator.
May 16, 2024
173d36b
Remove the "clang_" prefix from the attribute spellings.
May 16, 2024
5438e96
More review feedback.
May 16, 2024
9e4782c
- Clean up comments (trailing period).
May 17, 2024
60bf34c
TreeTransform is a class not a struct.
May 21, 2024
13ba987
Merge branch 'main' into nolock
May 21, 2024
877dec8
Add a positive test case per Aaron's feedback
May 22, 2024
6a92ddf
Merge branch 'main' into nolock
May 22, 2024
8bef15b
Fix: read past end of Conditions array in FunctionEffectSet::insert.
May 24, 2024
f015a24
Apply suggestions from code review
dougsonos May 24, 2024
d8d34be
FunctionEffectCondition => EffectConditionExpr, more minor review fee…
May 24, 2024
29d2c3d
In FunctionEffectsRef::get(QualType QT), handle case of multiple levels
May 24, 2024
8204611
Merge llvm-origin/main into nolock
May 27, 2024
3ac9bcb
Review feedback:
May 27, 2024
dbc511a
Add tests suggested by Aaron Ballman.
Jun 18, 2024
7cda574
Defer diagnosis of conflicting effect attributes when there is a cond…
Jun 20, 2024
23ff5a5
tolerate/ignore redundant attributes
Jun 20, 2024
23d486b
Merge remote-tracking branch 'llvm-origin/main' into nolock
Jun 20, 2024
7505858
Release notes
May 3, 2024
64fede2
fix test failure (last merge from main changed how bool template argu…
Jun 21, 2024
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
5 changes: 5 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,11 @@ Attribute Changes in Clang
};


- Introduced new function type attributes ``[[clang::nonblocking]]``, ``[[clang::nonallocating]]``,
``[[clang::blocking]]``, and ``[[clang::allocating]]``, with GNU-style variants as well.
The attributes declare constraints about a function's behavior pertaining to blocking and
heap memory allocation.

Improvements to Clang's diagnostics
-----------------------------------
- Clang now applies syntax highlighting to the code snippets it
Expand Down
9 changes: 9 additions & 0 deletions clang/include/clang/AST/AbstractBasicReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ class DataStreamBasicReader : public BasicReaderBase<Impl> {
return FunctionProtoType::ExtParameterInfo::getFromOpaqueValue(value);
}

FunctionEffect readFunctionEffect() {
uint32_t value = asImpl().readUInt32();
return FunctionEffect::fromOpaqueInt32(value);
}

EffectConditionExpr readEffectConditionExpr() {
return EffectConditionExpr{asImpl().readExprRef()};
}

NestedNameSpecifier *readNestedNameSpecifier() {
auto &ctx = getASTContext();

Expand Down
8 changes: 8 additions & 0 deletions clang/include/clang/AST/AbstractBasicWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ class DataStreamBasicWriter : public BasicWriterBase<Impl> {
asImpl().writeUInt32(epi.getOpaqueValue());
}

void writeFunctionEffect(FunctionEffect E) {
asImpl().writeUInt32(E.toOpaqueInt32());
}

void writeEffectConditionExpr(EffectConditionExpr CE) {
asImpl().writeExprRef(CE.getCondition());
}

void writeNestedNameSpecifier(NestedNameSpecifier *NNS) {
// Nested name specifiers usually aren't too long. I think that 8 would
// typically accommodate the vast majority.
Expand Down
17 changes: 17 additions & 0 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3042,6 +3042,16 @@ class FunctionDecl : public DeclaratorDecl,
/// computed and stored.
unsigned getODRHash() const;

FunctionEffectsRef getFunctionEffects() const {
// Effects may differ between declarations, but they should be propagated
// from old to new on any redeclaration, so it suffices to look at
// getMostRecentDecl().
if (const auto *FPT =
getMostRecentDecl()->getType()->getAs<FunctionProtoType>())
return FPT->getFunctionEffects();
return {};
}

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) {
Expand Down Expand Up @@ -4670,6 +4680,13 @@ class BlockDecl : public Decl, public DeclContext {

SourceRange getSourceRange() const override LLVM_READONLY;

FunctionEffectsRef getFunctionEffects() const {
if (const TypeSourceInfo *TSI = getSignatureAsWritten())
if (const auto *FPT = TSI->getType()->getAs<FunctionProtoType>())
return FPT->getFunctionEffects();
return {};
}

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == Block; }
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/AST/PropertiesBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def ExtParameterInfo : PropertyType<"FunctionProtoType::ExtParameterInfo">;
def FixedPointSemantics : PropertyType<"llvm::FixedPointSemantics"> {
let PassByReference = 1;
}
def FunctionEffect : PropertyType<"FunctionEffect">;
def EffectConditionExpr : PropertyType<"EffectConditionExpr">;
def Identifier : RefPropertyType<"IdentifierInfo"> { let ConstWhenWriting = 1; }
def LValuePathEntry : PropertyType<"APValue::LValuePathEntry">;
def LValuePathSerializationHelper :
Expand Down
Loading