Skip to content

Commit be188f8

Browse files
Doug Wyattcjappl
authored andcommitted
nonblocking/nonallocating attributes: 2nd pass caller/callee analysis/verification
1 parent 556e9d0 commit be188f8

File tree

15 files changed

+1645
-1
lines changed

15 files changed

+1645
-1
lines changed

clang/include/clang/Basic/DiagnosticGroups.td

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

15641565
// Warnings and notes InstallAPI verification.
15651566
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
@@ -10949,6 +10949,55 @@ def warn_imp_cast_drops_unaligned : Warning<
1094910949
InGroup<DiagGroup<"unaligned-qualifier-implicit-cast">>;
1095010950

1095110951
// Function effects
10952+
def warn_func_effect_allocates : Warning<
10953+
"'%0' function must not allocate or deallocate memory">,
10954+
InGroup<FunctionEffects>;
10955+
def note_func_effect_allocates : Note<
10956+
"function cannot be inferred '%0' because it allocates/deallocates memory">;
10957+
def warn_func_effect_throws_or_catches : Warning<
10958+
"'%0' function must not throw or catch exceptions">,
10959+
InGroup<FunctionEffects>;
10960+
def note_func_effect_throws_or_catches : Note<
10961+
"function cannot be inferred '%0' because it throws or catches exceptions">;
10962+
def warn_func_effect_has_static_local : Warning<
10963+
"'%0' function must not have static locals">,
10964+
InGroup<FunctionEffects>;
10965+
def note_func_effect_has_static_local : Note<
10966+
"function cannot be inferred '%0' because it has a static local">;
10967+
def warn_func_effect_uses_thread_local : Warning<
10968+
"'%0' function must not use thread-local variables">,
10969+
InGroup<FunctionEffects>;
10970+
def note_func_effect_uses_thread_local : Note<
10971+
"function cannot be inferred '%0' because it uses a thread-local variable">;
10972+
def warn_func_effect_calls_objc : Warning<
10973+
"'%0' function must not access an ObjC method or property">,
10974+
InGroup<FunctionEffects>;
10975+
def note_func_effect_calls_objc : Note<
10976+
"function cannot be inferred '%0' because it accesses an ObjC method or property">;
10977+
def warn_func_effect_calls_func_without_effect : Warning<
10978+
"'%0' function must not call non-'%0' function '%1'">,
10979+
InGroup<FunctionEffects>;
10980+
def warn_func_effect_calls_expr_without_effect : Warning<
10981+
"'%0' function must not call non-'%0' expression">,
10982+
InGroup<FunctionEffects>;
10983+
def note_func_effect_calls_func_without_effect : Note<
10984+
"function cannot be inferred '%0' because it calls non-'%0' function '%1'">;
10985+
def note_func_effect_call_extern : Note<
10986+
"function cannot be inferred '%0' because it has no definition in this translation unit">;
10987+
def note_func_effect_call_disallows_inference : Note<
10988+
"function does not permit inference of '%0'">;
10989+
def note_func_effect_call_virtual : Note<
10990+
"virtual method cannot be inferred '%0'">;
10991+
def note_func_effect_call_func_ptr : Note<
10992+
"function pointer cannot be inferred '%0'">;
10993+
def warn_perf_constraint_implies_noexcept : Warning<
10994+
"'%0' function should be declared noexcept">,
10995+
InGroup<PerfConstraintImpliesNoexcept>;
10996+
10997+
// FIXME: It would be nice if we could provide fuller template expansion notes.
10998+
def note_func_effect_from_template : Note<
10999+
"in template expansion here">;
11000+
1095211001
// spoofing nonblocking/nonallocating
1095311002
def warn_invalid_add_func_effects : Warning<
1095411003
"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
@@ -835,6 +835,13 @@ class Sema final : public SemaBase {
835835

836836
// ----- function effects ---
837837

838+
/// All functions/lambdas/blocks which have bodies and which have a non-empty
839+
/// FunctionEffectsRef to be verified.
840+
SmallVector<const Decl *> DeclsWithEffectsToVerify;
841+
/// The union of all effects present on DeclsWithEffectsToVerify. Conditions
842+
/// are all null.
843+
FunctionEffectSet AllEffectsToVerify;
844+
838845
/// Warn when implicitly changing function effects.
839846
void diagnoseFunctionEffectConversion(QualType DstType, QualType SrcType,
840847
SourceLocation Loc);
@@ -851,6 +858,12 @@ class Sema final : public SemaBase {
851858
SourceLocation NewLoc,
852859
SourceLocation OldLoc);
853860

861+
/// Potentially add a FunctionDecl or BlockDecl to DeclsWithEffectsToVerify.
862+
void maybeAddDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX);
863+
864+
/// Unconditionally add a Decl to DeclsWithEfffectsToVerify.
865+
void addDeclWithEffects(const Decl *D, const FunctionEffectsRef &FX);
866+
854867
/// Try to parse the conditional expression attached to an effect attribute
855868
/// (e.g. 'nonblocking'). (c.f. Sema::ActOnNoexceptSpec). Return an empty
856869
/// optional on error.

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,12 @@ enum ASTRecordTypes {
722722
/// Record code for \#pragma clang unsafe_buffer_usage begin/end
723723
PP_UNSAFE_BUFFER_USAGE = 69,
724724

725+
/// Record code for Sema's vector of functions/blocks with effects to
726+
/// be verified.
727+
DECLS_WITH_EFFECTS_TO_VERIFY = 70,
728+
725729
/// Record code for vtables to emit.
726-
VTABLES_TO_EMIT = 70,
730+
VTABLES_TO_EMIT = 71,
727731
};
728732

729733
/// 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
@@ -972,6 +972,9 @@ class ASTReader
972972
/// Sema tracks these to emit deferred diags.
973973
llvm::SmallSetVector<GlobalDeclID, 4> DeclsToCheckForDeferredDiags;
974974

975+
/// The IDs of all decls with function effects to be checked.
976+
SmallVector<GlobalDeclID, 0> DeclsWithEffectsToVerify;
977+
975978
private:
976979
struct ImportedSubmodule {
977980
serialization::SubmoduleID ID;

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ class ASTWriter : public ASTDeserializationListener,
596596
void WriteMSPointersToMembersPragmaOptions(Sema &SemaRef);
597597
void WritePackPragmaOptions(Sema &SemaRef);
598598
void WriteFloatControlPragmaOptions(Sema &SemaRef);
599+
void WriteDeclsWithEffectsToVerify(Sema &SemaRef);
599600
void WriteModuleFileExtension(Sema &SemaRef,
600601
ModuleFileExtensionWriter &Writer);
601602

0 commit comments

Comments
 (0)