Skip to content

Commit 8c5f854

Browse files
author
Doug Wyatt
committed
nonblocking/nonallocating attributes: 2nd pass caller/callee analysis/verification
1 parent f6e01b9 commit 8c5f854

File tree

16 files changed

+1645
-1
lines changed

16 files changed

+1645
-1
lines changed

clang/include/clang/AST/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4699,7 +4699,7 @@ class FunctionEffect {
46994699

47004700
private:
47014701
LLVM_PREFERRED_TYPE(Kind)
4702-
unsigned FKind : 3;
4702+
uint8_t FKind : 3;
47034703

47044704
// Expansion: for hypothetical TCB+types, there could be one Kind for TCB,
47054705
// then ~16(?) bits "SubKind" to map to a specific named TCB. SubKind would

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,7 @@ def UnsafeBufferUsage : DiagGroup<"unsafe-buffer-usage", [UnsafeBufferUsageInCon
15571557
// Warnings and notes related to the function effects system underlying
15581558
// the nonblocking and nonallocating attributes.
15591559
def FunctionEffects : DiagGroup<"function-effects">;
1560+
def PerfConstraintImpliesNoexcept : DiagGroup<"perf-constraint-implies-noexcept">;
15601561

15611562
// Warnings and notes InstallAPI verification.
15621563
def InstallAPIViolation : DiagGroup<"installapi-violation">;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10928,6 +10928,55 @@ def warn_imp_cast_drops_unaligned : Warning<
1092810928
InGroup<DiagGroup<"unaligned-qualifier-implicit-cast">>;
1092910929

1093010930
// Function effects
10931+
def warn_func_effect_allocates : Warning<
10932+
"'%0' function must not allocate or deallocate memory">,
10933+
InGroup<FunctionEffects>;
10934+
def note_func_effect_allocates : Note<
10935+
"function cannot be inferred '%0' because it allocates/deallocates memory">;
10936+
def warn_func_effect_throws_or_catches : Warning<
10937+
"'%0' function must not throw or catch exceptions">,
10938+
InGroup<FunctionEffects>;
10939+
def note_func_effect_throws_or_catches : Note<
10940+
"function cannot be inferred '%0' because it throws or catches exceptions">;
10941+
def warn_func_effect_has_static_local : Warning<
10942+
"'%0' function must not have static locals">,
10943+
InGroup<FunctionEffects>;
10944+
def note_func_effect_has_static_local : Note<
10945+
"function cannot be inferred '%0' because it has a static local">;
10946+
def warn_func_effect_uses_thread_local : Warning<
10947+
"'%0' function must not use thread-local variables">,
10948+
InGroup<FunctionEffects>;
10949+
def note_func_effect_uses_thread_local : Note<
10950+
"function cannot be inferred '%0' because it uses a thread-local variable">;
10951+
def warn_func_effect_calls_objc : Warning<
10952+
"'%0' function must not access an ObjC method or property">,
10953+
InGroup<FunctionEffects>;
10954+
def note_func_effect_calls_objc : Note<
10955+
"function cannot be inferred '%0' because it accesses an ObjC method or property">;
10956+
def warn_func_effect_calls_func_without_effect : Warning<
10957+
"'%0' function must not call non-'%0' function '%1'">,
10958+
InGroup<FunctionEffects>;
10959+
def warn_func_effect_calls_expr_without_effect : Warning<
10960+
"'%0' function must not call non-'%0' expression">,
10961+
InGroup<FunctionEffects>;
10962+
def note_func_effect_calls_func_without_effect : Note<
10963+
"function cannot be inferred '%0' because it calls non-'%0' function '%1'">;
10964+
def note_func_effect_call_extern : Note<
10965+
"function cannot be inferred '%0' because it has no definition in this translation unit">;
10966+
def note_func_effect_call_disallows_inference : Note<
10967+
"function does not permit inference of '%0'">;
10968+
def note_func_effect_call_virtual : Note<
10969+
"virtual method cannot be inferred '%0'">;
10970+
def note_func_effect_call_func_ptr : Note<
10971+
"function pointer cannot be inferred '%0'">;
10972+
def warn_perf_constraint_implies_noexcept : Warning<
10973+
"'%0' function should be declared noexcept">,
10974+
InGroup<PerfConstraintImpliesNoexcept>;
10975+
10976+
// FIXME: It would be nice if we could provide fuller template expansion notes.
10977+
def note_func_effect_from_template : Note<
10978+
"in template expansion here">;
10979+
1093110980
// spoofing nonblocking/nonallocating
1093210981
def warn_invalid_add_func_effects : Warning<
1093310982
"attribute '%0' should not be added via type conversion">,

clang/include/clang/Sema/Sema.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,13 @@ class Sema final : public SemaBase {
875875

876876
// ----- function effects ---
877877

878+
/// All functions/lambdas/blocks which have bodies and which have a non-empty
879+
/// FunctionEffectsRef to be verified.
880+
SmallVector<const Decl *> DeclsWithEffectsToVerify;
881+
/// The union of all effects present on DeclsWithEffectsToVerify. Conditions
882+
/// are all null.
883+
FunctionEffectSet AllEffectsToVerify;
884+
878885
/// Warn when implicitly changing function effects.
879886
void diagnoseFunctionEffectConversion(QualType DstType, QualType SrcType,
880887
SourceLocation Loc);
@@ -891,6 +898,12 @@ class Sema final : public SemaBase {
891898
SourceLocation NewLoc,
892899
SourceLocation OldLoc);
893900

901+
/// Potentially add a FunctionDecl or BlockDecl to DeclsWithEffectsToVerify.
902+
void maybeAddDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX);
903+
904+
/// Unconditionally add a Decl to DeclsWithEfffectsToVerify.
905+
void addDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX);
906+
894907
/// Try to parse the conditional expression attached to an effect attribute
895908
/// (e.g. 'nonblocking'). (c.f. Sema::ActOnNoexceptSpec). Return an empty
896909
/// optional on error.

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@ enum ASTRecordTypes {
721721

722722
/// Record code for \#pragma clang unsafe_buffer_usage begin/end
723723
PP_UNSAFE_BUFFER_USAGE = 69,
724+
725+
/// Record code for Sema's vector of functions/blocks with effects to
726+
/// be verified.
727+
DECLS_WITH_EFFECTS_TO_VERIFY = 70,
724728
};
725729

726730
/// Record types used within a source manager block.

clang/include/clang/Serialization/ASTReader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,9 @@ class ASTReader
948948
/// Sema tracks these to emit deferred diags.
949949
llvm::SmallSetVector<GlobalDeclID, 4> DeclsToCheckForDeferredDiags;
950950

951+
/// The IDs of all decls with function effects to be checked.
952+
SmallVector<GlobalDeclID, 0> DeclsWithEffectsToVerify;
953+
951954
private:
952955
struct ImportedSubmodule {
953956
serialization::SubmoduleID ID;

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ class ASTWriter : public ASTDeserializationListener,
592592
void WriteMSPointersToMembersPragmaOptions(Sema &SemaRef);
593593
void WritePackPragmaOptions(Sema &SemaRef);
594594
void WriteFloatControlPragmaOptions(Sema &SemaRef);
595+
void WriteDeclsWithEffectsToVerify(Sema &SemaRef);
595596
void WriteModuleFileExtension(Sema &SemaRef,
596597
ModuleFileExtensionWriter &Writer);
597598

0 commit comments

Comments
 (0)